@mastra/code-sdk 1.5.0-alpha.11 → 1.5.0-alpha.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (56) hide show
  1. package/CHANGELOG.md +0 -106
  2. package/dist/agents/instructions.d.ts +1 -12
  3. package/dist/agents/instructions.d.ts.map +1 -1
  4. package/dist/agents/instructions.js +5 -23
  5. package/dist/agents/instructions.js.map +1 -1
  6. package/dist/agents/memory.d.ts.map +1 -1
  7. package/dist/agents/memory.js +32 -35
  8. package/dist/agents/memory.js.map +1 -1
  9. package/dist/agents/model.d.ts +4 -11
  10. package/dist/agents/model.d.ts.map +1 -1
  11. package/dist/agents/model.js +1 -2
  12. package/dist/agents/model.js.map +1 -1
  13. package/dist/agents/prompts/agent-instructions.d.ts +0 -9
  14. package/dist/agents/prompts/agent-instructions.d.ts.map +1 -1
  15. package/dist/agents/prompts/agent-instructions.js +4 -14
  16. package/dist/agents/prompts/agent-instructions.js.map +1 -1
  17. package/dist/agents/prompts/index.d.ts +0 -28
  18. package/dist/agents/prompts/index.d.ts.map +1 -1
  19. package/dist/agents/prompts/index.js +9 -48
  20. package/dist/agents/prompts/index.js.map +1 -1
  21. package/dist/agents/tools.d.ts +1 -2
  22. package/dist/agents/tools.d.ts.map +1 -1
  23. package/dist/agents/tools.js +5 -4
  24. package/dist/agents/tools.js.map +1 -1
  25. package/dist/onboarding/settings.d.ts +6 -12
  26. package/dist/onboarding/settings.d.ts.map +1 -1
  27. package/dist/onboarding/settings.js +23 -18
  28. package/dist/onboarding/settings.js.map +1 -1
  29. package/dist/providers/openai-codex.d.ts +4 -3
  30. package/dist/providers/openai-codex.d.ts.map +1 -1
  31. package/dist/providers/openai-codex.js +9 -1
  32. package/dist/providers/openai-codex.js.map +1 -1
  33. package/dist/schema.d.ts +3 -4
  34. package/dist/schema.d.ts.map +1 -1
  35. package/dist/schema.js +8 -2
  36. package/dist/schema.js.map +1 -1
  37. package/dist/tools/index.d.ts +1 -1
  38. package/dist/tools/index.d.ts.map +1 -1
  39. package/dist/tools/index.js +2 -2
  40. package/dist/tools/web-search.d.ts +2 -81
  41. package/dist/tools/web-search.d.ts.map +1 -1
  42. package/dist/tools/web-search.js +4 -98
  43. package/dist/tools/web-search.js.map +1 -1
  44. package/dist/workflows/register-primitives.d.ts +4 -4
  45. package/dist/workflows/register-primitives.d.ts.map +1 -1
  46. package/dist/workflows/register-primitives.js +4 -5
  47. package/dist/workflows/register-primitives.js.map +1 -1
  48. package/package.json +11 -12
  49. package/dist/agents/context-audit.d.ts +0 -84
  50. package/dist/agents/context-audit.d.ts.map +0 -1
  51. package/dist/agents/context-audit.js +0 -118
  52. package/dist/agents/context-audit.js.map +0 -1
  53. package/dist/thinking.d.ts +0 -33
  54. package/dist/thinking.d.ts.map +0 -1
  55. package/dist/thinking.js +0 -58
  56. package/dist/thinking.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"schema.js","names":[],"sources":["../src/schema.ts"],"sourcesContent":["import { z } from 'zod';\nimport { DEFAULT_CONFIG_DIR, DEFAULT_OM_MODEL_ID } from './constants.js';\nimport { THINKING_LEVEL_VALUES } from './thinking.js';\nimport type { ThinkingLevelSetting } from './thinking.js';\n\nexport type PermissionPolicy = 'allow' | 'ask' | 'deny';\n\nexport type MastraCodeSessionState = {\n currentModelId: string;\n modeId: string;\n};\n\nexport type MastraCodeComposedState = MastraCodeState & MastraCodeSessionState;\n\nexport interface MastraCodeState {\n [key: string]: unknown;\n [key: `subagentModelId_${string}`]: string | undefined;\n subagentModelId?: string;\n projectPath?: string;\n projectName?: string;\n /** Factory project that owns this session. */\n factoryProjectId?: string;\n /** Authoritative organization id seeded by factory at session construction. */\n factoryOrgId?: string;\n /** Linked repository used by this session when source-control execution is required. */\n projectRepositoryId?: string;\n /** Persisted sandbox id for reattaching the project's cloud workspace. */\n sandboxId?: string;\n /** Path inside the sandbox the repo is cloned into. */\n sandboxWorkdir?: string;\n /** Active git worktree path inside the sandbox for the current unit of work. */\n worktreePath?: string;\n /** Active feature branch checked out in the worktree. */\n branch?: string;\n /**\n * The session's checkout contains third-party content (e.g. a PR branch\n * under review). Project-level instruction files (AGENTS.md, CLAUDE.md)\n * are attacker-writable there and must not be ingested into the system\n * prompt or injected as reminders.\n */\n untrustedCheckout?: boolean;\n /**\n * Trusted git ref (typically the PR's base branch) to serve project\n * instruction files from when the checkout is untrusted. Without it,\n * project-scope instruction files are skipped entirely.\n */\n baseRef?: string;\n /**\n * Skip the home-directory instruction files (~/.claude/AGENTS.md and\n * friends). Hosts running sessions for someone else set this so a run never\n * inherits the machine owner's personal configuration.\n */\n skipGlobalInstructions?: boolean;\n configDir: string;\n homeDir?: string;\n gitBranch?: string;\n lastCommand?: string;\n observerModelId: string;\n reflectorModelId: string;\n observationThreshold: number;\n reflectionThreshold: number;\n cavemanObservations: boolean;\n observeAttachments: 'auto' | boolean;\n omScope?: 'thread' | 'resource';\n /**\n * Session-level reasoning-effort override. When unset, the effective level is\n * resolved at request time from settings (`models.modeThinkingDefaults[mode]`\n * falling back to `preferences.thinkingLevel`).\n */\n thinkingLevel?: ThinkingLevelSetting;\n yolo: boolean;\n permissionRules: {\n categories: Record<string, PermissionPolicy>;\n tools: Record<string, PermissionPolicy>;\n };\n smartEditing: boolean;\n notifications: 'bell' | 'system' | 'both' | 'off';\n tasks: Array<{\n id?: string;\n content: string;\n status: 'pending' | 'in_progress' | 'completed';\n activeForm: string;\n }>;\n sandboxAllowedPaths: string[];\n pluginSkillPaths: string[];\n pluginCommandPaths: string[];\n pluginInstructions: string[];\n activePlan: {\n title: string;\n plan: string;\n approvedAt: string;\n } | null;\n activeBrowserSettings?: {\n enabled: boolean;\n provider: 'stagehand' | 'agent-browser';\n headless?: boolean;\n viewport?: { width: number; height: number } | 'window';\n cdpUrl?: string;\n stagehand?: {\n env: 'LOCAL' | 'BROWSERBASE';\n apiKey?: string;\n projectId?: string;\n };\n };\n}\n\nexport const stateSchema = z.object({\n // Session-scoped selection.\n // validates state against this schema, so they MUST be declared here — Zod\n // strips unknown keys on parse, which would otherwise silently discard the\n // seeded model and leave the controller with no model selected.\n currentModelId: z.string().optional(),\n modeId: z.string().optional(),\n subagentModelId: z.string().optional(),\n projectPath: z.string().optional(),\n projectName: z.string().optional(),\n factoryProjectId: z.string().optional(),\n factoryOrgId: z.string().optional(),\n projectRepositoryId: z.string().optional(),\n sandboxId: z.string().optional(),\n sandboxWorkdir: z.string().optional(),\n worktreePath: z.string().optional(),\n branch: z.string().optional(),\n // Session operates on an untrusted checkout — suppress AGENTS.md ingestion.\n untrustedCheckout: z.boolean().optional(),\n // Trusted ref to serve instruction files from on untrusted checkouts.\n baseRef: z.string().optional(),\n // Skip the operator machine's home-directory instruction files.\n skipGlobalInstructions: z.boolean().optional(),\n configDir: z.string().default(DEFAULT_CONFIG_DIR),\n homeDir: z.string().optional(),\n gitBranch: z.string().optional(),\n lastCommand: z.string().optional(),\n // Observational Memory model settings\n observerModelId: z.string().default(DEFAULT_OM_MODEL_ID),\n reflectorModelId: z.string().default(DEFAULT_OM_MODEL_ID),\n // Observational Memory threshold settings\n observationThreshold: z.number().default(30_000),\n reflectionThreshold: z.number().default(40_000),\n // Whether observations and reflections use the terse caveman-style instruction.\n // Off by default — caveman style is opt-in via `/om` settings; observers and\n // reflectors fall back to their built-in (prose) behavior unless enabled.\n cavemanObservations: z.boolean().default(false),\n // Whether OM forwards image/file attachment parts to the Observer LLM.\n // 'auto' (default) checks the provider capabilities registry to decide.\n // true/false forces the setting regardless of model capabilities.\n observeAttachments: z.union([z.literal('auto'), z.boolean()]).default('auto'),\n // Observational Memory scope — 'thread' (per-conversation) or 'resource' (shared across threads)\n omScope: z.enum(['thread', 'resource']).optional(),\n // Thinking level for model reasoning effort. Optional: absent means \"no\n // session override\" — the effective level is resolved from settings\n // (per-mode defaults, then the global preference) at request time.\n thinkingLevel: z.preprocess(value => (value === null ? undefined : value), z.enum(THINKING_LEVEL_VALUES).optional()),\n // YOLO mode — auto-approve all tool calls\n yolo: z.boolean().default(false),\n // Permission rules — per-category and per-tool approval policies\n permissionRules: z\n .object({\n categories: z.record(z.string(), z.enum(['allow', 'ask', 'deny'])).default({}),\n tools: z.record(z.string(), z.enum(['allow', 'ask', 'deny'])).default({}),\n })\n .default({ categories: {}, tools: {} }),\n // Smart editing mode — use AST-based analysis for code edits\n smartEditing: z.boolean().default(true),\n // Notification mode — alert when TUI needs user attention\n notifications: z.enum(['bell', 'system', 'both', 'off']).default('off'),\n // Task list (ephemeral per-thread, cleared on thread switch/creation)\n tasks: z\n .array(\n z.object({\n id: z.string().optional(),\n content: z.string(),\n status: z.enum(['pending', 'in_progress', 'completed']),\n activeForm: z.string(),\n }),\n )\n .default([]),\n // Sandbox allowed paths (per-thread, absolute paths allowed in addition to project root)\n sandboxAllowedPaths: z.array(z.string()).default([]),\n // Asset directories contributed by active plugins.\n pluginSkillPaths: z.array(z.string()).default([]),\n pluginCommandPaths: z.array(z.string()).default([]),\n pluginInstructions: z.array(z.string()).default([]),\n // Active plan (set when a plan is approved in Plan mode)\n activePlan: z\n .object({\n title: z.string(),\n plan: z.string(),\n approvedAt: z.string(),\n })\n .nullable()\n .default(null),\n // Active browser settings (tracks what's actually running vs. what's in the settings file)\n activeBrowserSettings: z\n .object({\n enabled: z.boolean(),\n provider: z.enum(['stagehand', 'agent-browser']),\n headless: z.boolean().optional(),\n viewport: z\n .union([\n z.object({\n width: z.number(),\n height: z.number(),\n }),\n z.literal('window'),\n ])\n .optional(),\n cdpUrl: z.string().optional(),\n stagehand: z\n .object({\n env: z.enum(['LOCAL', 'BROWSERBASE']),\n apiKey: z.string().optional(),\n projectId: z.string().optional(),\n })\n .optional(),\n })\n .optional(),\n});\n"],"mappings":";;;;AA0GA,MAAa,cAAc,EAAE,OAAO;CAKlC,gBAAgB,EAAE,OAAO,CAAC,CAAC,SAAS;CACpC,QAAQ,EAAE,OAAO,CAAC,CAAC,SAAS;CAC5B,iBAAiB,EAAE,OAAO,CAAC,CAAC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,CACV,QAAQ,IAAI;CAEf,uBAAuB,EACpB,OAAO;EACN,SAAS,EAAE,QAAQ;EACnB,UAAU,EAAE,KAAK,CAAC,aAAa,eAAe,CAAC;EAC/C,UAAU,EAAE,QAAQ,CAAC,CAAC,SAAS;EAC/B,UAAU,EACP,MAAM,CACL,EAAE,OAAO;GACP,OAAO,EAAE,OAAO;GAChB,QAAQ,EAAE,OAAO;EACnB,CAAC,GACD,EAAE,QAAQ,QAAQ,CACpB,CAAC,CAAC,CACD,SAAS;EACZ,QAAQ,EAAE,OAAO,CAAC,CAAC,SAAS;EAC5B,WAAW,EACR,OAAO;GACN,KAAK,EAAE,KAAK,CAAC,SAAS,aAAa,CAAC;GACpC,QAAQ,EAAE,OAAO,CAAC,CAAC,SAAS;GAC5B,WAAW,EAAE,OAAO,CAAC,CAAC,SAAS;EACjC,CAAC,CAAC,CACD,SAAS;CACd,CAAC,CAAC,CACD,SAAS;AACd,CAAC"}
