{"version":3,"file":"SubagentTool.cjs","sources":["../../../src/tools/SubagentTool.ts"],"sourcesContent":["import { Constants } from '@/common';\nimport type { SubagentConfig } from '@/types';\nimport type { JsonSchemaType, LCTool } from '@/types/tools';\n\nexport const SubagentToolName = Constants.SUBAGENT;\n\nexport const SubagentToolDescription = `Delegate a task to a specialized subagent that runs in an isolated context window. The subagent executes independently and returns only its final text result — all intermediate tool calls, reasoning, and context stay isolated.\n\nWHEN TO USE:\n- The task is self-contained and can be described in a single prompt.\n- You want to offload verbose or exploratory work without bloating your own context.\n- A specialized subagent is available for the task domain.\n\nWHAT HAPPENS:\n- A fresh agent is created with the task description as its only input.\n- The subagent runs to completion using its own tools and context.\n- Only the final text response is returned to you.\n\nCONSTRAINTS:\n- subagent_type must match one of the available types listed below.\n- The subagent cannot see your conversation history.`;\n\nconst DESCRIPTION_PROP_DESCRIPTION =\n  'Complete task description for the subagent. This is the ONLY information it receives — include all necessary context, requirements, and constraints.';\n\nconst SUBAGENT_TYPE_PROP_DESCRIPTION =\n  'Which subagent type to delegate to. Must be one of the available types.';\n\nexport const SubagentToolSchema = {\n  type: 'object',\n  properties: {\n    description: {\n      type: 'string',\n      description: DESCRIPTION_PROP_DESCRIPTION,\n    },\n    subagent_type: {\n      type: 'string',\n      description: SUBAGENT_TYPE_PROP_DESCRIPTION,\n    },\n  },\n  required: ['description', 'subagent_type'] as string[],\n} as const;\n\nexport const SubagentToolDefinition: LCTool = {\n  name: SubagentToolName,\n  description: SubagentToolDescription,\n  parameters: SubagentToolSchema,\n};\n\n/**\n * Build the name, schema, and description params for `tool()` from available configs.\n * Used by `Graph.createAgentNode()` when constructing the runtime tool instance.\n * Extends `SubagentToolSchema` by populating `subagent_type.enum` dynamically.\n */\nexport function buildSubagentToolParams(configs: SubagentConfig[]): {\n  name: string;\n  schema: JsonSchemaType;\n  description: string;\n} {\n  const types = configs.map((c) => c.type);\n  const typeDescriptions = configs\n    .map((c) => `- \"${c.type}\" (${c.name}): ${c.description}`)\n    .join('\\n');\n\n  return {\n    name: SubagentToolName,\n    schema: {\n      type: 'object',\n      properties: {\n        description: {\n          type: 'string',\n          description: DESCRIPTION_PROP_DESCRIPTION,\n        },\n        subagent_type: {\n          type: 'string',\n          enum: types,\n          description: `${SUBAGENT_TYPE_PROP_DESCRIPTION} Available: ${types.join(', ')}.`,\n        },\n      },\n      required: ['description', 'subagent_type'],\n    },\n    description: `${SubagentToolDescription}\\n\\nAvailable types:\\n${typeDescriptions}`,\n  };\n}\n\n/**\n * Create a SubagentTool LCTool definition with dynamic enum and description\n * populated from the available subagent configs.\n * Used for the tool registry in event-driven mode.\n */\nexport function createSubagentToolDefinition(\n  configs: SubagentConfig[]\n): LCTool {\n  const params = buildSubagentToolParams(configs);\n  return {\n    name: params.name,\n    description: params.description,\n    parameters: params.schema,\n  };\n}\n"],"names":["Constants"],"mappings":";;;;;AAIO,MAAM,gBAAgB,GAAGA,eAAS,CAAC;AAEnC,MAAM,uBAAuB,GAAG,CAAA;;;;;;;;;;;;;;;AAgBvC,MAAM,4BAA4B,GAChC,sJAAsJ;AAExJ,MAAM,8BAA8B,GAClC,yEAAyE;AAEpE,MAAM,kBAAkB,GAAG;AAChC,IAAA,IAAI,EAAE,QAAQ;AACd,IAAA,UAAU,EAAE;AACV,QAAA,WAAW,EAAE;AACX,YAAA,IAAI,EAAE,QAAQ;AACd,YAAA,WAAW,EAAE,4BAA4B;AAC1C,SAAA;AACD,QAAA,aAAa,EAAE;AACb,YAAA,IAAI,EAAE,QAAQ;AACd,YAAA,WAAW,EAAE,8BAA8B;AAC5C,SAAA;AACF,KAAA;AACD,IAAA,QAAQ,EAAE,CAAC,aAAa,EAAE,eAAe,CAAa;;AAGjD,MAAM,sBAAsB,GAAW;AAC5C,IAAA,IAAI,EAAE,gBAAgB;AACtB,IAAA,WAAW,EAAE,uBAAuB;AACpC,IAAA,UAAU,EAAE,kBAAkB;;AAGhC;;;;AAIG;AACG,SAAU,uBAAuB,CAAC,OAAyB,EAAA;AAK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