(config: PythonReplToolConfig)
| 562 | } |
| 563 | |
| 564 | export function createPythonReplTool(config: PythonReplToolConfig) { |
| 565 | const inputSchema = buildInputSchema(config.inputSchemaDescription) |
| 566 | const outputSchema = buildOutputSchema() |
| 567 | const hiddenToolNames = new Set(config.forbiddenNestedToolNames ?? []) |
| 568 | |
| 569 | return buildTool({ |
| 570 | name: config.toolName, |
| 571 | searchHint: config.searchHint, |
| 572 | maxResultSizeChars: Infinity, |
| 573 | async description() { |
| 574 | return config.description |
| 575 | }, |
| 576 | get inputSchema() { |
| 577 | return inputSchema() |
| 578 | }, |
| 579 | get outputSchema() { |
| 580 | return outputSchema() |
| 581 | }, |
| 582 | isReadOnly() { |
| 583 | return false |
| 584 | }, |
| 585 | toAutoClassifierInput(input) { |
| 586 | return input.code |
| 587 | }, |
| 588 | async checkPermissions(input, context): Promise<PermissionResult> { |
| 589 | const mode = context.getAppState().toolPermissionContext.mode |
| 590 | if (mode === 'acceptEdits') { |
| 591 | return { |
| 592 | behavior: 'allow', |
| 593 | updatedInput: input, |
| 594 | decisionReason: { |
| 595 | type: 'mode', |
| 596 | mode, |
| 597 | }, |
| 598 | } |
| 599 | } |
| 600 | return { |
| 601 | behavior: 'passthrough', |
| 602 | updatedInput: input, |
| 603 | } |
| 604 | }, |
| 605 | async prompt() { |
| 606 | return typeof config.prompt === 'function' ? config.prompt() : config.prompt |
| 607 | }, |
| 608 | userFacingName() { |
| 609 | return config.userFacingName |
| 610 | }, |
| 611 | renderToolUseMessage(input) { |
| 612 | const compact = input.code.replace(/\s+/g, ' ').trim() |
| 613 | if (!compact) { |
| 614 | return 'script' |
| 615 | } |
| 616 | return preview(compact, 120) |
| 617 | }, |
| 618 | renderToolUseProgressMessage(progressMessages) { |
| 619 | const latest = [...progressMessages] |
| 620 | .reverse() |
| 621 | .find( |
no test coverage detected