1
+ {"version":3,"file":"schema.js","names":[],"sources":["../src/schema.ts"],"sourcesContent":["import { z } from 'zod';\nimport { DEFAULT_CONFIG_DIR, DEFAULT_OM_MODEL_ID } from './constants.js';\n\nexport type PermissionPolicy = 'allow' | 'ask' | 'deny';\n\nexport type MastraCodeSessionState = {\n currentModelId: string;\n modeId: string;\n};\n\nexport type MastraCodeComposedState = MastraCodeState & MastraCodeSessionState;\n\nexport interface MastraCodeState {\n [key: string]: unknown;\n [key: `subagentModelId_${string}`]: string | undefined;\n subagentModelId?: string;\n projectPath?: string;\n projectName?: string;\n /** Factory project that owns this session. */\n factoryProjectId?: string;\n /** Authoritative organization id seeded by factory at session construction. */\n factoryOrgId?: string;\n /** Linked repository used by this session when source-control execution is required. */\n projectRepositoryId?: string;\n /** Persisted sandbox id for reattaching the project's cloud workspace. */\n sandboxId?: string;\n /** Path inside the sandbox the repo is cloned into. */\n sandboxWorkdir?: string;\n /** Active git worktree path inside the sandbox for the current unit of work. */\n worktreePath?: string;\n /** Active feature branch checked out in the worktree. */\n branch?: string;\n /**\n * The session's checkout contains third-party content (e.g. a PR branch\n * under review). Project-level instruction files (AGENTS.md, CLAUDE.md)\n * are attacker-writable there and must not be ingested into the system\n * prompt or injected as reminders.\n */\n untrustedCheckout?: boolean;\n /**\n * Trusted git ref (typically the PR's base branch) to serve project\n * instruction files from when the checkout is untrusted. Without it,\n * project-scope instruction files are skipped entirely.\n */\n baseRef?: string;\n /**\n * Skip the home-directory instruction files (~/.claude/AGENTS.md and\n * friends). Hosts running sessions for someone else set this so a run never\n * inherits the machine owner's personal configuration.\n */\n skipGlobalInstructions?: boolean;\n configDir: string;\n homeDir?: string;\n gitBranch?: string;\n lastCommand?: string;\n observerModelId: string;\n reflectorModelId: string;\n observationThreshold: number;\n reflectionThreshold: number;\n cavemanObservations: boolean;\n observeAttachments: 'auto' | boolean;\n omScope?: 'thread' | 'resource';\n /**\n * Session-level reasoning-effort override. When unset, the effective level is\n * resolved at request time from settings (`models.modeThinkingDefaults[mode]`\n * falling back to `preferences.thinkingLevel`).\n */\n thinkingLevel?: 'off' | 'low' | 'medium' | 'high' | 'xhigh' | 'max';\n yolo: boolean;\n permissionRules: {\n categories: Record<string, PermissionPolicy>;\n tools: Record<string, PermissionPolicy>;\n };\n smartEditing: boolean;\n notifications: 'bell' | 'system' | 'both' | 'off';\n tasks: Array<{\n id?: string;\n content: string;\n status: 'pending' | 'in_progress' | 'completed';\n activeForm: string;\n }>;\n sandboxAllowedPaths: string[];\n pluginSkillPaths: string[];\n pluginCommandPaths: string[];\n pluginInstructions: string[];\n activePlan: {\n title: string;\n plan: string;\n approvedAt: string;\n } | null;\n activeBrowserSettings?: {\n enabled: boolean;\n provider: 'stagehand' | 'agent-browser';\n headless?: boolean;\n viewport?: { width: number; height: number } | 'window';\n cdpUrl?: string;\n stagehand?: {\n env: 'LOCAL' | 'BROWSERBASE';\n apiKey?: string;\n projectId?: string;\n };\n };\n}\n\nexport const stateSchema = z.object({\n // Session-scoped selection.\n // validates state against this schema, so they MUST be declared here — Zod\n // strips unknown keys on parse, which would otherwise silently discard the\n // seeded model and leave the controller with no model selected.\n currentModelId: z.string().optional(),\n modeId: z.string().optional(),\n subagentModelId: z.string().optional(),\n projectPath: z.string().optional(),\n projectName: z.string().optional(),\n factoryProjectId: z.string().optional(),\n factoryOrgId: z.string().optional(),\n projectRepositoryId: z.string().optional(),\n sandboxId: z.string().optional(),\n sandboxWorkdir: z.string().optional(),\n worktreePath: z.string().optional(),\n branch: z.string().optional(),\n // Session operates on an untrusted checkout — suppress AGENTS.md ingestion.\n untrustedCheckout: z.boolean().optional(),\n // Trusted ref to serve instruction files from on untrusted checkouts.\n baseRef: z.string().optional(),\n // Skip the operator machine's home-directory instruction files.\n skipGlobalInstructions: z.boolean().optional(),\n configDir: z.string().default(DEFAULT_CONFIG_DIR),\n homeDir: z.string().optional(),\n gitBranch: z.string().optional(),\n lastCommand: z.string().optional(),\n // Observational Memory model settings\n observerModelId: z.string().default(DEFAULT_OM_MODEL_ID),\n reflectorModelId: z.string().default(DEFAULT_OM_MODEL_ID),\n // Observational Memory threshold settings\n observationThreshold: z.number().default(30_000),\n reflectionThreshold: z.number().default(40_000),\n // Whether observations and reflections use the terse caveman-style instruction.\n // Off by default — caveman style is opt-in via `/om` settings; observers and\n // reflectors fall back to their built-in (prose) behavior unless enabled.\n cavemanObservations: z.boolean().default(false),\n // Whether OM forwards image/file attachment parts to the Observer LLM.\n // 'auto' (default) checks the provider capabilities registry to decide.\n // true/false forces the setting regardless of model capabilities.\n observeAttachments: z.union([z.literal('auto'), z.boolean()]).default('auto'),\n // Observational Memory scope — 'thread' (per-conversation) or 'resource' (shared across threads)\n omScope: z.enum(['thread', 'resource']).optional(),\n // Thinking level for model reasoning effort. Optional: absent means \"no\n // session override\" — the effective level is resolved from settings\n // (per-mode defaults, then the global preference) at request time.\n thinkingLevel: z.enum(['off', 'low', 'medium', 'high', 'xhigh', 'max']).optional(),\n // YOLO mode — auto-approve all tool calls\n yolo: z.boolean().default(false),\n // Permission rules — per-category and per-tool approval policies\n permissionRules: z\n .object({\n categories: z.record(z.string(), z.enum(['allow', 'ask', 'deny'])).default({}),\n tools: z.record(z.string(), z.enum(['allow', 'ask', 'deny'])).default({}),\n })\n .default({ categories: {}, tools: {} }),\n // Smart editing mode — use AST-based analysis for code edits\n smartEditing: z.boolean().default(true),\n // Notification mode — alert when TUI needs user attention\n notifications: z.enum(['bell', 'system', 'both', 'off']).default('off'),\n // Task list (ephemeral per-thread, cleared on thread switch/creation)\n tasks: z\n .array(\n z.object({\n id: z.string().optional(),\n content: z.string(),\n status: z.enum(['pending', 'in_progress', 'completed']),\n activeForm: z.string(),\n }),\n )\n .default([]),\n // Sandbox allowed paths (per-thread, absolute paths allowed in addition to project root)\n sandboxAllowedPaths: z.array(z.string()).default([]),\n // Asset directories contributed by active plugins.\n pluginSkillPaths: z.array(z.string()).default([]),\n pluginCommandPaths: z.array(z.string()).default([]),\n pluginInstructions: z.array(z.string()).default([]),\n // Active plan (set when a plan is approved in Plan mode)\n activePlan: z\n .object({\n title: z.string(),\n plan: z.string(),\n approvedAt: z.string(),\n })\n .nullable()\n .default(null),\n // Active browser settings (tracks what's actually running vs. what's in the settings file)\n activeBrowserSettings: z\n .object({\n enabled: z.boolean(),\n provider: z.enum(['stagehand', 'agent-browser']),\n headless: z.boolean().optional(),\n viewport: z\n .union([\n z.object({\n width: z.number(),\n height: z.number(),\n }),\n z.literal('window'),\n ])\n .optional(),\n cdpUrl: z.string().optional(),\n stagehand: z\n .object({\n env: z.enum(['LOCAL', 'BROWSERBASE']),\n apiKey: z.string().optional(),\n projectId: z.string().optional(),\n })\n .optional(),\n })\n .optional(),\n});\n"],"mappings":";;;AAwGA,MAAa,cAAc,EAAE,OAAO;CAKlC,gBAAgB,EAAE,OAAO,CAAC,CAAC,SAAS;CACpC,QAAQ,EAAE,OAAO,CAAC,CAAC,SAAS;CAC5B,iBAAiB,EAAE,OAAO,CAAC,CAAC,SAAS;CACrC,aAAa,EAAE,OAAO,CAAC,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AAS,EAAE,QAAQ;EACnB,UAAU,EAAE,KAAK,CAAC,aAAa,eAAe,CAAC;EAC/C,UAAU,EAAE,QAAQ,CAAC,CAAC,SAAS;EAC/B,UAAU,EACP,MAAM,CACL,EAAE,OAAO;GACP,OAAO,EAAE,OAAO;GAChB,QAAQ,EAAE,OAAO;EACnB,CAAC,GACD,EAAE,QAAQ,QAAQ,CACpB,CAAC,CAAC,CACD,SAAS;EACZ,QAAQ,EAAE,OAAO,CAAC,CAAC,SAAS;EAC5B,WAAW,EACR,OAAO;GACN,KAAK,EAAE,KAAK,CAAC,SAAS,aAAa,CAAC;GACpC,QAAQ,EAAE,OAAO,CAAC,CAAC,SAAS;GAC5B,WAAW,EAAE,OAAO,CAAC,CAAC,SAAS;EACjC,CAAC,CAAC,CACD,SAAS;CACd,CAAC,CAAC,CACD,SAAS;AACd,CAAC"}
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * Tool exports for Mastra Code
3
3
  */
