@mastra/code-sdk 1.15.1-alpha.4 → 1.16.0-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/dist/acp/agent.js +1 -2
- package/dist/acp/errors.js +1 -2
- package/dist/acp/event-mapper.js +1 -2
- package/dist/acp/index.js +1 -2
- package/dist/acp/runtime.d.ts.map +1 -1
- package/dist/acp/runtime.js +5 -4
- package/dist/acp/runtime.js.map +1 -1
- package/dist/acp/server.js +1 -2
- package/dist/acp/skills.js +1 -2
- package/dist/agent-connections/messaging-processor.js +1 -2
- package/dist/agent-connections/ownership.js +1 -2
- package/dist/agent-connections/registry.js +1 -2
- package/dist/agent-connections/session-advertisement.js +1 -2
- package/dist/agent-connections/signal-provider.js +1 -2
- package/dist/agent-connections/state-processor.js +1 -2
- package/dist/agent-connections/thread-state.js +1 -2
- package/dist/agent-connections/tools.js +1 -2
- package/dist/agent-connections/types.js +1 -2
- package/dist/agent-connections/untrusted-text.js +1 -2
- package/dist/agents/background-completion-events.js +1 -2
- package/dist/agents/background-completion.js +1 -2
- package/dist/agents/context-audit.js +1 -2
- package/dist/agents/credential-resolver.js +1 -2
- package/dist/agents/custom-provider-source.js +1 -2
- package/dist/agents/instructions.js +1 -2
- package/dist/agents/mastracode-gateway.js +1 -2
- package/dist/agents/memory.js +1 -2
- package/dist/agents/model.js +1 -2
- package/dist/agents/modes/build.js +1 -2
- package/dist/agents/modes/explore.js +1 -2
- package/dist/agents/modes/plan.js +1 -2
- package/dist/agents/prompts/agent-instructions.js +1 -2
- package/dist/agents/prompts/build.js +1 -2
- package/dist/agents/prompts/fast.js +1 -2
- package/dist/agents/prompts/index.js +1 -2
- package/dist/agents/prompts/model.js +1 -2
- package/dist/agents/prompts/plan.js +1 -2
- package/dist/agents/prompts/tool-guidance.js +1 -2
- package/dist/agents/sandbox-filesystem.d.ts.map +1 -1
- package/dist/agents/sandbox-filesystem.js +9 -7
- package/dist/agents/sandbox-filesystem.js.map +1 -1
- package/dist/agents/subagents/execute.js +1 -2
- package/dist/agents/subagents/explore.js +1 -2
- package/dist/agents/subagents/index.d.ts +6 -0
- package/dist/agents/subagents/index.d.ts.map +1 -0
- package/dist/agents/subagents/index.js +17 -0
- package/dist/agents/subagents/index.js.map +1 -0
- package/dist/agents/subagents/plan.js +1 -2
- package/dist/agents/thread-caveman-state.js +1 -2
- package/dist/agents/tool-availability.js +1 -2
- package/dist/agents/tools.js +1 -2
- package/dist/agents/workflow-builder-agent.js +1 -2
- package/dist/agents/workspace.js +1 -2
- package/dist/analytics.js +1 -2
- package/dist/auth/account-rotation-processor.d.ts +6 -6
- package/dist/auth/account-rotation-processor.d.ts.map +1 -1
- package/dist/auth/account-rotation-processor.js +41 -51
- package/dist/auth/account-rotation-processor.js.map +1 -1
- package/dist/auth/account-routing-context.js +1 -2
- package/dist/auth/authorization-input.js +1 -2
- package/dist/auth/device-code.js +1 -2
- package/dist/auth/pkce.js +1 -2
- package/dist/auth/provider-auth-error.d.ts +2 -0
- package/dist/auth/provider-auth-error.d.ts.map +1 -1
- package/dist/auth/provider-auth-error.js +8 -3
- package/dist/auth/provider-auth-error.js.map +1 -1
- package/dist/auth/providers/anthropic.js +1 -2
- package/dist/auth/providers/github-copilot.js +1 -2
- package/dist/auth/providers/kimi-coding.js +1 -2
- package/dist/auth/providers/openai-codex.js +1 -2
- package/dist/auth/providers/xai.js +1 -2
- package/dist/auth/storage.js +1 -2
- package/dist/clipboard/index.js +1 -2
- package/dist/constants.js +1 -2
- package/dist/error-classification.js +1 -2
- package/dist/evals/context-builder.js +1 -2
- package/dist/evals/scorers/classify-command.d.ts +1 -2
- package/dist/evals/scorers/classify-command.d.ts.map +1 -1
- package/dist/evals/scorers/classify-command.js +7 -17
- package/dist/evals/scorers/classify-command.js.map +1 -1
- package/dist/evals/scorers/efficiency.js +1 -2
- package/dist/evals/scorers/extract-tools.js +1 -2
- package/dist/evals/scorers/outcome.d.ts.map +1 -1
- package/dist/evals/scorers/outcome.js +36 -22
- package/dist/evals/scorers/outcome.js.map +1 -1
- package/dist/experimental-agent.js +1 -2
- package/dist/factory/client.js +1 -2
- package/dist/factory/remote-controller.js +1 -2
- package/dist/factory/remote-session.js +1 -2
- package/dist/goal-manager.js +1 -2
- package/dist/goal-signal.js +1 -2
- package/dist/headless/cli.d.ts.map +1 -1
- package/dist/headless/cli.js +4 -3
- package/dist/headless/cli.js.map +1 -1
- package/dist/headless/flags.js +1 -2
- package/dist/headless/format.js +1 -2
- package/dist/headless/policy.js +1 -2
- package/dist/headless/run-mc.js +1 -2
- package/dist/headless/types.js +1 -2
- package/dist/hooks/config.js +1 -2
- package/dist/hooks/executor.js +1 -2
- package/dist/hooks/manager.js +1 -2
- package/dist/hooks/types.js +1 -2
- package/dist/index.d.ts +7 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +9 -15
- package/dist/index.js.map +1 -1
- package/dist/ipc/ipc-reporter.js +1 -2
- package/dist/knowledge-inspector.js +1 -2
- package/dist/knowledge-scope.js +1 -2
- package/dist/lsp/client.d.ts.map +1 -1
- package/dist/lsp/client.js +1 -2
- package/dist/lsp/client.js.map +1 -1
- package/dist/lsp/language.js +1 -2
- package/dist/lsp/manager.js +1 -2
- package/dist/lsp/server.js +1 -2
- package/dist/lsp/workspace.js +1 -2
- package/dist/mcp/config.js +1 -2
- package/dist/mcp/manager.js +1 -2
- package/dist/mcp/state.js +1 -2
- package/dist/onboarding/custom-packs.js +1 -2
- package/dist/onboarding/custom-providers.js +1 -2
- package/dist/onboarding/om-settings.js +1 -2
- package/dist/onboarding/pack-activation.js +1 -2
- package/dist/onboarding/packs.js +1 -2
- package/dist/onboarding/settings.js +1 -2
- package/dist/permissions.js +1 -2
- package/dist/platform/index.js +1 -2
- package/dist/plugin.js +1 -2
- package/dist/plugins/dependencies.js +1 -2
- package/dist/plugins/install.js +1 -2
- package/dist/plugins/loader.js +1 -2
- package/dist/plugins/manager.js +1 -2
- package/dist/plugins/manifest.js +1 -2
- package/dist/plugins/package-link.js +1 -2
- package/dist/plugins/paths.js +1 -2
- package/dist/plugins/registry.js +1 -2
- package/dist/plugins/scaffold.js +1 -2
- package/dist/plugins/signal-lane.js +1 -2
- package/dist/process-memory-diagnostics.js +1 -2
- package/dist/processors/plan-rejection-abort.js +1 -2
- package/dist/providers/amazon-bedrock-gateway.js +1 -2
- package/dist/providers/amazon-bedrock.js +1 -2
- package/dist/providers/anthropic-prompt-cache.js +1 -2
- package/dist/providers/anthropic-thinking.js +1 -2
- package/dist/providers/claude-max.d.ts.map +1 -1
- package/dist/providers/claude-max.js +4 -4
- package/dist/providers/claude-max.js.map +1 -1
- package/dist/providers/github-copilot-gateway.js +1 -2
- package/dist/providers/github-copilot.d.ts.map +1 -1
- package/dist/providers/github-copilot.js +5 -5
- package/dist/providers/github-copilot.js.map +1 -1
- package/dist/providers/google-thinking.js +1 -2
- package/dist/providers/kimi-coding.d.ts.map +1 -1
- package/dist/providers/kimi-coding.js +8 -7
- package/dist/providers/kimi-coding.js.map +1 -1
- package/dist/providers/model-ids.js +1 -2
- package/dist/providers/openai-codex.d.ts.map +1 -1
- package/dist/providers/openai-codex.js +7 -7
- package/dist/providers/openai-codex.js.map +1 -1
- package/dist/providers/provider-thinking.js +1 -2
- package/dist/providers/thinking-request.js +1 -2
- package/dist/providers/xai.d.ts.map +1 -1
- package/dist/providers/xai.js +5 -5
- package/dist/providers/xai.js.map +1 -1
- package/dist/schedules/interval.js +1 -2
- package/dist/schedules/prompt.js +1 -2
- package/dist/schedules/run-script.js +1 -2
- package/dist/schedules/scheduler.js +1 -2
- package/dist/schedules/tools.js +1 -2
- package/dist/schema.js +1 -2
- package/dist/theme-palette.js +1 -2
- package/dist/thinking-catalog.js +1 -2
- package/dist/thinking.js +1 -2
- package/dist/tool-names.js +1 -2
- package/dist/tools/request-sandbox-access.js +1 -2
- package/dist/tools/utils.js +1 -2
- package/dist/tools/web-search.js +1 -2
- package/dist/tools/workflows/create-workflow.js +1 -2
- package/dist/tools/workflows/delete-workflow.js +1 -2
- package/dist/tools/workflows/ephemeral-memory.js +1 -2
- package/dist/tools/workflows/extract-json-schema.js +1 -2
- package/dist/tools/workflows/get-workflow.js +1 -2
- package/dist/tools/workflows/list-available-agents.js +1 -2
- package/dist/tools/workflows/list-available-classifiers.js +1 -2
- package/dist/tools/workflows/list-available-tools.js +1 -2
- package/dist/tools/workflows/list-available-workflows.js +1 -2
- package/dist/tools/workflows/list-workflows.js +1 -2
- package/dist/tools/workflows/run-workflow.js +1 -2
- package/dist/tools/workflows/save-workflow.js +1 -2
- package/dist/tools/workflows/tool-ids.js +1 -2
- package/dist/utils/binaries.js +1 -2
- package/dist/utils/debug-log.js +1 -2
- package/dist/utils/discarding-scores-storage.js +1 -2
- package/dist/utils/errors.d.ts +1 -1
- package/dist/utils/errors.d.ts.map +1 -1
- package/dist/utils/errors.js +99 -80
- package/dist/utils/errors.js.map +1 -1
- package/dist/utils/gateway-sync.js +1 -2
- package/dist/utils/local-observability.js +1 -2
- package/dist/utils/maintenance-lock.js +1 -2
- package/dist/utils/notification-dispatch.js +1 -2
- package/dist/utils/open-url.js +1 -2
- package/dist/utils/path-security.js +1 -2
- package/dist/utils/plan-diff.js +1 -2
- package/dist/utils/plans.js +1 -2
- package/dist/utils/project.js +1 -2
- package/dist/utils/prune-cli.js +1 -2
- package/dist/utils/signals-pubsub.js +1 -2
- package/dist/utils/slash-command-loader.js +1 -2
- package/dist/utils/slash-command-processor.js +1 -2
- package/dist/utils/stdin-pipe.js +1 -2
- package/dist/utils/storage-factory.js +1 -2
- package/dist/utils/storage-maintenance.js +1 -2
- package/dist/utils/thread-lock.js +1 -2
- package/dist/utils/token-estimator.js +1 -2
- package/dist/utils/update-check.js +1 -2
- package/dist/utils/wake-session.js +1 -2
- package/dist/voice/stt-registry.js +1 -2
- package/dist/workflows/register-primitives.js +1 -2
- package/dist/workflows/service.js +1 -2
- package/package.json +35 -31
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { listWorkflows } from "../../workflows/service.js";
|
|
2
2
|
import { createTool } from "@mastra/core/tools";
|
|
3
3
|
import { z } from "zod";
|
|
4
|
-
|
|
4
|
+
// src/tools/workflows/list-workflows.ts
|
|
5
5
|
const listWorkflowsTool = createTool({
|
|
6
6
|
id: "list-workflows",
|
|
7
7
|
description: "List active Dynamic Workflows persisted to storage. Returns id + description + status for each.",
|
|
@@ -27,7 +27,6 @@ const listWorkflowsTool = createTool({
|
|
|
27
27
|
};
|
|
28
28
|
}
|
|
29
29
|
});
|
|
30
|
-
//#endregion
|
|
31
30
|
export { listWorkflowsTool };
|
|
32
31
|
|
|
33
32
|
//# sourceMappingURL=list-workflows.js.map
|
|
@@ -2,7 +2,7 @@ import { runWorkflow } from "../../workflows/service.js";
|
|
|
2
2
|
import { withEphemeralMemory } from "./ephemeral-memory.js";
|
|
3
3
|
import { createTool } from "@mastra/core/tools";
|
|
4
4
|
import { z } from "zod";
|
|
5
|
-
|
|
5
|
+
// src/tools/workflows/run-workflow.ts
|
|
6
6
|
const runWorkflowTool = createTool({
|
|
7
7
|
id: "run-workflow",
|
|
8
8
|
description: "Run a saved workflow by id with the provided input data. Returns the run result inline. Use when the user asks you to \"run X\", \"execute X\", or asks for the outcome of a saved workflow.",
|
|
@@ -46,7 +46,6 @@ const runWorkflowTool = createTool({
|
|
|
46
46
|
});
|
|
47
47
|
}
|
|
48
48
|
});
|
|
49
|
-
//#endregion
|
|
50
49
|
export { runWorkflowTool };
|
|
51
50
|
|
|
52
51
|
//# sourceMappingURL=run-workflow.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { createTool } from "@mastra/core/tools";
|
|
2
2
|
import { z } from "zod";
|
|
3
3
|
import { WORKFLOW_BUILDER_MAPPING_CONFIG_DESCRIPTION as MAPPING_CONFIG_DESCRIPTION, normalizeWorkflowBuilderDefinition, workflowBuilderDefinitionSchema } from "@mastra/core/workflows/builder";
|
|
4
|
-
|
|
4
|
+
// src/tools/workflows/save-workflow.ts
|
|
5
5
|
const workflowDefinitionInputSchema = z.preprocess(normalizeWorkflowBuilderDefinition, workflowBuilderDefinitionSchema);
|
|
6
6
|
const saveWorkflowTool = createTool({
|
|
7
7
|
id: "save-workflow",
|
|
@@ -22,7 +22,6 @@ const saveWorkflowTool = createTool({
|
|
|
22
22
|
};
|
|
23
23
|
}
|
|
24
24
|
});
|
|
25
|
-
//#endregion
|
|
26
25
|
export { MAPPING_CONFIG_DESCRIPTION, saveWorkflowTool, workflowDefinitionInputSchema };
|
|
27
26
|
|
|
28
27
|
//# sourceMappingURL=save-workflow.js.map
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
// src/tools/workflows/tool-ids.ts
|
|
2
2
|
const WORKFLOW_AUTHORING_TOOL_IDS = {
|
|
3
3
|
listAgents: "list-available-agents",
|
|
4
4
|
listClassifiers: "list-available-classifiers",
|
|
@@ -14,7 +14,6 @@ const WORKFLOW_MANAGEMENT_TOOL_IDS = {
|
|
|
14
14
|
deleteWorkflow: "delete-workflow"
|
|
15
15
|
};
|
|
16
16
|
const WORKFLOW_BUILDER_NOISE_TOOL_IDS = [...Object.values(WORKFLOW_AUTHORING_TOOL_IDS), ...Object.values(WORKFLOW_MANAGEMENT_TOOL_IDS)];
|
|
17
|
-
//#endregion
|
|
18
17
|
export { WORKFLOW_AUTHORING_TOOL_IDS, WORKFLOW_BUILDER_NOISE_TOOL_IDS, WORKFLOW_MANAGEMENT_TOOL_IDS };
|
|
19
18
|
|
|
20
19
|
//# sourceMappingURL=tool-ids.js.map
|
package/dist/utils/binaries.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { execFile, execFileSync } from "child_process";
|
|
2
|
-
|
|
2
|
+
// src/utils/binaries.ts
|
|
3
3
|
const COMMON_BINARIES = [
|
|
4
4
|
"python",
|
|
5
5
|
"python3",
|
|
@@ -72,7 +72,6 @@ async function detectCommonBinariesAsync() {
|
|
|
72
72
|
inFlightPromise = null;
|
|
73
73
|
}
|
|
74
74
|
}
|
|
75
|
-
//#endregion
|
|
76
75
|
export { detectCommonBinaries, detectCommonBinariesAsync };
|
|
77
76
|
|
|
78
77
|
//# sourceMappingURL=binaries.js.map
|
package/dist/utils/debug-log.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { getAppDataDir } from "./project.js";
|
|
2
2
|
import * as path$1 from "path";
|
|
3
3
|
import * as fs$1 from "fs";
|
|
4
|
-
|
|
4
|
+
// src/utils/debug-log.ts
|
|
5
5
|
const MAX_LOG_SIZE = 5242880;
|
|
6
6
|
const KEEP_SIZE = 4194304;
|
|
7
7
|
/**
|
|
@@ -53,7 +53,6 @@ function setupDebugLogging() {
|
|
|
53
53
|
console.warn = noop;
|
|
54
54
|
}
|
|
55
55
|
}
|
|
56
|
-
//#endregion
|
|
57
56
|
export { setupDebugLogging, truncateLogFile };
|
|
58
57
|
|
|
59
58
|
//# sourceMappingURL=debug-log.js.map
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ScoresStorage } from "@mastra/core/storage";
|
|
2
|
-
|
|
2
|
+
// src/utils/discarding-scores-storage.ts
|
|
3
3
|
/**
|
|
4
4
|
* A scores domain that accepts writes and keeps nothing.
|
|
5
5
|
*
|
|
@@ -48,7 +48,6 @@ function empty(pagination) {
|
|
|
48
48
|
scores: []
|
|
49
49
|
};
|
|
50
50
|
}
|
|
51
|
-
//#endregion
|
|
52
51
|
export { DiscardingScoresStorage };
|
|
53
52
|
|
|
54
53
|
//# sourceMappingURL=discarding-scores-storage.js.map
|
package/dist/utils/errors.d.ts
CHANGED
|
@@ -18,7 +18,7 @@ export interface ParsedError {
|
|
|
18
18
|
/** Original error for debugging */
|
|
19
19
|
originalError: Error;
|
|
20
20
|
}
|
|
21
|
-
export type ErrorType = 'rate_limit' | 'auth' | 'network' | 'timeout' | 'invalid_request' | 'server_error' | 'model_not_found' | 'context_length' | 'content_filter' | 'unknown';
|
|
21
|
+
export type ErrorType = 'rate_limit' | 'quota' | 'auth' | 'network' | 'timeout' | 'invalid_request' | 'server_error' | 'model_not_found' | 'context_length' | 'content_filter' | 'unknown';
|
|
22
22
|
export declare function parseError(error: unknown): ParsedError;
|
|
23
23
|
/**
|
|
24
24
|
* Sleep for a given number of milliseconds.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/utils/errors.ts"],"names":[],"mappings":"AAAA;;;GAGG;
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/utils/errors.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAMH,MAAM,WAAW,WAAW;IAC1B,kCAAkC;IAClC,OAAO,EAAE,MAAM,CAAC;IAChB,qDAAqD;IACrD,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,0DAA0D;IAC1D,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,oCAAoC;IACpC,IAAI,EAAE,SAAS,CAAC;IAChB,sCAAsC;IACtC,SAAS,EAAE,OAAO,CAAC;IACnB,iDAAiD;IACjD,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,mCAAmC;IACnC,aAAa,EAAE,KAAK,CAAC;CACtB;AAED,MAAM,MAAM,SAAS,GACjB,YAAY,GACZ,OAAO,GACP,MAAM,GACN,SAAS,GACT,SAAS,GACT,iBAAiB,GACjB,cAAc,GACd,iBAAiB,GACjB,gBAAgB,GAChB,gBAAgB,GAChB,SAAS,CAAC;AAuId,wBAAgB,UAAU,CAAC,KAAK,EAAE,OAAO,GAAG,WAAW,CA0GtD;AAkDD;;GAEG;AACH,wBAAgB,KAAK,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAE/C;AAED;;GAEG;AACH,wBAAsB,SAAS,CAAC,CAAC,EAC/B,EAAE,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,EACpB,OAAO,GAAE;IACP,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;CACpD,GACL,OAAO,CAAC,CAAC,CAAC,CA6BZ"}
|
package/dist/utils/errors.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import "../auth/provider-auth-error.js";
|
|
2
|
-
|
|
2
|
+
import { classifyProviderError } from "@mastra/core/error";
|
|
3
|
+
// src/utils/errors.ts
|
|
3
4
|
/**
|
|
4
5
|
* Error handling utilities for the Mastra Code TUI.
|
|
5
6
|
* Parses API errors and provides user-friendly messages.
|
|
@@ -47,10 +48,26 @@ function toError(error) {
|
|
|
47
48
|
rebuilt.name = error.name;
|
|
48
49
|
return rebuilt;
|
|
49
50
|
}
|
|
51
|
+
function errorTypeOf(error, message, status) {
|
|
52
|
+
const kind = classifyProviderError(typeof status === "number" ? {
|
|
53
|
+
statusCode: status,
|
|
54
|
+
cause: error
|
|
55
|
+
} : error);
|
|
56
|
+
if (kind === "quota") return "quota";
|
|
57
|
+
if (kind === "rate_limited" || status === 429 || message.includes("429")) return "rate_limit";
|
|
58
|
+
if (kind === "auth" || status === 401 || status === 403 || kind !== "unavailable" && (message.includes("unauthorized") || message.includes("authentication") || message.includes("api key"))) return "auth";
|
|
59
|
+
if (message.includes("network") || message.includes("econnrefused") || message.includes("enotfound") || message.includes("fetch failed") || message.includes("connection")) return "network";
|
|
60
|
+
if (kind === "timeout") return "timeout";
|
|
61
|
+
if (kind === "model_rejected" || message.includes("does not exist")) return "model_not_found";
|
|
62
|
+
if (kind === "context_overflow" || message.includes("context length") || message.includes("too many tokens") || message.includes("token limit")) return "context_length";
|
|
63
|
+
if (message.includes("content filter") || message.includes("content_filter") || message.includes("content policy") || message.includes("safety") || message.includes("prohibited")) return "content_filter";
|
|
64
|
+
if (kind === "unavailable" || typeof status === "number" && status >= 500 && status < 600) return "server_error";
|
|
65
|
+
if (kind === "invalid_request" || kind === "tool_history_rejected" || status === 400 || message.includes("invalid request") || message.includes("bad request")) return "invalid_request";
|
|
66
|
+
return "unknown";
|
|
67
|
+
}
|
|
50
68
|
function parseError(error) {
|
|
51
69
|
const err = toError(error);
|
|
52
|
-
const
|
|
53
|
-
const errorObj = error;
|
|
70
|
+
const errorObj = typeof error === "object" && error !== null ? error : {};
|
|
54
71
|
const detail = summarizeErrorDetail(error);
|
|
55
72
|
const requestUrl = extractRequestUrl(error);
|
|
56
73
|
if (err.name === "ProviderAuthRequiredError") return {
|
|
@@ -61,82 +78,85 @@ function parseError(error) {
|
|
|
61
78
|
retryable: false,
|
|
62
79
|
originalError: err
|
|
63
80
|
};
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
81
|
+
const type = errorTypeOf(error, err.message.toLowerCase(), errorObj.statusCode ?? errorObj.status);
|
|
82
|
+
switch (type) {
|
|
83
|
+
case "quota": return {
|
|
84
|
+
message: "Usage quota exhausted for this provider account.",
|
|
85
|
+
detail,
|
|
86
|
+
requestUrl,
|
|
87
|
+
type,
|
|
88
|
+
retryable: false,
|
|
89
|
+
originalError: err
|
|
90
|
+
};
|
|
91
|
+
case "rate_limit": return {
|
|
92
|
+
message: "Rate limited. Please wait a moment before trying again.",
|
|
93
|
+
type,
|
|
94
|
+
retryable: true,
|
|
95
|
+
retryDelay: extractRetryAfter(errorObj) || 5e3,
|
|
96
|
+
originalError: err
|
|
97
|
+
};
|
|
98
|
+
case "auth": return {
|
|
99
|
+
message: (errorObj.statusCode ?? errorObj.status) === 403 ? "Access denied. You may not have permission to use this model." : "Authentication failed. Check the credential configured for this provider.",
|
|
100
|
+
detail,
|
|
101
|
+
requestUrl,
|
|
102
|
+
type,
|
|
103
|
+
retryable: false,
|
|
104
|
+
originalError: err
|
|
105
|
+
};
|
|
106
|
+
case "network": return {
|
|
107
|
+
message: "Network error while contacting the provider or gateway.",
|
|
108
|
+
detail,
|
|
109
|
+
requestUrl,
|
|
110
|
+
type,
|
|
111
|
+
retryable: true,
|
|
112
|
+
retryDelay: 2e3,
|
|
113
|
+
originalError: err
|
|
114
|
+
};
|
|
115
|
+
case "timeout": return {
|
|
116
|
+
message: "Request timed out. The server may be overloaded.",
|
|
117
|
+
type,
|
|
118
|
+
retryable: true,
|
|
119
|
+
retryDelay: 3e3,
|
|
120
|
+
originalError: err
|
|
121
|
+
};
|
|
122
|
+
case "model_not_found": return {
|
|
123
|
+
message: "Model not found. Please select a different model with /models.",
|
|
124
|
+
type,
|
|
125
|
+
retryable: false,
|
|
126
|
+
originalError: err
|
|
127
|
+
};
|
|
128
|
+
case "context_length": return {
|
|
129
|
+
message: "Message too long. Try starting a new thread with /new.",
|
|
130
|
+
type,
|
|
131
|
+
retryable: false,
|
|
132
|
+
originalError: err
|
|
133
|
+
};
|
|
134
|
+
case "content_filter": return {
|
|
135
|
+
message: "Content was filtered by the model's safety system.",
|
|
136
|
+
type,
|
|
137
|
+
retryable: false,
|
|
138
|
+
originalError: err
|
|
139
|
+
};
|
|
140
|
+
case "server_error": return {
|
|
141
|
+
message: "Server error. The API may be experiencing issues.",
|
|
142
|
+
type,
|
|
143
|
+
retryable: true,
|
|
144
|
+
retryDelay: 5e3,
|
|
145
|
+
originalError: err
|
|
146
|
+
};
|
|
147
|
+
case "invalid_request": return {
|
|
148
|
+
message: `Invalid request: ${extractErrorDetail(err)}`,
|
|
149
|
+
type,
|
|
150
|
+
retryable: false,
|
|
151
|
+
originalError: err
|
|
152
|
+
};
|
|
153
|
+
case "unknown": return {
|
|
154
|
+
message: extractErrorDetail(err),
|
|
155
|
+
type,
|
|
156
|
+
retryable: false,
|
|
157
|
+
originalError: err
|
|
158
|
+
};
|
|
159
|
+
}
|
|
140
160
|
}
|
|
141
161
|
/**
|
|
142
162
|
* Extract retry-after header value from error.
|
|
@@ -190,7 +210,6 @@ async function withRetry(fn, options = {}) {
|
|
|
190
210
|
}
|
|
191
211
|
throw lastError?.originalError || /* @__PURE__ */ new Error("Retry failed");
|
|
192
212
|
}
|
|
193
|
-
//#endregion
|
|
194
213
|
export { parseError, sleep, withRetry };
|
|
195
214
|
|
|
196
215
|
//# sourceMappingURL=errors.js.map
|
package/dist/utils/errors.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.js","names":[],"sources":["../../src/utils/errors.ts"],"sourcesContent":["/**\n * Error handling utilities for the Mastra Code TUI.\n * Parses API errors and provides user-friendly messages.\n */\n\nimport { PROVIDER_AUTH_REQUIRED_ERROR } from '../auth/provider-auth-error.js';\n\nexport interface ParsedError {\n /** User-friendly error message */\n message: string;\n /** Extra diagnostic detail to surface to the user */\n detail?: string;\n /** Request URL involved in the failure, when available */\n requestUrl?: string;\n /** Error type for categorization */\n type: ErrorType;\n /** Whether this error is retryable */\n retryable: boolean;\n /** Suggested retry delay in ms (if retryable) */\n retryDelay?: number;\n /** Original error for debugging */\n originalError: Error;\n}\n\nexport type ErrorType =\n | 'rate_limit'\n | 'auth'\n | 'network'\n | 'timeout'\n | 'invalid_request'\n | 'server_error'\n | 'model_not_found'\n | 'context_length'\n | 'content_filter'\n | 'unknown';\n\n/**\n * Parse an error and return a user-friendly representation.\n */\nfunction summarizeErrorDetail(error: unknown): string | undefined {\n if (error instanceof Error) {\n if (error.cause instanceof Error && error.cause.message) {\n return error.cause.message;\n }\n\n if (typeof error.cause === 'string' && error.cause.trim().length > 0) {\n return error.cause;\n }\n\n if (error.message.trim().length > 0) {\n return error.message;\n }\n }\n\n if (typeof error === 'string' && error.trim().length > 0) {\n return error;\n }\n\n if (error && typeof error === 'object') {\n const errorObj = error as Record<string, unknown>;\n const candidates = [errorObj['message'], errorObj['cause'], errorObj['code'], errorObj['statusText']];\n\n for (const candidate of candidates) {\n if (typeof candidate === 'string' && candidate.trim().length > 0) {\n return candidate;\n }\n }\n }\n\n return undefined;\n}\n\nfunction extractRequestUrl(error: unknown): string | undefined {\n if (!error || typeof error !== 'object') {\n return undefined;\n }\n\n const candidates: unknown[] = [];\n const errorObj = error as Record<string, unknown>;\n candidates.push(errorObj['requestUrl'], errorObj['url']);\n\n if (errorObj['cause'] && typeof errorObj['cause'] === 'object') {\n const causeObj = errorObj['cause'] as Record<string, unknown>;\n candidates.push(causeObj['requestUrl'], causeObj['url']);\n }\n\n for (const candidate of candidates) {\n if (typeof candidate === 'string' && candidate.trim().length > 0) {\n return candidate;\n }\n }\n\n return undefined;\n}\n\n/** A flattened error crossing the wire: the server sends `{ name, message }`, not an `Error`. */\nfunction isSerializedError(value: unknown): value is { name: string; message: string } {\n return (\n typeof value === 'object' &&\n value !== null &&\n 'name' in value &&\n typeof value.name === 'string' &&\n 'message' in value &&\n typeof value.message === 'string'\n );\n}\n\nfunction toError(error: unknown): Error {\n if (error instanceof Error) return error;\n if (!isSerializedError(error)) return new Error(String(error));\n const rebuilt = new Error(error.message);\n rebuilt.name = error.name;\n return rebuilt;\n}\n\nexport function parseError(error: unknown): ParsedError {\n const err = toError(error);\n const message = err.message.toLowerCase();\n const errorObj = error as Record<string, unknown>;\n const detail = summarizeErrorDetail(error);\n const requestUrl = extractRequestUrl(error);\n\n // Matched by name, not instance: the error may have crossed a serialization boundary.\n if (err.name === PROVIDER_AUTH_REQUIRED_ERROR) {\n return { message: err.message, detail, requestUrl, type: 'auth', retryable: false, originalError: err };\n }\n\n // Check for rate limiting\n if (\n message.includes('rate limit') ||\n message.includes('rate_limit') ||\n message.includes('429') ||\n errorObj.statusCode === 429 ||\n errorObj.status === 429\n ) {\n const retryAfter = extractRetryAfter(errorObj);\n return {\n message: 'Rate limited. Please wait a moment before trying again.',\n type: 'rate_limit',\n retryable: true,\n retryDelay: retryAfter || 5000,\n originalError: err,\n };\n }\n\n // Check for authentication errors\n if (\n message.includes('unauthorized') ||\n message.includes('authentication') ||\n message.includes('invalid api key') ||\n message.includes('invalid_api_key') ||\n message.includes('api key') ||\n errorObj.statusCode === 401 ||\n errorObj.status === 401\n ) {\n return {\n message: 'Authentication failed. Check the credential configured for this provider.',\n detail,\n requestUrl,\n type: 'auth',\n retryable: false,\n originalError: err,\n };\n }\n\n // Check for forbidden/permission errors\n if (errorObj.statusCode === 403 || errorObj.status === 403) {\n return {\n message: 'Access denied. You may not have permission to use this model.',\n detail,\n requestUrl,\n type: 'auth',\n retryable: false,\n originalError: err,\n };\n }\n\n // Check for network errors\n if (\n message.includes('network') ||\n message.includes('econnrefused') ||\n message.includes('enotfound') ||\n message.includes('fetch failed') ||\n message.includes('connection')\n ) {\n return {\n message: 'Network error while contacting the provider or gateway.',\n detail,\n requestUrl,\n type: 'network',\n retryable: true,\n retryDelay: 2000,\n originalError: err,\n };\n }\n\n // Check for timeout errors\n if (message.includes('timeout') || message.includes('timed out') || message.includes('etimedout')) {\n return {\n message: 'Request timed out. The server may be overloaded.',\n type: 'timeout',\n retryable: true,\n retryDelay: 3000,\n originalError: err,\n };\n }\n\n // Check for model not found\n if (\n message.includes('model not found') ||\n message.includes('model_not_found') ||\n message.includes('does not exist') ||\n message.includes('invalid model')\n ) {\n return {\n message: 'Model not found. Please select a different model with /models.',\n type: 'model_not_found',\n retryable: false,\n originalError: err,\n };\n }\n\n // Check for context length errors\n if (\n message.includes('context length') ||\n message.includes('context_length') ||\n message.includes('too many tokens') ||\n message.includes('maximum context') ||\n message.includes('token limit')\n ) {\n return {\n message: 'Message too long. Try starting a new thread with /new.',\n type: 'context_length',\n retryable: false,\n originalError: err,\n };\n }\n\n // Check for content filter errors\n if (\n message.includes('content filter') ||\n message.includes('content_filter') ||\n message.includes('content policy') ||\n message.includes('safety') ||\n message.includes('prohibited')\n ) {\n return {\n message: \"Content was filtered by the model's safety system.\",\n type: 'content_filter',\n retryable: false,\n originalError: err,\n };\n }\n\n // Check for server errors\n if (\n message.includes('internal server') ||\n message.includes('server error') ||\n errorObj.statusCode === 500 ||\n errorObj.status === 500 ||\n errorObj.statusCode === 502 ||\n errorObj.status === 502 ||\n errorObj.statusCode === 503 ||\n errorObj.status === 503\n ) {\n return {\n message: 'Server error. The API may be experiencing issues.',\n type: 'server_error',\n retryable: true,\n retryDelay: 5000,\n originalError: err,\n };\n }\n\n // Check for invalid request errors\n if (\n message.includes('invalid request') ||\n message.includes('bad request') ||\n errorObj.statusCode === 400 ||\n errorObj.status === 400\n ) {\n return {\n message: `Invalid request: ${extractErrorDetail(err)}`,\n type: 'invalid_request',\n retryable: false,\n originalError: err,\n };\n }\n\n // Unknown error - try to extract useful info\n return {\n message: extractErrorDetail(err),\n type: 'unknown',\n retryable: false,\n originalError: err,\n };\n}\n\n/**\n * Extract retry-after header value from error.\n */\nfunction extractRetryAfter(error: Record<string, unknown>): number | undefined {\n const headers = error.headers as Record<string, unknown> | undefined;\n const retryAfter = error.retryAfter || headers?.['retry-after'];\n if (typeof retryAfter === 'number') {\n return retryAfter * 1000; // Convert seconds to ms\n }\n if (typeof retryAfter === 'string') {\n const seconds = parseInt(retryAfter, 10);\n if (!isNaN(seconds)) {\n return seconds * 1000;\n }\n }\n return undefined;\n}\n\n/**\n * Extract a useful error detail from an error object.\n */\nfunction extractErrorDetail(error: Error): string {\n const errorObj = error as unknown as Record<string, unknown>;\n\n // Try to get a specific error message from common API error formats\n if (errorObj.error && typeof errorObj.error === 'object') {\n const apiError = errorObj.error as Record<string, unknown>;\n if (apiError.message) return String(apiError.message);\n }\n\n if (errorObj.message) return String(errorObj.message);\n if (errorObj.detail) return String(errorObj.detail);\n if (errorObj.reason) return String(errorObj.reason);\n\n // Clean up the error message\n let message = error.message;\n\n // Remove common prefixes\n message = message.replace(/^(error|exception|failed):\\s*/i, '');\n\n // Truncate very long messages\n if (message.length > 200) {\n message = message.substring(0, 200) + '...';\n }\n\n return message || 'An unknown error occurred';\n}\n\n/**\n * Sleep for a given number of milliseconds.\n */\nexport function sleep(ms: number): Promise<void> {\n return new Promise(resolve => setTimeout(resolve, ms));\n}\n\n/**\n * Retry a function with exponential backoff.\n */\nexport async function withRetry<T>(\n fn: () => Promise<T>,\n options: {\n maxRetries?: number;\n initialDelay?: number;\n maxDelay?: number;\n onRetry?: (error: ParsedError, attempt: number) => void;\n } = {},\n): Promise<T> {\n const { maxRetries = 3, initialDelay = 1000, maxDelay = 30000, onRetry } = options;\n\n let lastError: ParsedError | undefined;\n\n for (let attempt = 0; attempt <= maxRetries; attempt++) {\n try {\n return await fn();\n } catch (error) {\n lastError = parseError(error);\n\n // Don't retry non-retryable errors\n if (!lastError.retryable || attempt === maxRetries) {\n throw lastError.originalError;\n }\n\n // Calculate delay with exponential backoff\n const delay = Math.min(lastError.retryDelay || initialDelay * Math.pow(2, attempt), maxDelay);\n\n if (onRetry) {\n onRetry(lastError, attempt + 1);\n }\n\n await sleep(delay);\n }\n }\n\n // Should never reach here, but TypeScript needs this\n throw lastError?.originalError || new Error('Retry failed');\n}\n"],"mappings":";;;;;;;;;AAuCA,SAAS,qBAAqB,OAAoC;CAChE,IAAI,iBAAiB,OAAO;EAC1B,IAAI,MAAM,iBAAiB,SAAS,MAAM,MAAM,SAC9C,OAAO,MAAM,MAAM;EAGrB,IAAI,OAAO,MAAM,UAAU,YAAY,MAAM,MAAM,KAAK,CAAC,CAAC,SAAS,GACjE,OAAO,MAAM;EAGf,IAAI,MAAM,QAAQ,KAAK,CAAC,CAAC,SAAS,GAChC,OAAO,MAAM;CAEjB;CAEA,IAAI,OAAO,UAAU,YAAY,MAAM,KAAK,CAAC,CAAC,SAAS,GACrD,OAAO;CAGT,IAAI,SAAS,OAAO,UAAU,UAAU;EACtC,MAAM,WAAW;EACjB,MAAM,aAAa;GAAC,SAAS;GAAY,SAAS;GAAU,SAAS;GAAS,SAAS;EAAa;EAEpG,KAAK,MAAM,aAAa,YACtB,IAAI,OAAO,cAAc,YAAY,UAAU,KAAK,CAAC,CAAC,SAAS,GAC7D,OAAO;CAGb;AAGF;AAEA,SAAS,kBAAkB,OAAoC;CAC7D,IAAI,CAAC,SAAS,OAAO,UAAU,UAC7B;CAGF,MAAM,aAAwB,CAAC;CAC/B,MAAM,WAAW;CACjB,WAAW,KAAK,SAAS,eAAe,SAAS,MAAM;CAEvD,IAAI,SAAS,YAAY,OAAO,SAAS,aAAa,UAAU;EAC9D,MAAM,WAAW,SAAS;EAC1B,WAAW,KAAK,SAAS,eAAe,SAAS,MAAM;CACzD;CAEA,KAAK,MAAM,aAAa,YACtB,IAAI,OAAO,cAAc,YAAY,UAAU,KAAK,CAAC,CAAC,SAAS,GAC7D,OAAO;AAKb;;AAGA,SAAS,kBAAkB,OAA4D;CACrF,OACE,OAAO,UAAU,YACjB,UAAU,QACV,UAAU,SACV,OAAO,MAAM,SAAS,YACtB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AAa,YAAY,YACtC,MAAM,UAAU;EAIlB,MAAM,QAAQ,KAAK,IAAI,UAAU,cAAc,eAAe,KAAK,IAAI,GAAG,OAAO,GAAG,QAAQ;EAE5F,IAAI,SACF,QAAQ,WAAW,UAAU,CAAC;EAGhC,MAAM,MAAM,KAAK;CACnB;CAIF,MAAM,WAAW,iCAAiB,IAAI,MAAM,cAAc;AAC5D"}
|
|
1
|
+
{"version":3,"file":"errors.js","names":[],"sources":["../../src/utils/errors.ts"],"sourcesContent":["/**\n * Error handling utilities for the Mastra Code TUI.\n * Parses API errors and provides user-friendly messages.\n */\n\nimport { classifyProviderError } from '@mastra/core/error';\n\nimport { PROVIDER_AUTH_REQUIRED_ERROR } from '../auth/provider-auth-error.js';\n\nexport interface ParsedError {\n /** User-friendly error message */\n message: string;\n /** Extra diagnostic detail to surface to the user */\n detail?: string;\n /** Request URL involved in the failure, when available */\n requestUrl?: string;\n /** Error type for categorization */\n type: ErrorType;\n /** Whether this error is retryable */\n retryable: boolean;\n /** Suggested retry delay in ms (if retryable) */\n retryDelay?: number;\n /** Original error for debugging */\n originalError: Error;\n}\n\nexport type ErrorType =\n | 'rate_limit'\n | 'quota'\n | 'auth'\n | 'network'\n | 'timeout'\n | 'invalid_request'\n | 'server_error'\n | 'model_not_found'\n | 'context_length'\n | 'content_filter'\n | 'unknown';\n\n/**\n * Parse an error and return a user-friendly representation.\n */\nfunction summarizeErrorDetail(error: unknown): string | undefined {\n if (error instanceof Error) {\n if (error.cause instanceof Error && error.cause.message) {\n return error.cause.message;\n }\n\n if (typeof error.cause === 'string' && error.cause.trim().length > 0) {\n return error.cause;\n }\n\n if (error.message.trim().length > 0) {\n return error.message;\n }\n }\n\n if (typeof error === 'string' && error.trim().length > 0) {\n return error;\n }\n\n if (error && typeof error === 'object') {\n const errorObj = error as Record<string, unknown>;\n const candidates = [errorObj['message'], errorObj['cause'], errorObj['code'], errorObj['statusText']];\n\n for (const candidate of candidates) {\n if (typeof candidate === 'string' && candidate.trim().length > 0) {\n return candidate;\n }\n }\n }\n\n return undefined;\n}\n\nfunction extractRequestUrl(error: unknown): string | undefined {\n if (!error || typeof error !== 'object') {\n return undefined;\n }\n\n const candidates: unknown[] = [];\n const errorObj = error as Record<string, unknown>;\n candidates.push(errorObj['requestUrl'], errorObj['url']);\n\n if (errorObj['cause'] && typeof errorObj['cause'] === 'object') {\n const causeObj = errorObj['cause'] as Record<string, unknown>;\n candidates.push(causeObj['requestUrl'], causeObj['url']);\n }\n\n for (const candidate of candidates) {\n if (typeof candidate === 'string' && candidate.trim().length > 0) {\n return candidate;\n }\n }\n\n return undefined;\n}\n\n/** A flattened error crossing the wire: the server sends `{ name, message }`, not an `Error`. */\nfunction isSerializedError(value: unknown): value is { name: string; message: string } {\n return (\n typeof value === 'object' &&\n value !== null &&\n 'name' in value &&\n typeof value.name === 'string' &&\n 'message' in value &&\n typeof value.message === 'string'\n );\n}\n\nfunction toError(error: unknown): Error {\n if (error instanceof Error) return error;\n if (!isSerializedError(error)) return new Error(String(error));\n const rebuilt = new Error(error.message);\n rebuilt.name = error.name;\n return rebuilt;\n}\n\nfunction errorTypeOf(error: unknown, message: string, status: unknown): ErrorType {\n const kind = classifyProviderError(typeof status === 'number' ? { statusCode: status, cause: error } : error);\n if (kind === 'quota') return 'quota';\n if (kind === 'rate_limited' || status === 429 || message.includes('429')) return 'rate_limit';\n if (\n kind === 'auth' ||\n status === 401 ||\n status === 403 ||\n (kind !== 'unavailable' &&\n (message.includes('unauthorized') || message.includes('authentication') || message.includes('api key')))\n ) {\n return 'auth';\n }\n if (\n message.includes('network') ||\n message.includes('econnrefused') ||\n message.includes('enotfound') ||\n message.includes('fetch failed') ||\n message.includes('connection')\n ) {\n return 'network';\n }\n if (kind === 'timeout') return 'timeout';\n if (kind === 'model_rejected' || message.includes('does not exist')) return 'model_not_found';\n if (\n kind === 'context_overflow' ||\n message.includes('context length') ||\n message.includes('too many tokens') ||\n message.includes('token limit')\n ) {\n return 'context_length';\n }\n if (\n message.includes('content filter') ||\n message.includes('content_filter') ||\n message.includes('content policy') ||\n message.includes('safety') ||\n message.includes('prohibited')\n ) {\n return 'content_filter';\n }\n if (kind === 'unavailable' || (typeof status === 'number' && status >= 500 && status < 600)) return 'server_error';\n if (\n kind === 'invalid_request' ||\n kind === 'tool_history_rejected' ||\n status === 400 ||\n message.includes('invalid request') ||\n message.includes('bad request')\n ) {\n return 'invalid_request';\n }\n return 'unknown';\n}\n\nexport function parseError(error: unknown): ParsedError {\n const err = toError(error);\n const errorObj = (typeof error === 'object' && error !== null ? error : {}) as Record<string, unknown>;\n const detail = summarizeErrorDetail(error);\n const requestUrl = extractRequestUrl(error);\n\n // Matched by name, not instance: the error may have crossed a serialization boundary.\n if (err.name === PROVIDER_AUTH_REQUIRED_ERROR) {\n return { message: err.message, detail, requestUrl, type: 'auth', retryable: false, originalError: err };\n }\n\n const message = err.message.toLowerCase();\n const type = errorTypeOf(error, message, errorObj.statusCode ?? errorObj.status);\n\n switch (type) {\n case 'quota':\n return {\n message: 'Usage quota exhausted for this provider account.',\n detail,\n requestUrl,\n type,\n retryable: false,\n originalError: err,\n };\n case 'rate_limit':\n return {\n message: 'Rate limited. Please wait a moment before trying again.',\n type,\n retryable: true,\n retryDelay: extractRetryAfter(errorObj) || 5000,\n originalError: err,\n };\n case 'auth':\n return {\n message:\n (errorObj.statusCode ?? errorObj.status) === 403\n ? 'Access denied. You may not have permission to use this model.'\n : 'Authentication failed. Check the credential configured for this provider.',\n detail,\n requestUrl,\n type,\n retryable: false,\n originalError: err,\n };\n case 'network':\n return {\n message: 'Network error while contacting the provider or gateway.',\n detail,\n requestUrl,\n type,\n retryable: true,\n retryDelay: 2000,\n originalError: err,\n };\n case 'timeout':\n return {\n message: 'Request timed out. The server may be overloaded.',\n type,\n retryable: true,\n retryDelay: 3000,\n originalError: err,\n };\n case 'model_not_found':\n return {\n message: 'Model not found. Please select a different model with /models.',\n type,\n retryable: false,\n originalError: err,\n };\n case 'context_length':\n return {\n message: 'Message too long. Try starting a new thread with /new.',\n type,\n retryable: false,\n originalError: err,\n };\n case 'content_filter':\n return {\n message: \"Content was filtered by the model's safety system.\",\n type,\n retryable: false,\n originalError: err,\n };\n case 'server_error':\n return {\n message: 'Server error. The API may be experiencing issues.',\n type,\n retryable: true,\n retryDelay: 5000,\n originalError: err,\n };\n case 'invalid_request':\n return {\n message: `Invalid request: ${extractErrorDetail(err)}`,\n type,\n retryable: false,\n originalError: err,\n };\n case 'unknown':\n return {\n message: extractErrorDetail(err),\n type,\n retryable: false,\n originalError: err,\n };\n }\n}\n\n/**\n * Extract retry-after header value from error.\n */\nfunction extractRetryAfter(error: Record<string, unknown>): number | undefined {\n const headers = error.headers as Record<string, unknown> | undefined;\n const retryAfter = error.retryAfter || headers?.['retry-after'];\n if (typeof retryAfter === 'number') {\n return retryAfter * 1000; // Convert seconds to ms\n }\n if (typeof retryAfter === 'string') {\n const seconds = parseInt(retryAfter, 10);\n if (!isNaN(seconds)) {\n return seconds * 1000;\n }\n }\n return undefined;\n}\n\n/**\n * Extract a useful error detail from an error object.\n */\nfunction extractErrorDetail(error: Error): string {\n const errorObj = error as unknown as Record<string, unknown>;\n\n // Try to get a specific error message from common API error formats\n if (errorObj.error && typeof errorObj.error === 'object') {\n const apiError = errorObj.error as Record<string, unknown>;\n if (apiError.message) return String(apiError.message);\n }\n\n if (errorObj.message) return String(errorObj.message);\n if (errorObj.detail) return String(errorObj.detail);\n if (errorObj.reason) return String(errorObj.reason);\n\n // Clean up the error message\n let message = error.message;\n\n // Remove common prefixes\n message = message.replace(/^(error|exception|failed):\\s*/i, '');\n\n // Truncate very long messages\n if (message.length > 200) {\n message = message.substring(0, 200) + '...';\n }\n\n return message || 'An unknown error occurred';\n}\n\n/**\n * Sleep for a given number of milliseconds.\n */\nexport function sleep(ms: number): Promise<void> {\n return new Promise(resolve => setTimeout(resolve, ms));\n}\n\n/**\n * Retry a function with exponential backoff.\n */\nexport async function withRetry<T>(\n fn: () => Promise<T>,\n options: {\n maxRetries?: number;\n initialDelay?: number;\n maxDelay?: number;\n onRetry?: (error: ParsedError, attempt: number) => void;\n } = {},\n): Promise<T> {\n const { maxRetries = 3, initialDelay = 1000, maxDelay = 30000, onRetry } = options;\n\n let lastError: ParsedError | undefined;\n\n for (let attempt = 0; attempt <= maxRetries; attempt++) {\n try {\n return await fn();\n } catch (error) {\n lastError = parseError(error);\n\n // Don't retry non-retryable errors\n if (!lastError.retryable || attempt === maxRetries) {\n throw lastError.originalError;\n }\n\n // Calculate delay with exponential backoff\n const delay = Math.min(lastError.retryDelay || initialDelay * Math.pow(2, attempt), maxDelay);\n\n if (onRetry) {\n onRetry(lastError, attempt + 1);\n }\n\n await sleep(delay);\n }\n }\n\n // Should never reach here, but TypeScript needs this\n throw lastError?.originalError || new Error('Retry failed');\n}\n"],"mappings":";;;;;;;;;;AA0CA,SAAS,qBAAqB,OAAoC;CAChE,IAAI,iBAAiB,OAAO;EAC1B,IAAI,MAAM,iBAAiB,SAAS,MAAM,MAAM,SAC9C,OAAO,MAAM,MAAM;EAGrB,IAAI,OAAO,MAAM,UAAU,YAAY,MAAM,MAAM,KAAK,CAAC,CAAC,SAAS,GACjE,OAAO,MAAM;EAGf,IAAI,MAAM,QAAQ,KAAK,CAAC,CAAC,SAAS,GAChC,OAAO,MAAM;CAEjB;CAEA,IAAI,OAAO,UAAU,YAAY,MAAM,KAAK,CAAC,CAAC,SAAS,GACrD,OAAO;CAGT,IAAI,SAAS,OAAO,UAAU,UAAU;EACtC,MAAM,WAAW;EACjB,MAAM,aAAa;GAAC,SAAS;GAAY,SAAS;GAAU,SAAS;GAAS,SAAS;EAAa;EAEpG,KAAK,MAAM,aAAa,YACtB,IAAI,OAAO,cAAc,YAAY,UAAU,KAAK,CAAC,CAAC,SAAS,GAC7D,OAAO;CAGb;AAGF;AAEA,SAAS,kBAAkB,OAAoC;CAC7D,IAAI,CAAC,SAAS,OAAO,UAAU,UAC7B;CAGF,MAAM,aAAwB,CAAC;CAC/B,MAAM,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QAAQ,UAAU,GAAG,GAAG,IAAI;CAGxC,OAAO,WAAW;AACpB;;;;AAKA,SAAgB,MAAM,IAA2B;CAC/C,OAAO,IAAI,SAAQ,YAAW,WAAW,SAAS,EAAE,CAAC;AACvD;;;;AAKA,eAAsB,UACpB,IACA,UAKI,CAAC,GACO;CACZ,MAAM,EAAE,aAAa,GAAG,eAAe,KAAM,WAAW,KAAO,YAAY;CAE3E,IAAI;CAEJ,KAAK,IAAI,UAAU,GAAG,WAAW,YAAY,WAC3C,IAAI;EACF,OAAO,MAAM,GAAG;CAClB,SAAS,OAAO;EACd,YAAY,WAAW,KAAK;EAG5B,IAAI,CAAC,UAAU,aAAa,YAAY,YACtC,MAAM,UAAU;EAIlB,MAAM,QAAQ,KAAK,IAAI,UAAU,cAAc,eAAe,KAAK,IAAI,GAAG,OAAO,GAAG,QAAQ;EAE5F,IAAI,SACF,QAAQ,WAAW,UAAU,CAAC;EAGhC,MAAM,MAAM,KAAK;CACnB;CAIF,MAAM,WAAW,iCAAiB,IAAI,MAAM,cAAc;AAC5D"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { GatewayRegistry } from "@mastra/core/llm";
|
|
2
|
-
|
|
2
|
+
// src/utils/gateway-sync.ts
|
|
3
3
|
/**
|
|
4
4
|
* Gateway sync utility for keeping the model registry up to date.
|
|
5
5
|
*
|
|
@@ -55,7 +55,6 @@ function stopGatewaySync() {
|
|
|
55
55
|
syncInterval = null;
|
|
56
56
|
}
|
|
57
57
|
}
|
|
58
|
-
//#endregion
|
|
59
58
|
export { startGatewaySync, stopGatewaySync, syncGateways };
|
|
60
59
|
|
|
61
60
|
//# sourceMappingURL=gateway-sync.js.map
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
// src/utils/local-observability.ts
|
|
2
2
|
/**
|
|
3
3
|
* Age limits for the local trace store: 14 days for spans, metrics and logs,
|
|
4
4
|
* 30 days for scores and feedback. Spans, logs and scores use the same windows
|
|
@@ -51,7 +51,6 @@ async function openLocalObservabilityStore(path) {
|
|
|
51
51
|
pruned: pruneExistingTables(store).catch(() => [])
|
|
52
52
|
};
|
|
53
53
|
}
|
|
54
|
-
//#endregion
|
|
55
54
|
export { LOCAL_OBSERVABILITY_RETENTION, openLocalObservabilityStore };
|
|
56
55
|
|
|
57
56
|
//# sourceMappingURL=local-observability.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { getAppDataDir } from "./project.js";
|
|
2
2
|
import path from "path";
|
|
3
3
|
import fs from "fs";
|
|
4
|
-
|
|
4
|
+
// src/utils/maintenance-lock.ts
|
|
5
5
|
/**
|
|
6
6
|
* Mutual exclusion between storage maintenance (`mastracode prune`) and running
|
|
7
7
|
* mastracode sessions, using the same pid-file / stale-PID pattern as
|
|
@@ -193,7 +193,6 @@ function acquireMaintenanceLock() {
|
|
|
193
193
|
}
|
|
194
194
|
return release;
|
|
195
195
|
}
|
|
196
|
-
//#endregion
|
|
197
196
|
export { MALFORMED_PID_FILE_GRACE_MS, MaintenanceLockError, UNKNOWN_OWNER, acquireMaintenanceLock, getLiveSessionPids, getMaintenanceLockOwner, getMaintenanceLockPath, registerSession, registerSessionAndWaitForMaintenance, resetSessionRegistrationsForTesting, unregisterSession };
|
|
198
197
|
|
|
199
198
|
//# sourceMappingURL=maintenance-lock.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { notificationDispatchLeaseKey } from "./signals-pubsub.js";
|
|
2
2
|
import { dispatchDueNotifications } from "@mastra/core/notifications";
|
|
3
3
|
import { AsyncLocalStorage } from "async_hooks";
|
|
4
|
-
|
|
4
|
+
// src/utils/notification-dispatch.ts
|
|
5
5
|
const DEFAULT_INTERVAL_MS = 1e4;
|
|
6
6
|
const DEFAULT_LEASE_TTL_MS = 6e4;
|
|
7
7
|
/**
|
|
@@ -125,7 +125,6 @@ function createResourceNotificationDispatcher(options) {
|
|
|
125
125
|
tick
|
|
126
126
|
};
|
|
127
127
|
}
|
|
128
|
-
//#endregion
|
|
129
128
|
export { createResourceNotificationDispatcher, isDispatchingNotificationsFor, shouldHoldNotificationDelivery };
|
|
130
129
|
|
|
131
130
|
//# sourceMappingURL=notification-dispatch.js.map
|
package/dist/utils/open-url.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { spawn } from "child_process";
|
|
2
|
-
|
|
2
|
+
// src/utils/open-url.ts
|
|
3
3
|
/**
|
|
4
4
|
* Best-effort browser opening for OAuth and other login flows.
|
|
5
5
|
*/
|
|
@@ -24,7 +24,6 @@ function openUrlInBrowser(url) {
|
|
|
24
24
|
child.on("error", () => {});
|
|
25
25
|
child.unref();
|
|
26
26
|
}
|
|
27
|
-
//#endregion
|
|
28
27
|
export { openUrlInBrowser };
|
|
29
28
|
|
|
30
29
|
//# sourceMappingURL=open-url.js.map
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import path from "path";
|
|
2
|
-
|
|
2
|
+
// src/utils/path-security.ts
|
|
3
3
|
function isPathWithinRoot(candidatePath, rootPath) {
|
|
4
4
|
const relativePath = path.relative(rootPath, candidatePath);
|
|
5
5
|
return relativePath === "" || !relativePath.startsWith(`..${path.sep}`) && relativePath !== ".." && !path.isAbsolute(relativePath);
|
|
6
6
|
}
|
|
7
|
-
//#endregion
|
|
8
7
|
export { isPathWithinRoot };
|
|
9
8
|
|
|
10
9
|
//# sourceMappingURL=path-security.js.map
|
package/dist/utils/plan-diff.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
// src/utils/plan-diff.ts
|
|
2
2
|
/** Produce structured diff entries between two plan texts using an LCS diff. */
|
|
3
3
|
function generatePlanDiff(oldText, newText) {
|
|
4
4
|
const oldLines = oldText.split(/\r?\n/);
|
|
@@ -56,7 +56,6 @@ function shouldShowDiff(previousPlan, plan, maxChangedRatio = .5) {
|
|
|
56
56
|
if (changed === 0) return false;
|
|
57
57
|
return changed / Math.max(entries.length, 1) <= maxChangedRatio;
|
|
58
58
|
}
|
|
59
|
-
//#endregion
|
|
60
59
|
export { generatePlanDiff, shouldShowDiff };
|
|
61
60
|
|
|
62
61
|
//# sourceMappingURL=plan-diff.js.map
|
package/dist/utils/plans.js
CHANGED
|
@@ -2,7 +2,7 @@ import { DEFAULT_CONFIG_DIR } from "../constants.js";
|
|
|
2
2
|
import { getAppDataDir } from "./project.js";
|
|
3
3
|
import path from "path";
|
|
4
4
|
import fs from "fs/promises";
|
|
5
|
-
|
|
5
|
+
// src/utils/plans.ts
|
|
6
6
|
/** Global plans directory for approved-plan archives. */
|
|
7
7
|
function getPlansDir() {
|
|
8
8
|
return process.env.MASTRA_PLANS_DIR ?? path.join(getAppDataDir(), "plans");
|
|
@@ -111,7 +111,6 @@ async function approvePlanFile(opts) {
|
|
|
111
111
|
});
|
|
112
112
|
return path.basename(planPath);
|
|
113
113
|
}
|
|
114
|
-
//#endregion
|
|
115
114
|
export { approvePlanFile, getLocalPlansDir, getLocalPlansRelativeDir, getPlanFilename, getPlansDir, getSuggestedPlanRelativePath, isPlanFilePath, readPlanFile, resolvePlanPath, savePlanToDisk };
|
|
116
115
|
|
|
117
116
|
//# sourceMappingURL=plans.js.map
|
package/dist/utils/project.js
CHANGED
|
@@ -4,7 +4,7 @@ import { createHash } from "crypto";
|
|
|
4
4
|
import fs from "fs";
|
|
5
5
|
import { execFile, execSync } from "child_process";
|
|
6
6
|
import os from "os";
|
|
7
|
-
|
|
7
|
+
// src/utils/project.ts
|
|
8
8
|
/**
|
|
9
9
|
* Project detection utilities
|
|
10
10
|
*
|
|
@@ -358,7 +358,6 @@ function loadStringField(filePath, field) {
|
|
|
358
358
|
return null;
|
|
359
359
|
}
|
|
360
360
|
}
|
|
361
|
-
//#endregion
|
|
362
361
|
export { detectProject, getAppDataDir, getCurrentGitBranch, getCurrentGitBranchAsync, getDatabasePath, getObservabilityDatabasePath, getOmScope, getResourceIdOverride, getStorageConfig, getUserId, getUserName, getVectorDatabasePath };
|
|
363
362
|
|
|
364
363
|
//# sourceMappingURL=project.js.map
|
package/dist/utils/prune-cli.js
CHANGED
|
@@ -6,7 +6,7 @@ import { DEFAULT_RETENTION, createStorageMaintenance, resolveLocalDbFiles, runSt
|
|
|
6
6
|
import { createStorage, createVectorStore } from "./storage-factory.js";
|
|
7
7
|
import path from "path";
|
|
8
8
|
import { LibSQLVector } from "@mastra/libsql";
|
|
9
|
-
|
|
9
|
+
// src/utils/prune-cli.ts
|
|
10
10
|
/**
|
|
11
11
|
* `mastracode prune` — storage maintenance from a non-interactive shell.
|
|
12
12
|
*
|
|
@@ -121,7 +121,6 @@ function describeStorageTarget(config) {
|
|
|
121
121
|
if (config.connectionString) return `pg ${redactUrl(config.connectionString)}`;
|
|
122
122
|
return `pg postgres://${`${config.host ?? "localhost"}${config.port ? `:${config.port}` : ""}`}/${config.database ?? ""}`;
|
|
123
123
|
}
|
|
124
|
-
//#endregion
|
|
125
124
|
export { describeStorageTarget, runPruneCommand };
|
|
126
125
|
|
|
127
126
|
//# sourceMappingURL=prune-cli.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { isAbsolute, join } from "path";
|
|
2
2
|
import { mkdir } from "fs/promises";
|
|
3
3
|
import { PubSub, UnixSocketPubSub } from "@mastra/core/events";
|
|
4
|
-
|
|
4
|
+
// src/utils/signals-pubsub.ts
|
|
5
5
|
const DEFAULT_SOCKET_ROOT = "/tmp/mc";
|
|
6
6
|
const SHARED_SCOPE_DIR = "_shared";
|
|
7
7
|
const THREAD_STREAM_PREFIX = "agent.thread-stream.";
|
|
@@ -406,7 +406,6 @@ var SignalsPubSub = class extends PubSub {
|
|
|
406
406
|
function createSignalsPubSub(resourceId, options) {
|
|
407
407
|
return new SignalsPubSub(resourceId, options);
|
|
408
408
|
}
|
|
409
|
-
//#endregion
|
|
410
409
|
export { createSignalsPubSub, notificationDispatchLeaseKey };
|
|
411
410
|
|
|
412
411
|
//# sourceMappingURL=signals-pubsub.js.map
|
|
@@ -3,7 +3,7 @@ import { isPathWithinRoot } from "./path-security.js";
|
|
|
3
3
|
import * as path$1 from "path";
|
|
4
4
|
import { promises } from "fs";
|
|
5
5
|
import { parse } from "yaml";
|
|
6
|
-
|
|
6
|
+
// src/utils/slash-command-loader.ts
|
|
7
7
|
/**
|
|
8
8
|
* Parse a command file and extract metadata and template
|
|
9
9
|
* Supports both frontmatter-based and plain markdown files
|
|
@@ -136,7 +136,6 @@ Shell commands with !command will be executed and output included.
|
|
|
136
136
|
console.error("Error initializing commands directory:", error);
|
|
137
137
|
}
|
|
138
138
|
}
|
|
139
|
-
//#endregion
|
|
140
139
|
export { extractCommandName, getProjectCommandsDir, initCommandsDirectory, loadCustomCommands, parseCommandFile, scanCommandDirectory };
|
|
141
140
|
|
|
142
141
|
//# sourceMappingURL=slash-command-loader.js.map
|