4
- export { createConfiguredWebTools, createParallelWebExtractTool, createParallelWebSearchTool, createWebExtractTool, createWebSearchTool, hasParallelKey, hasTavilyKey, resolveWebSearchProvider, } from './web-search.js';
4
+ export { createWebSearchTool, createWebExtractTool, hasTavilyKey } from './web-search.js';
5
5
  export { requestSandboxAccessTool } from './request-sandbox-access.js';
6
6
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/tools/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EACL,wBAAwB,EACxB,4BAA4B,EAC5B,2BAA2B,EAC3B,oBAAoB,EACpB,mBAAmB,EACnB,cAAc,EACd,YAAY,EACZ,wBAAwB,GACzB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,wBAAwB,EAAE,MAAM,6BAA6B,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/tools/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,mBAAmB,EAAE,oBAAoB,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAC1F,OAAO,EAAE,wBAAwB,EAAE,MAAM,6BAA6B,CAAC"}
@@ -1,3 +1,3 @@
1
- import { createConfiguredWebTools, createParallelWebExtractTool, createParallelWebSearchTool, createWebExtractTool, createWebSearchTool, hasParallelKey, hasTavilyKey, resolveWebSearchProvider } from "./web-search.js";
1
+ import { createWebExtractTool, createWebSearchTool, hasTavilyKey } from "./web-search.js";
2
2
  import { requestSandboxAccessTool } from "./request-sandbox-access.js";
3
- export { createConfiguredWebTools, createParallelWebExtractTool, createParallelWebSearchTool, createWebExtractTool, createWebSearchTool, hasParallelKey, hasTavilyKey, requestSandboxAccessTool, resolveWebSearchProvider };
3
+ export { createWebExtractTool, createWebSearchTool, hasTavilyKey, requestSandboxAccessTool };
@@ -1,12 +1,9 @@
1
- import { type WebSearchProviderSetting } from '../onboarding/settings.js';
2
1
  /**
3
2
  * Check whether a Tavily API key is available in the environment.
4
- * Used to select model-independent web tools before falling back to
5
- * model-native web search.
3
+ * Used by main.ts to decide whether to include Tavily tools or fall back
4
+ * to Anthropic's native web search.
6
5
  */
7
6
  export declare function hasTavilyKey(): boolean;
8
- /** Check whether a Parallel API key is available in the environment. */
9
- export declare function hasParallelKey(): boolean;
10
7
  /**
11
8
  * Wraps the @mastra/tavily search tool with mastracode-specific behavior:
12
9
  * relevance filtering, markdown string formatting, and token truncation.
@@ -35,80 +32,4 @@ export declare function createWebExtractTool(): import("@mastra/core/tools").Too
35
32
  includeImages?: boolean | undefined;
36
33
  format?: "markdown" | "text" | undefined;
37
34
  }, unknown, unknown, unknown, import("@mastra/core/tools").ToolExecutionContext<unknown, unknown, unknown>, "web-extract", unknown>;
38
- /**
39
- * Wraps the @mastra/parallel search tool with Mastra Code's standard tool id,
40
- * markdown string output, and token truncation.
41
- */
42
- export declare function createParallelWebSearchTool(): import("@mastra/core/tools").Tool<{
43
- query: string;
44
- }, unknown, unknown, unknown, import("@mastra/core/tools").ToolExecutionContext<unknown, unknown, unknown>, "web-search", unknown>;
45
- /**
46
- * Wraps the @mastra/parallel extract tool with Mastra Code's standard tool id,
47
- * markdown string output, and token truncation.
48
- */
49
- export declare function createParallelWebExtractTool(): import("@mastra/core/tools").Tool<{
50
- urls: string[];
51
- objective?: string | undefined;
52
- searchQueries?: string[] | undefined;
53
- excerptMaxCharsPerResult?: number | undefined;
54
- clientModel?: string | undefined;
55
- fullContent?: number | boolean | undefined;
56
- maxCharsTotal?: number | undefined;
57
- fetchPolicy?: {
58
- maxAgeSeconds?: number | undefined;
59
- timeoutSeconds?: number | undefined;
60
- disableCacheFallback?: boolean | undefined;
61
- } | undefined;
62
- sessionId?: string | undefined;
63
- }, unknown, unknown, unknown, import("@mastra/core/tools").ToolExecutionContext<unknown, unknown, unknown>, "web-extract", unknown>;
64
- /**
65
- * Resolve which model-independent web provider to use. An explicit user
66
- * preference wins while its API key is configured; otherwise `auto` picks the
67
- * first configured provider key (Tavily, then Parallel).
68
- */
69
- export declare function resolveWebSearchProvider(preference?: WebSearchProviderSetting): 'tavily' | 'parallel' | undefined;
70
- /**
71
- * Create the configured model-independent web tools for the provider selected
72
- * via the `webSearchProvider` preference (set in the TUI settings panel).
73
- */
74
- export declare function createConfiguredWebTools(): {
75
- web_search: import("@mastra/core/tools").Tool<{
76
- query: string;
77
- }, unknown, unknown, unknown, import("@mastra/core/tools").ToolExecutionContext<unknown, unknown, unknown>, "web-search", unknown>;
78
- web_extract: import("@mastra/core/tools").Tool<{
79
- urls: string[];
80
- objective?: string | undefined;
81
- searchQueries?: string[] | undefined;
82
- excerptMaxCharsPerResult?: number | undefined;
83
- clientModel?: string | undefined;
84
- fullContent?: number | boolean | undefined;
85
- maxCharsTotal?: number | undefined;
86
- fetchPolicy?: {
87
- maxAgeSeconds?: number | undefined;
88
- timeoutSeconds?: number | undefined;
89
- disableCacheFallback?: boolean | undefined;
90
- } | undefined;
91
- sessionId?: string | undefined;
92
- }, unknown, unknown, unknown, import("@mastra/core/tools").ToolExecutionContext<unknown, unknown, unknown>, "web-extract", unknown>;
93
- } | {
94
- web_search: import("@mastra/core/tools").Tool<{
95
- query: string;
96
- searchDepth?: "basic" | "advanced" | "fast" | "ultra-fast" | undefined;
97
- maxResults?: number | undefined;
98
- includeAnswer?: boolean | "basic" | "advanced" | undefined;
99
- includeImages?: boolean | undefined;
100
- includeImageDescriptions?: boolean | undefined;
101
- includeRawContent?: false | "markdown" | "text" | undefined;
102
- includeDomains?: string[] | undefined;
103
- excludeDomains?: string[] | undefined;
104
- timeRange?: "day" | "week" | "month" | "year" | undefined;
105
- }, unknown, unknown, unknown, import("@mastra/core/tools").ToolExecutionContext<unknown, unknown, unknown>, "web-search", unknown>;
106
- web_extract: import("@mastra/core/tools").Tool<{
107
- urls: string[];
108
- extractDepth?: "basic" | "advanced" | undefined;
109
- query?: string | undefined;
110
- includeImages?: boolean | undefined;
111
- format?: "markdown" | "text" | undefined;
112
- }, unknown, unknown, unknown, import("@mastra/core/tools").ToolExecutionContext<unknown, unknown, unknown>, "web-extract", unknown>;
113
- } | undefined;
114
35
  //# sourceMappingURL=web-search.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"web-search.d.ts","sourceRoot":"","sources":["../../src/tools/web-search.ts"],"names":[],"mappings":"AAKA,OAAO,EAAgB,KAAK,wBAAwB,EAAE,MAAM,2BAA2B,CAAC;AAwBxF;;;;GAIG;AACH,wBAAgB,YAAY,IAAI,OAAO,CAEtC;AAED,wEAAwE;AACxE,wBAAgB,cAAc,IAAI,OAAO,CAExC;AAED;;;;GAIG;AACH,wBAAgB,mBAAmB;;;;;;;;;;;mIA8BlC;AAED;;;GAGG;AACH,wBAAgB,oBAAoB;;;;;;oIAwBnC;AAED;;;GAGG;AACH,wBAAgB,2BAA2B;;mIAuB1C;AAED;;;GAGG;AACH,wBAAgB,4BAA4B;;;;;;;;;qBAtI1C,CAAC;sBAEK,CAAC;4BAEe,CAAC;;;oIA0JxB;AAED;;;;GAIG;AACH,wBAAgB,wBAAwB,CACtC,UAAU,GAAE,wBAAiC,GAC5C,QAAQ,GAAG,UAAU,GAAG,SAAS,CAQnC;AAED;;;GAGG;AACH,wBAAgB,wBAAwB;;;;;;;;;;;;;yBArLtC,CAAC;0BAEK,CAAC;gCAEe,CAAC;;;;;;;;;;;;;;;;;;;;;;;;cAmMxB"}
1
+ {"version":3,"file":"web-search.d.ts","sourceRoot":"","sources":["../../src/tools/web-search.ts"],"names":[],"mappings":"AAUA;;;;GAIG;AACH,wBAAgB,YAAY,IAAI,OAAO,CAEtC;AAED;;;;GAIG;AACH,wBAAgB,mBAAmB;;;;;;;;;;;mIA8BlC;AAED;;;GAGG;AACH,wBAAgB,oBAAoB;;;;;;oIAwBnC"}
@@ -1,31 +1,18 @@
1
- import { loadSettings } from "../onboarding/settings.js";
2
1
  import { truncateStringForTokenEstimate } from "../utils/token-estimator.js";
3
- import { createTool, isValidationError } from "@mastra/core/tools";
4
- import { createParallelExtractTool, createParallelSearchTool } from "@mastra/parallel";
2
+ import { createTool } from "@mastra/core/tools";
5
3
  import { createTavilyExtractTool, createTavilySearchTool } from "@mastra/tavily";
6
- import { z } from "zod";
7
4
  //#region src/tools/web-search.ts
8
5
  const MAX_WEB_SEARCH_TOKENS = 2e3;
9
6
  const MAX_WEB_EXTRACT_TOKENS = 2e3;
10
7
  const MIN_RELEVANCE_SCORE = .25;
11
- const parallelWebSearchInputSchema = z.object({ query: z.string().min(1).describe("The search query") });
12
- function requireParallelOutput(output, operation) {
13
- if (output === void 0) throw new Error(`Parallel ${operation} returned no output`);
14
- if (isValidationError(output)) throw new Error(output.message);
15
- return output;
16
- }
17
8
  /**
18
9
  * Check whether a Tavily API key is available in the environment.
19
- * Used to select model-independent web tools before falling back to
20
- * model-native web search.
10
+ * Used by main.ts to decide whether to include Tavily tools or fall back
11
+ * to Anthropic's native web search.
21
12
  */
22
13
  function hasTavilyKey() {
23
14
  return !!process.env.TAVILY_API_KEY;
24
15
  }
25
- /** Check whether a Parallel API key is available in the environment. */
26
- function hasParallelKey() {
27
- return !!process.env.PARALLEL_API_KEY;
28
- }
29
16
  /**
30
17
  * Wraps the @mastra/tavily search tool with mastracode-specific behavior:
31
18
  * relevance filtering, markdown string formatting, and token truncation.
@@ -68,88 +55,7 @@ function createWebExtractTool() {
68
55
  }
69
56
  });
70
57
  }
71
- /**
72
- * Wraps the @mastra/parallel search tool with Mastra Code's standard tool id,
73
- * markdown string output, and token truncation.
74
- */
75
- function createParallelWebSearchTool() {
76
- const parallelSearchTool = createParallelSearchTool();
77
- return createTool({
78
- id: "web-search",
79
- description: parallelSearchTool.description,
80
- inputSchema: parallelWebSearchInputSchema,
81
- execute: async (input, context) => {
82
- const output = requireParallelOutput(await parallelSearchTool.execute({ searchQueries: [input.query] }, context), "search");
83
- const parts = [];
84
- for (const result of output.results) {
85
- const title = result.title || result.url;
86
- const excerpts = (result.excerpts || []).filter(Boolean).join("\n");
87
- parts.push([
88
- `## ${title}`,
89
- result.url,
90
- excerpts
91
- ].filter(Boolean).join("\n"));
92
- }
93
- return truncateStringForTokenEstimate(parts.join("\n\n"), MAX_WEB_SEARCH_TOKENS);
94
- }
95
- });
96
- }
97
- /**
98
- * Wraps the @mastra/parallel extract tool with Mastra Code's standard tool id,
99
- * markdown string output, and token truncation.
100
- */
101
- function createParallelWebExtractTool() {
102
- const parallelExtractTool = createParallelExtractTool();
103
- return createTool({
104
- id: "web-extract",
105
- description: parallelExtractTool.description,
106
- inputSchema: parallelExtractTool.inputSchema,
107
- execute: async (input, context) => {
108
- const output = requireParallelOutput(await parallelExtractTool.execute(input, context), "extract");
109
- const parts = [];
110
- for (const result of output.results) {
111
- const content = result.fullContent || (result.excerpts || []).filter(Boolean).join("\n");
112
- parts.push([`## ${result.url}`, content].filter(Boolean).join("\n"));
113
- }
114
- for (const error of output.errors) {
115
- const status = error.httpStatusCode ? ` (${error.httpStatusCode})` : "";
116
- parts.push([
117
- `## ${error.url}`,
118
- `Error: ${error.errorType}${status}`,
119
- error.content
120
- ].filter(Boolean).join("\n"));
121
- }
122
- return truncateStringForTokenEstimate(parts.join("\n\n"), MAX_WEB_EXTRACT_TOKENS);
123
- }
124
- });
125
- }
126
- /**
127
- * Resolve which model-independent web provider to use. An explicit user
128
- * preference wins while its API key is configured; otherwise `auto` picks the
129
- * first configured provider key (Tavily, then Parallel).
130
- */
131
- function resolveWebSearchProvider(preference = "auto") {
132
- if (preference === "tavily" && hasTavilyKey()) return "tavily";
133
- if (preference === "parallel" && hasParallelKey()) return "parallel";
134
- if (hasTavilyKey()) return "tavily";
135
- if (hasParallelKey()) return "parallel";
136
- }
137
- /**
138
- * Create the configured model-independent web tools for the provider selected
139
- * via the `webSearchProvider` preference (set in the TUI settings panel).
140
- */
141
- function createConfiguredWebTools() {
142
- const provider = resolveWebSearchProvider(loadSettings().preferences.webSearchProvider);
143
- if (provider === "parallel") return {
144
- web_search: createParallelWebSearchTool(),
145
- web_extract: createParallelWebExtractTool()
146
- };
147
- if (provider === "tavily") return {
148
- web_search: createWebSearchTool(),
149
- web_extract: createWebExtractTool()
150
- };
151
- }
152
58
  //#endregion
153
- export { createConfiguredWebTools, createParallelWebExtractTool, createParallelWebSearchTool, createWebExtractTool, createWebSearchTool, hasParallelKey, hasTavilyKey, resolveWebSearchProvider };
59
+ export { createWebExtractTool, createWebSearchTool, hasTavilyKey };
154
60
 
155
61
  //# sourceMappingURL=web-search.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"web-search.js","names":[],"sources":["../../src/tools/web-search.ts"],"sourcesContent":["import { createTool, isValidationError, type ValidationError } from '@mastra/core/tools';\nimport { createParallelSearchTool, createParallelExtractTool } from '@mastra/parallel';\nimport { createTavilySearchTool, createTavilyExtractTool } from '@mastra/tavily';\nimport { z } from 'zod';\n\nimport { loadSettings, type WebSearchProviderSetting } from '../onboarding/settings.js';\nimport { truncateStringForTokenEstimate } from '../utils/token-estimator.js';\n\nconst MAX_WEB_SEARCH_TOKENS = 2_000;\nconst MAX_WEB_EXTRACT_TOKENS = 2_000;\n\nconst MIN_RELEVANCE_SCORE = 0.25;\n\nconst parallelWebSearchInputSchema = z.object({\n query: z.string().min(1).describe('The search query'),\n});\n\nfunction requireParallelOutput<T>(output: T | ValidationError | void, operation: 'search' | 'extract'): T {\n if (output === undefined) {\n throw new Error(`Parallel ${operation} returned no output`);\n }\n\n if (isValidationError(output)) {\n throw new Error(output.message);\n }\n\n return output;\n}\n\n/**\n * Check whether a Tavily API key is available in the environment.\n * Used to select model-independent web tools before falling back to\n * model-native web search.\n */\nexport function hasTavilyKey(): boolean {\n return !!process.env.TAVILY_API_KEY;\n}\n\n/** Check whether a Parallel API key is available in the environment. */\nexport function hasParallelKey(): boolean {\n return !!process.env.PARALLEL_API_KEY;\n}\n\n/**\n * Wraps the @mastra/tavily search tool with mastracode-specific behavior:\n * relevance filtering, markdown string formatting, and token truncation.\n * The underlying Tavily tool handles client init, input validation, and the API call.\n */\nexport function createWebSearchTool() {\n const tavilySearchTool = createTavilySearchTool();\n\n return createTool({\n id: 'web-search',\n description: tavilySearchTool.description!,\n inputSchema: tavilySearchTool.inputSchema!,\n execute: async (input, context) => {\n const output: any = await tavilySearchTool.execute!(input as any, context as any);\n\n const parts: string[] = [];\n\n if (output.answer) {\n parts.push(`Answer: ${output.answer}`);\n }\n\n const filtered = output.results.filter((r: any) => (r.score ?? 1) >= MIN_RELEVANCE_SCORE);\n for (const r of filtered) {\n parts.push(`## ${r.title}\\n${r.url}\\n${r.content}`);\n }\n\n const images = (output.images || []).map((img: any) => img.url).filter(Boolean);\n if (images.length > 0) {\n parts.push(`Images:\\n${images.join('\\n')}`);\n }\n\n const text = parts.join('\\n\\n');\n return truncateStringForTokenEstimate(text, MAX_WEB_SEARCH_TOKENS);\n },\n });\n}\n\n/**\n * Wraps the @mastra/tavily extract tool with mastracode-specific behavior:\n * markdown string formatting and token truncation.\n */\nexport function createWebExtractTool() {\n const tavilyExtractTool = createTavilyExtractTool();\n\n return createTool({\n id: 'web-extract',\n description: tavilyExtractTool.description!,\n inputSchema: tavilyExtractTool.inputSchema!,\n execute: async (input, context) => {\n const output: any = await tavilyExtractTool.execute!(input as any, context as any);\n\n const parts: string[] = [];\n\n for (const r of output.results) {\n parts.push(`## ${r.url}\\n${r.rawContent}`);\n }\n\n for (const r of output.failedResults) {\n parts.push(`## ${r.url}\\nError: ${r.error}`);\n }\n\n const text = parts.join('\\n\\n');\n return truncateStringForTokenEstimate(text, MAX_WEB_EXTRACT_TOKENS);\n },\n });\n}\n\n/**\n * Wraps the @mastra/parallel search tool with Mastra Code's standard tool id,\n * markdown string output, and token truncation.\n */\nexport function createParallelWebSearchTool() {\n const parallelSearchTool = createParallelSearchTool();\n\n return createTool({\n id: 'web-search',\n description: parallelSearchTool.description!,\n inputSchema: parallelWebSearchInputSchema,\n execute: async (input, context) => {\n const output = requireParallelOutput(\n await parallelSearchTool.execute!({ searchQueries: [input.query] }, context),\n 'search',\n );\n const parts: string[] = [];\n\n for (const result of output.results) {\n const title = result.title || result.url;\n const excerpts = (result.excerpts || []).filter(Boolean).join('\\n');\n parts.push([`## ${title}`, result.url, excerpts].filter(Boolean).join('\\n'));\n }\n\n return truncateStringForTokenEstimate(parts.join('\\n\\n'), MAX_WEB_SEARCH_TOKENS);\n },\n });\n}\n\n/**\n * Wraps the @mastra/parallel extract tool with Mastra Code's standard tool id,\n * markdown string output, and token truncation.\n */\nexport function createParallelWebExtractTool() {\n const parallelExtractTool = createParallelExtractTool();\n\n return createTool({\n id: 'web-extract',\n description: parallelExtractTool.description!,\n inputSchema: parallelExtractTool.inputSchema!,\n execute: async (input, context) => {\n const output = requireParallelOutput(await parallelExtractTool.execute!(input, context), 'extract');\n const parts: string[] = [];\n\n for (const result of output.results) {\n const content = result.fullContent || (result.excerpts || []).filter(Boolean).join('\\n');\n parts.push([`## ${result.url}`, content].filter(Boolean).join('\\n'));\n }\n\n for (const error of output.errors) {\n const status = error.httpStatusCode ? ` (${error.httpStatusCode})` : '';\n parts.push([`## ${error.url}`, `Error: ${error.errorType}${status}`, error.content].filter(Boolean).join('\\n'));\n }\n\n return truncateStringForTokenEstimate(parts.join('\\n\\n'), MAX_WEB_EXTRACT_TOKENS);\n },\n });\n}\n\n/**\n * Resolve which model-independent web provider to use. An explicit user\n * preference wins while its API key is configured; otherwise `auto` picks the\n * first configured provider key (Tavily, then Parallel).\n */\nexport function resolveWebSearchProvider(\n preference: WebSearchProviderSetting = 'auto',\n): 'tavily' | 'parallel' | undefined {\n if (preference === 'tavily' && hasTavilyKey()) return 'tavily';\n if (preference === 'parallel' && hasParallelKey()) return 'parallel';\n\n // `auto`, or an explicit choice whose key is no longer configured.\n if (hasTavilyKey()) return 'tavily';\n if (hasParallelKey()) return 'parallel';\n return undefined;\n}\n\n/**\n * Create the configured model-independent web tools for the provider selected\n * via the `webSearchProvider` preference (set in the TUI settings panel).\n */\nexport function createConfiguredWebTools() {\n const provider = resolveWebSearchProvider(loadSettings().preferences.webSearchProvider);\n\n if (provider === 'parallel') {\n return {\n web_search: createParallelWebSearchTool(),\n web_extract: createParallelWebExtractTool(),\n };\n }\n\n if (provider === 'tavily') {\n return {\n web_search: createWebSearchTool(),\n web_extract: createWebExtractTool(),\n };\n }\n\n return undefined;\n}\n"],"mappings":";;;;;;;AAQA,MAAM,wBAAwB;AAC9B,MAAM,yBAAyB;AAE/B,MAAM,sBAAsB;AAE5B,MAAM,+BAA+B,EAAE,OAAO,EAC5C,OAAO,EAAE,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS,kBAAkB,EACtD,CAAC;AAED,SAAS,sBAAyB,QAAoC,WAAoC;CACxG,IAAI,WAAW,KAAA,GACb,MAAM,IAAI,MAAM,YAAY,UAAU,oBAAoB;CAG5D,IAAI,kBAAkB,MAAM,GAC1B,MAAM,IAAI,MAAM,OAAO,OAAO;CAGhC,OAAO;AACT;;;;;;AAOA,SAAgB,eAAwB;CACtC,OAAO,CAAC,CAAC,QAAQ,IAAI;AACvB;;AAGA,S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IACrE,MAAM,KAAK;KAAC,MAAM,MAAM;KAAO,UAAU,MAAM,YAAY;KAAU,MAAM;IAAO,CAAC,CAAC,OAAO,OAAO,CAAC,CAAC,KAAK,IAAI,CAAC;GAChH;GAEA,OAAO,+BAA+B,MAAM,KAAK,MAAM,GAAG,sBAAsB;EAClF;CACF,CAAC;AACH;;;;;;AAOA,SAAgB,yBACd,aAAuC,QACJ;CACnC,IAAI,eAAe,YAAY,aAAa,GAAG,OAAO;CACtD,IAAI,eAAe,cAAc,eAAe,GAAG,OAAO;CAG1D,IAAI,aAAa,GAAG,OAAO;CAC3B,IAAI,eAAe,GAAG,OAAO;AAE/B;;;;;AAMA,SAAgB,2BAA2B;CACzC,MAAM,WAAW,yBAAyB,aAAa,CAAC,CAAC,YAAY,iBAAiB;CAEtF,IAAI,aAAa,YACf,OAAO;EACL,YAAY,4BAA4B;EACxC,aAAa,6BAA6B;CAC5C;CAGF,IAAI,aAAa,UACf,OAAO;EACL,YAAY,oBAAoB;EAChC,aAAa,qBAAqB;CACpC;AAIJ"}
1
+ {"version":3,"file":"web-search.js","names":[],"sources":["../../src/tools/web-search.ts"],"sourcesContent":["import { createTool } from '@mastra/core/tools';\nimport { createTavilySearchTool, createTavilyExtractTool } from '@mastra/tavily';\n\nimport { truncateStringForTokenEstimate } from '../utils/token-estimator.js';\n\nconst MAX_WEB_SEARCH_TOKENS = 2_000;\nconst MAX_WEB_EXTRACT_TOKENS = 2_000;\n\nconst MIN_RELEVANCE_SCORE = 0.25;\n\n/**\n * Check whether a Tavily API key is available in the environment.\n * Used by main.ts to decide whether to include Tavily tools or fall back\n * to Anthropic's native web search.\n */\nexport function hasTavilyKey(): boolean {\n return !!process.env.TAVILY_API_KEY;\n}\n\n/**\n * Wraps the @mastra/tavily search tool with mastracode-specific behavior:\n * relevance filtering, markdown string formatting, and token truncation.\n * The underlying Tavily tool handles client init, input validation, and the API call.\n */\nexport function createWebSearchTool() {\n const tavilySearchTool = createTavilySearchTool();\n\n return createTool({\n id: 'web-search',\n description: tavilySearchTool.description!,\n inputSchema: tavilySearchTool.inputSchema!,\n execute: async (input, context) => {\n const output: any = await tavilySearchTool.execute!(input as any, context as any);\n\n const parts: string[] = [];\n\n if (output.answer) {\n parts.push(`Answer: ${output.answer}`);\n }\n\n const filtered = output.results.filter((r: any) => (r.score ?? 1) >= MIN_RELEVANCE_SCORE);\n for (const r of filtered) {\n parts.push(`## ${r.title}\\n${r.url}\\n${r.content}`);\n }\n\n const images = (output.images || []).map((img: any) => img.url).filter(Boolean);\n if (images.length > 0) {\n parts.push(`Images:\\n${images.join('\\n')}`);\n }\n\n const text = parts.join('\\n\\n');\n return truncateStringForTokenEstimate(text, MAX_WEB_SEARCH_TOKENS);\n },\n });\n}\n\n/**\n * Wraps the @mastra/tavily extract tool with mastracode-specific behavior:\n * markdown string formatting and token truncation.\n */\nexport function createWebExtractTool() {\n const tavilyExtractTool = createTavilyExtractTool();\n\n return createTool({\n id: 'web-extract',\n description: tavilyExtractTool.description!,\n inputSchema: tavilyExtractTool.inputSchema!,\n execute: async (input, context) => {\n const output: any = await tavilyExtractTool.execute!(input as any, context as any);\n\n const parts: string[] = [];\n\n for (const r of output.results) {\n parts.push(`## ${r.url}\\n${r.rawContent}`);\n }\n\n for (const r of output.failedResults) {\n parts.push(`## ${r.url}\\nError: ${r.error}`);\n }\n\n const text = parts.join('\\n\\n');\n return truncateStringForTokenEstimate(text, MAX_WEB_EXTRACT_TOKENS);\n },\n });\n}\n"],"mappings":";;;;AAKA,MAAM,wBAAwB;AAC9B,MAAM,yBAAyB;AAE/B,MAAM,sBAAsB;;;;;;AAO5B,SAAgB,eAAwB;CACtC,OAAO,CAAC,CAAC,QAAQ,IAAI;AACvB;;;;;;AAOA,SAAgB,sBAAsB;CACpC,MAAM,mBAAmB,uBAAuB;CAEhD,OAAO,WAAW;EAChB,IAAI;EACJ,aAAa,iBAAiB;EAC9B,aAAa,iBAAiB;EAC9B,SAAS,OAAO,OAAO,YAAY;GACjC,MAAM,SAAc,MAAM,iBAAiB,QAAS,OAAc,OAAc;GAEhF,MAAM,QAAkB,CAAC;GAEzB,IAAI,OAAO,QACT,MAAM,KAAK,WAAW,OAAO,QAAQ;GAGvC,MAAM,WAAW,OAAO,QAAQ,QAAQ,OAAY,EAAE,SAAS,MAAM,mBAAmB;GACxF,KAAK,MAAM,KAAK,UACd,MAAM,KAAK,MAAM,EAAE,MAAM,IAAI,EAAE,IAAI,IAAI,EAAE,SAAS;GAGpD,MAAM,UAAU,OAAO,UAAU,CAAC,EAAA,CAAG,KAAK,QAAa,IAAI,GAAG,CAAC,CAAC,OAAO,OAAO;GAC9E,IAAI,OAAO,SAAS,GAClB,MAAM,KAAK,YAAY,OAAO,KAAK,IAAI,GAAG;GAI5C,OAAO,+BADM,MAAM,KAAK,MACiB,GAAG,qBAAqB;EACnE;CACF,CAAC;AACH;;;;;AAMA,SAAgB,uBAAuB;CACrC,MAAM,oBAAoB,wBAAwB;CAElD,OAAO,WAAW;EAChB,IAAI;EACJ,aAAa,kBAAkB;EAC/B,aAAa,kBAAkB;EAC/B,SAAS,OAAO,OAAO,YAAY;GACjC,MAAM,SAAc,MAAM,kBAAkB,QAAS,OAAc,OAAc;GAEjF,MAAM,QAAkB,CAAC;GAEzB,KAAK,MAAM,KAAK,OAAO,SACrB,MAAM,KAAK,MAAM,EAAE,IAAI,IAAI,EAAE,YAAY;GAG3C,KAAK,MAAM,KAAK,OAAO,eACrB,MAAM,KAAK,MAAM,EAAE,IAAI,WAAW,EAAE,OAAO;GAI7C,OAAO,+BADM,MAAM,KAAK,MACiB,GAAG,sBAAsB;EACpE;CACF,CAAC;AACH"}
@@ -7,7 +7,7 @@
7
7
  * - workflow-builder sub-agent (so `create-workflow` can delegate)
8
8
  * - code-agent (as a plain agent, callable via agent steps)
9
9
  * - workspace tools (view/write/edit/find_files/execute_command/etc.)
10
- * - configured model-independent web tools so workflows can compose search/extract steps
10
+ * - web tools (Tavily-gated) so workflows can compose search/extract steps
11
11
  * - notification_inbox
12
12
  * - snapshot of MCP tools from mcpManager
13
13
  *
@@ -18,10 +18,10 @@
18
18
  * Tradeoffs:
19
19
  * - MCP tools are snapshotted. Servers added after boot are invisible to
20
20
  * the workflow-builder until restart.
21
- * - Provider-native (Anthropic/OpenAI) web
21
+ * - Web tool flavor is Tavily-only. Provider-native (Anthropic/OpenAI) web
22
22
  * tools are skipped because they'd freeze workflows to one model provider.
23
- * - Workflow tool steps get the closed-over workspace + auth (web provider
24
- * key, MCP server credentials), not per-request permissions — deliberate; if
23
+ * - Workflow tool steps get the closed-over workspace + auth (Tavily key,
24
+ * MCP server credentials), not per-request permissions — deliberate; if
25
25
  * the user built + saved the workflow they meant to run it.
26
26
  */
27
27
  import type { Agent } from '@mastra/core/agent';
@@ -1 +1 @@
1
- {"version":3,"file":"register-primitives.d.ts","sourceRoot":"","sources":["../../src/workflows/register-primitives.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAChD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAMlD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AAIzC,MAAM,WAAW,wCAAwC;IACvD,WAAW,EAAE,MAAM,CAAC;IACpB;;;;;OAKG;IACH,YAAY,CAAC,EAAE,MAAM,EAAE,CAAC;IACxB;;;;OAIG;IACH,SAAS,EAAE,KAAK,CAAC;IACjB;;;OAGG;IACH,UAAU,CAAC,EAAE,UAAU,CAAC;CACzB;AAED,wBAAsB,iCAAiC,CACrD,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,wCAAwC,GAChD,OAAO,CAAC,IAAI,CAAC,CAkDf"}
1
+ {"version":3,"file":"register-primitives.d.ts","sourceRoot":"","sources":["../../src/workflows/register-primitives.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAChD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAMlD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AAIzC,MAAM,WAAW,wCAAwC;IACvD,WAAW,EAAE,MAAM,CAAC;IACpB;;;;;OAKG;IACH,YAAY,CAAC,EAAE,MAAM,EAAE,CAAC;IACxB;;;;OAIG;IACH,SAAS,EAAE,KAAK,CAAC;IACjB;;;OAGG;IACH,UAAU,CAAC,EAAE,UAAU,CAAC;CACzB;AAED,wBAAsB,iCAAiC,CACrD,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,wCAAwC,GAChD,OAAO,CAAC,IAAI,CAAC,CAiDf"}
@@ -1,5 +1,5 @@
1
1
  import { MC_TOOLS } from "../tool-names.js";
2
- import { createConfiguredWebTools } from "../tools/web-search.js";
2
+ import { createWebExtractTool, createWebSearchTool, hasTavilyKey } from "../tools/web-search.js";
3
3
  import { MASTRACODE_WORKSPACE_TOOLS } from "../agents/tool-availability.js";
4
4
  import { LazyNotificationsStorage } from "../agents/tools.js";
5
5
  import { workflowBuilderAgent } from "../agents/workflow-builder-agent.js";
@@ -22,10 +22,9 @@ async function registerWorkflowBuilderPrimitives(mastra, options) {
22
22
  });
23
23
  const workspaceTools = await createWorkspaceTools(workspace, { workspace });
24
24
  for (const [toolId, tool] of Object.entries(workspaceTools)) mastra.addTool(tool, toolId);
25
- const configuredWebTools = createConfiguredWebTools();
26
- if (configuredWebTools) {
27
- mastra.addTool(configuredWebTools.web_search, "web-search");
28
- mastra.addTool(configuredWebTools.web_extract, "web-extract");
25
+ if (hasTavilyKey()) {
26
+ mastra.addTool(createWebSearchTool(), "web-search");
27
+ mastra.addTool(createWebExtractTool(), "web-extract");
29
28
  }
30
29
  const storage = mastra.getStorage();
31
30
  if (storage) {
@@ -1 +1 @@
1
- {"version":3,"file":"register-primitives.js","names":[],"sources":["../../src/workflows/register-primitives.ts"],"sourcesContent":["/**\n * Statically register workflow-related primitives on the mastracode Mastra\n * instance so `mastra.listTools()` + `mastra.listAgents()` — and, therefore,\n * the workflow-builder's discovery + the workflow rehydrator — see everything\n * a workflow might want to compose:\n *\n * - workflow-builder sub-agent (so `create-workflow` can delegate)\n * - code-agent (as a plain agent, callable via agent steps)\n * - workspace tools (view/write/edit/find_files/execute_command/etc.)\n * - configured model-independent web tools so workflows can compose search/extract steps\n * - notification_inbox\n * - snapshot of MCP tools from mcpManager\n *\n * Called after `controller.init()` but before `startWorkers()` in both boot\n * paths, so `loadStoredWorkflows()` (inside startWorkers) sees the full\n * registry when rehydrating previously-saved workflows.\n *\n * Tradeoffs:\n * - MCP tools are snapshotted. Servers added after boot are invisible to\n * the workflow-builder until restart.\n * - Provider-native (Anthropic/OpenAI) web\n * tools are skipped because they'd freeze workflows to one model provider.\n * - Workflow tool steps get the closed-over workspace + auth (web provider\n * key, MCP server credentials), not per-request permissions — deliberate; if\n * the user built + saved the workflow they meant to run it.\n */\nimport type { Agent } from '@mastra/core/agent';\nimport type { Mastra } from '@mastra/core/mastra';\nimport { createNotificationInboxTool } from '@mastra/core/notifications';\nimport { LocalFilesystem, LocalSandbox, Workspace, createWorkspaceTools } from '@mastra/core/workspace';\nimport { MASTRACODE_WORKSPACE_TOOLS } from '../agents/tool-availability.js';\nimport { LazyNotificationsStorage } from '../agents/tools.js';\nimport { workflowBuilderAgent } from '../agents/workflow-builder-agent.js';\nimport type { McpManager } from '../mcp';\nimport { MC_TOOLS } from '../tool-names.js';\nimport { createConfiguredWebTools } from '../tools/web-search.js';\n\nexport interface RegisterWorkflowBuilderPrimitivesOptions {\n projectPath: string;\n /**\n * Extra allowed paths the workspace can read/write. Mastracode normally\n * collects skill paths + sandboxAllowedPaths per-request; for the workflow\n * workspace we accept anything the caller wants up-front and trust the\n * worker process to honour the user's intent.\n */\n allowedPaths?: string[];\n /**\n * The code-agent Agent instance. Registered as `code-agent` so workflows\n * can compose it in agent steps. It already has full dynamic tool access\n * (workspace/MCP/web/etc.) via its own `tools: createDynamicTools(...)`.\n */\n codeAgent: Agent;\n /**\n * McpManager for snapshotting MCP tools at boot. Omit or pass undefined\n * if MCP is disabled — workflow-builder will just see fewer tools.\n */\n mcpManager?: McpManager;\n}\n\nexport async function registerWorkflowBuilderPrimitives(\n mastra: Mastra,\n options: RegisterWorkflowBuilderPrimitivesOptions,\n): Promise<void> {\n const { projectPath, allowedPaths = [], codeAgent, mcpManager } = options;\n\n // 1. Agents workflows can compose.\n mastra.addAgent(workflowBuilderAgent, 'workflow-builder');\n mastra.addAgent(codeAgent, 'code-agent');\n\n // 2. Workspace tools — bound to a project-rooted local workspace.\n const workspace = new Workspace({\n id: 'workflow-builder-workspace',\n name: 'Mastra Code Workspace (workflows)',\n filesystem: new LocalFilesystem({\n basePath: projectPath,\n allowedPaths: [projectPath, ...allowedPaths],\n }),\n sandbox: new LocalSandbox({ workingDirectory: projectPath }),\n tools: MASTRACODE_WORKSPACE_TOOLS,\n });\n const workspaceTools = await createWorkspaceTools(workspace, { workspace });\n for (const [toolId, tool] of Object.entries(workspaceTools)) {\n mastra.addTool(tool, toolId);\n }\n\n // 3. Model-independent web tools. Provider-native web tools (Anthropic/OpenAI)\n // are model-locked and would freeze workflows to one provider.\n const configuredWebTools = createConfiguredWebTools();\n if (configuredWebTools) {\n mastra.addTool(configuredWebTools.web_search, 'web-search');\n mastra.addTool(configuredWebTools.web_extract, 'web-extract');\n }\n\n // 4. notification_inbox — LazyNotificationsStorage resolves the notifications\n // domain per-call rather than at boot, so it works even when the domain\n // isn't fully initialised yet.\n const storage = mastra.getStorage();\n if (storage) {\n const notificationInbox = createNotificationInboxTool({\n storage: new LazyNotificationsStorage(storage as never),\n });\n mastra.addTool(notificationInbox, MC_TOOLS.NOTIFICATION_INBOX);\n }\n\n // 5. MCP tools — snapshot the current set. Ids are already server-namespaced\n // (`${serverName}_${toolName}`), so the workflow rehydrator's\n // `mastra.getTool(id)` resolves them at run time.\n if (mcpManager) {\n for (const [toolId, tool] of Object.entries(mcpManager.getTools())) {\n mastra.addTool(tool, toolId);\n }\n }\n}\n"],"mappings":";;;;;;;;AA2DA,eAAsB,kCACpB,QACA,SACe;CACf,MAAM,EAAE,aAAa,eAAe,CAAC,GAAG,WAAW,eAAe;CAGlE,OAAO,SAAS,sBAAsB,kBAAkB;CACxD,OAAO,SAAS,WAAW,YAAY;CAGvC,MAAM,YAAY,IAAI,UAAU;EAC9B,IAAI;EACJ,MAAM;EACN,YAAY,IAAI,gBAAgB;GAC9B,UAAU;GACV,cAAc,CAAC,aAAa,GAAG,YAAY;EAC7C,CAAC;EACD,SAAS,IAAI,aAAa,EAAE,kBAAkB,YAAY,CAAC;EAC3D,OAAO;CACT,CAAC;CACD,MAAM,iBAAiB,MAAM,qBAAqB,WAAW,EAAE,UAAU,CAAC;CAC1E,KAAK,MAAM,CAAC,QAAQ,SAAS,OAAO,QAAQ,cAAc,GACxD,OAAO,QAAQ,MAAM,MAAM;CAK7B,MAAM,qBAAqB,yBAAyB;CACpD,IAAI,oBAAoB;EACtB,OAAO,QAAQ,mBAAmB,YAAY,YAAY;EAC1D,OAAO,QAAQ,mBAAmB,aAAa,aAAa;CAC9D;CAKA,MAAM,UAAU,OAAO,WAAW;CAClC,IAAI,SAAS;EACX,MAAM,oBAAoB,4BAA4B,EACpD,SAAS,IAAI,yBAAyB,OAAgB,EACxD,CAAC;EACD,OAAO,QAAQ,mBAAmB,SAAS,kBAAkB;CAC/D;CAKA,IAAI,YACF,KAAK,MAAM,CAAC,QAAQ,SAAS,OAAO,QAAQ,WAAW,SAAS,CAAC,GAC/D,OAAO,QAAQ,MAAM,MAAM;AAGjC"}
1
+ {"version":3,"file":"register-primitives.js","names":[],"sources":["../../src/workflows/register-primitives.ts"],"sourcesContent":["/**\n * Statically register workflow-related primitives on the mastracode Mastra\n * instance so `mastra.listTools()` + `mastra.listAgents()` — and, therefore,\n * the workflow-builder's discovery + the workflow rehydrator — see everything\n * a workflow might want to compose:\n *\n * - workflow-builder sub-agent (so `create-workflow` can delegate)\n * - code-agent (as a plain agent, callable via agent steps)\n * - workspace tools (view/write/edit/find_files/execute_command/etc.)\n * - web tools (Tavily-gated) so workflows can compose search/extract steps\n * - notification_inbox\n * - snapshot of MCP tools from mcpManager\n *\n * Called after `controller.init()` but before `startWorkers()` in both boot\n * paths, so `loadStoredWorkflows()` (inside startWorkers) sees the full\n * registry when rehydrating previously-saved workflows.\n *\n * Tradeoffs:\n * - MCP tools are snapshotted. Servers added after boot are invisible to\n * the workflow-builder until restart.\n * - Web tool flavor is Tavily-only. Provider-native (Anthropic/OpenAI) web\n * tools are skipped because they'd freeze workflows to one model provider.\n * - Workflow tool steps get the closed-over workspace + auth (Tavily key,\n * MCP server credentials), not per-request permissions — deliberate; if\n * the user built + saved the workflow they meant to run it.\n */\nimport type { Agent } from '@mastra/core/agent';\nimport type { Mastra } from '@mastra/core/mastra';\nimport { createNotificationInboxTool } from '@mastra/core/notifications';\nimport { LocalFilesystem, LocalSandbox, Workspace, createWorkspaceTools } from '@mastra/core/workspace';\nimport { MASTRACODE_WORKSPACE_TOOLS } from '../agents/tool-availability.js';\nimport { LazyNotificationsStorage } from '../agents/tools.js';\nimport { workflowBuilderAgent } from '../agents/workflow-builder-agent.js';\nimport type { McpManager } from '../mcp';\nimport { MC_TOOLS } from '../tool-names.js';\nimport { createWebExtractTool, createWebSearchTool, hasTavilyKey } from '../tools/web-search.js';\n\nexport interface RegisterWorkflowBuilderPrimitivesOptions {\n projectPath: string;\n /**\n * Extra allowed paths the workspace can read/write. Mastracode normally\n * collects skill paths + sandboxAllowedPaths per-request; for the workflow\n * workspace we accept anything the caller wants up-front and trust the\n * worker process to honour the user's intent.\n */\n allowedPaths?: string[];\n /**\n * The code-agent Agent instance. Registered as `code-agent` so workflows\n * can compose it in agent steps. It already has full dynamic tool access\n * (workspace/MCP/web/etc.) via its own `tools: createDynamicTools(...)`.\n */\n codeAgent: Agent;\n /**\n * McpManager for snapshotting MCP tools at boot. Omit or pass undefined\n * if MCP is disabled — workflow-builder will just see fewer tools.\n */\n mcpManager?: McpManager;\n}\n\nexport async function registerWorkflowBuilderPrimitives(\n mastra: Mastra,\n options: RegisterWorkflowBuilderPrimitivesOptions,\n): Promise<void> {\n const { projectPath, allowedPaths = [], codeAgent, mcpManager } = options;\n\n // 1. Agents workflows can compose.\n mastra.addAgent(workflowBuilderAgent, 'workflow-builder');\n mastra.addAgent(codeAgent, 'code-agent');\n\n // 2. Workspace tools — bound to a project-rooted local workspace.\n const workspace = new Workspace({\n id: 'workflow-builder-workspace',\n name: 'Mastra Code Workspace (workflows)',\n filesystem: new LocalFilesystem({\n basePath: projectPath,\n allowedPaths: [projectPath, ...allowedPaths],\n }),\n sandbox: new LocalSandbox({ workingDirectory: projectPath }),\n tools: MASTRACODE_WORKSPACE_TOOLS,\n });\n const workspaceTools = await createWorkspaceTools(workspace, { workspace });\n for (const [toolId, tool] of Object.entries(workspaceTools)) {\n mastra.addTool(tool, toolId);\n }\n\n // 3. Web tools — Tavily only. Provider-native web tools (Anthropic/OpenAI)\n // are model-locked and would freeze workflows to one provider.\n if (hasTavilyKey()) {\n mastra.addTool(createWebSearchTool(), 'web-search');\n mastra.addTool(createWebExtractTool(), 'web-extract');\n }\n\n // 4. notification_inbox — LazyNotificationsStorage resolves the notifications\n // domain per-call rather than at boot, so it works even when the domain\n // isn't fully initialised yet.\n const storage = mastra.getStorage();\n if (storage) {\n const notificationInbox = createNotificationInboxTool({\n storage: new LazyNotificationsStorage(storage as never),\n });\n mastra.addTool(notificationInbox, MC_TOOLS.NOTIFICATION_INBOX);\n }\n\n // 5. MCP tools — snapshot the current set. Ids are already server-namespaced\n // (`${serverName}_${toolName}`), so the workflow rehydrator's\n // `mastra.getTool(id)` resolves them at run time.\n if (mcpManager) {\n for (const [toolId, tool] of Object.entries(mcpManager.getTools())) {\n mastra.addTool(tool, toolId);\n }\n }\n}\n"],"mappings":";;;;;;;;AA2DA,eAAsB,kCACpB,QACA,SACe;CACf,MAAM,EAAE,aAAa,eAAe,CAAC,GAAG,WAAW,eAAe;CAGlE,OAAO,SAAS,sBAAsB,kBAAkB;CACxD,OAAO,SAAS,WAAW,YAAY;CAGvC,MAAM,YAAY,IAAI,UAAU;EAC9B,IAAI;EACJ,MAAM;EACN,YAAY,IAAI,gBAAgB;GAC9B,UAAU;GACV,cAAc,CAAC,aAAa,GAAG,YAAY;EAC7C,CAAC;EACD,SAAS,IAAI,aAAa,EAAE,kBAAkB,YAAY,CAAC;EAC3D,OAAO;CACT,CAAC;CACD,MAAM,iBAAiB,MAAM,qBAAqB,WAAW,EAAE,UAAU,CAAC;CAC1E,KAAK,MAAM,CAAC,QAAQ,SAAS,OAAO,QAAQ,cAAc,GACxD,OAAO,QAAQ,MAAM,MAAM;CAK7B,IAAI,aAAa,GAAG;EAClB,OAAO,QAAQ,oBAAoB,GAAG,YAAY;EAClD,OAAO,QAAQ,qBAAqB,GAAG,aAAa;CACtD;CAKA,MAAM,UAAU,OAAO,WAAW;CAClC,IAAI,SAAS;EACX,MAAM,oBAAoB,4BAA4B,EACpD,SAAS,IAAI,yBAAyB,OAAgB,EACxD,CAAC;EACD,OAAO,QAAQ,mBAAmB,SAAS,kBAAkB;CAC/D;CAKA,IAAI,YACF,KAAK,MAAM,CAAC,QAAQ,SAAS,OAAO,QAAQ,WAAW,SAAS,CAAC,GAC/D,OAAO,QAAQ,MAAM,MAAM;AAGjC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mastra/code-sdk",
3
- "version": "1.5.0-alpha.11",
3
+ "version": "1.5.0-alpha.3",
4
4
  "description": "Mastra Code SDK: the agent core behind Mastra Code (everything except the TUI) — build your own UIs and surfaces on top of it",
5
5
  "type": "module",
6
6
  "publishConfig": {
@@ -57,17 +57,16 @@
57
57
  "vscode-languageserver-protocol": "^3.17.5",
58
58
  "yaml": "^2.7.1",
59
59
  "zod": "^4.3.6",
60
- "@mastra/agent-browser": "0.5.1",
61
- "@mastra/core": "1.62.0-alpha.11",
60
+ "@mastra/core": "1.62.0-alpha.3",
62
61
  "@mastra/duckdb": "1.6.3-alpha.0",
63
- "@mastra/libsql": "1.22.0-alpha.2",
64
- "@mastra/mcp": "1.17.2-alpha.2",
65
- "@mastra/github-signals": "0.3.0-alpha.0",
66
- "@mastra/memory": "1.28.0-alpha.4",
67
- "@mastra/observability": "1.17.2-alpha.2",
68
- "@mastra/fastembed": "1.3.0-alpha.0",
69
- "@mastra/pg": "1.22.0-alpha.4",
70
- "@mastra/parallel": "0.1.0-alpha.0",
62
+ "@mastra/fastembed": "1.2.0",
63
+ "@mastra/libsql": "1.22.0-alpha.0",
64
+ "@mastra/agent-browser": "0.5.1",
65
+ "@mastra/github-signals": "0.2.5",
66
+ "@mastra/mcp": "1.17.2-alpha.0",
67
+ "@mastra/memory": "1.27.1-alpha.0",
68
+ "@mastra/pg": "1.22.0-alpha.1",
69
+ "@mastra/observability": "1.17.2-alpha.1",
71
70
  "@mastra/schema-compat": "1.3.7",
72
71
  "@mastra/stagehand": "0.3.3",
73
72
  "@mastra/tavily": "1.1.1"
@@ -81,8 +80,8 @@
81
80
  "typescript": "^6.0.3",
82
81
  "typescript-eslint": "^8.57.0",
83
82
  "vitest": "4.1.10",
84
- "@internal/lint": "0.0.125",
85
83
  "@internal/types-builder": "0.0.100",
84
+ "@internal/lint": "0.0.125",
86
85
  "@internal/workspace-test-utils": "0.0.69"
87
86
  },
88
87
  "engines": {
@@ -1,84 +0,0 @@
1
- import type { PromptSection } from './prompts/index.js';
2
- /** A single measured contributor to the context window. */
3
- export interface ContextAuditEntry {
4
- id: string;
5
- label: string;
6
- /** Provenance: file path, server name, model id — whatever identifies the source. */
7
- detail?: string;
8
- tokens: number;
9
- characters: number;
10
- /** Share of the audit total, 0-100. */
11
- percent: number;
12
- }
13
- /** A category of contributors (e.g. all agent instruction files). */
14
- export interface ContextAuditGroup {
15
- id: string;
16
- label: string;
17
- tokens: number;
18
- /** Share of the audit total, 0-100. */
19
- percent: number;
20
- entries: ContextAuditEntry[];
21
- /** Shown alongside the group when its numbers need qualifying. */
22
- note?: string;
23
- }
24
- export interface ContextAudit {
25
- /** Context present before the first message: system prompt, skills, tools. */
26
- startup: {
27
- tokens: number;
28
- percent: number;
29
- groups: ContextAuditGroup[];
30
- };
31
- /** Context accumulated by the session: conversation and observation memory. */
32
- accumulated: {
33
- tokens: number;
34
- percent: number;
35
- groups: ContextAuditGroup[];
36
- };
37
- /** Startup + accumulated. Percentages elsewhere are shares of this. */
38
- totalTokens: number;
39
- /** Estimated rather than measured: token counts come from a heuristic estimator. */
40
- estimated: true;
41
- }
42
- /** A tool definition as advertised to the model. */
43
- export interface ContextAuditTool {
44
- name: string;
45
- description?: string;
46
- /** JSON schema (or any serializable shape) sent with the definition. */
47
- parameters?: unknown;
48
- /** MCP server that provides the tool, when it is not built in. */
49
- server?: string;
50
- }
51
- export interface ContextAuditInput {
52
- /** Labeled sections of the assembled system prompt. */
53
- promptSections?: PromptSection[];
54
- /** Labeled sections of the per-request dynamic instructions. */
55
- instructionSections?: PromptSection[];
56
- /** The skills catalog exactly as injected into the system message. */
57
- skillsCatalog?: string;
58
- /** Tool definitions advertised to the model. */
59
- tools?: ContextAuditTool[];
60
- /**
61
- * Observation memory currently occupying the context window, either as the
62
- * injected text or as a token count reported by the memory subsystem.
63
- *
64
- * Only observations that are actually in the context belong here.
65
- * Observations that merely sit in storage cost nothing until recalled, and
66
- * conflating the two is exactly the confusion this audit exists to resolve.
67
- */
68
- injectedObservations?: string | {
69
- tokens: number;
70
- };
71
- /** Prompt tokens the provider reported for the most recent request. */
72
- conversation?: {
73
- promptTokens?: number;
74
- };
75
- }
76
- /**
77
- * Build a context audit from already-collected context.
78
- *
79
- * Percentages are shares of the audited total, not of the model's context
80
- * window: window size is not exposed by the model registry, and inventing one
81
- * would make every number wrong for models that disagree with the guess.
82
- */
83
- export declare function buildContextAudit(input: ContextAuditInput): ContextAudit;
84
- //# sourceMappingURL=context-audit.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"context-audit.d.ts","sourceRoot":"","sources":["../../src/agents/context-audit.ts"],"names":[],"mappings":"AAcA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAExD,2DAA2D;AAC3D,MAAM,WAAW,iBAAiB;IAChC,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IACd,qFAAqF;IACrF,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,MAAM,CAAC;IACnB,uCAAuC;IACvC,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,qEAAqE;AACrE,MAAM,WAAW,iBAAiB;IAChC,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,uCAAuC;IACvC,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,iBAAiB,EAAE,CAAC;IAC7B,kEAAkE;IAClE,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,YAAY;IAC3B,8EAA8E;IAC9E,OAAO,EAAE;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,iBAAiB,EAAE,CAAA;KAAE,CAAC;IAC1E,+EAA+E;IAC/E,WAAW,EAAE;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,iBAAiB,EAAE,CAAA;KAAE,CAAC;IAC9E,uEAAuE;IACvE,WAAW,EAAE,MAAM,CAAC;IACpB,oFAAoF;IACpF,SAAS,EAAE,IAAI,CAAC;CACjB;AAED,oDAAoD;AACpD,MAAM,WAAW,gBAAgB;IAC/B,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,wEAAwE;IAC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