MCPcopy Create free account
hub / github.com/apache/maka / executeTool

Method executeTool

packages/runtime/src/tool-runtime.ts:867–1629  ·  view source on GitHub ↗
(
    tool: MakaTool,
    turnId: string,
    queue: DurableSessionEventSink,
    args: unknown,
    ctx: {
      toolCallId: string;
      abortSignal: AbortSignal;
      providerOptions?: Record<string, unknown>;
      origin: 'provider' | 'code_mode';
      parentToolCallId?: string;
      parentOperationId?: string;
      maxResultBytes?: number;
    },
    stepId?: string,
  )

Source from the content-addressed store, hash-verified

865 }
866
867 private async executeTool(
868 tool: MakaTool,
869 turnId: string,
870 queue: DurableSessionEventSink,
871 args: unknown,
872 ctx: {
873 toolCallId: string;
874 abortSignal: AbortSignal;
875 providerOptions?: Record<string, unknown>;
876 origin: 'provider' | 'code_mode';
877 parentToolCallId?: string;
878 parentOperationId?: string;
879 maxResultBytes?: number;
880 },
881 stepId?: string,
882 ): Promise<unknown> {
883 const rawExecutionArgs = snapshotToolArgs(args);
884 const toolUseId = ctx.toolCallId;
885 // Registration is synchronous and happens before the first await, so
886 // parallel Runtime settlements cannot race past exclusive admission.
887 const directOnlyFailure =
888 ctx.origin === 'code_mode' && tool.nesting === 'direct_only'
889 ? `Tool ${tool.name} is direct-only and cannot run inside exec.`
890 : undefined;
891 const admissionFailure = directOnlyFailure ?? this.admitToolForStep(tool, stepId);
892 const executionArgs = rawExecutionArgs;
893 let permissionArgs = executionArgs;
894 let permissionArgsError: unknown;
895 if (directOnlyFailure === undefined) {
896 try {
897 // A surface that cannot carry a sandbox-boundary request rejects the
898 // operation before it interprets the requested expansion. Preserve that
899 // availability contract even when an older caller sends a legacy shape.
900 const sandboxBoundaryUnavailable =
901 tool.name === 'request_sandbox_boundary' &&
902 !this.interactionRun() &&
903 (!this.input.createSandboxBoundaryRequest || !this.input.settleSandboxBoundaryRequest);
904 if (!sandboxBoundaryUnavailable) {
905 await validateDeclaredToolArgs(tool.parameters, rawExecutionArgs);
906 }
907 permissionArgs = tool.permissionArgs
908 ? snapshotToolArgs(
909 tool.permissionArgs(structuredClone(executionArgs) as never, {
910 sessionId: this.input.sessionId,
911 turnId,
912 toolCallId: toolUseId,
913 }),
914 )
915 : executionArgs;
916 } catch (error) {
917 permissionArgsError = error;
918 }
919 }
920 // The args written into the `tool_start` event, the persisted `tool_call`
921 // message and the durable ledger — that is, the record of the call the
922 // model reads back on its next turn (`model-history.ts` replays
923 // `event.content.args`).
924 //

Callers 1

performToolSettlementMethod · 0.95

Calls 15

admitToolForStepMethod · 0.95
interactionRunMethod · 0.95
recordLoopGateOutcomeMethod · 0.95
errorReturnMethod · 0.95
reserveSubagentSlotMethod · 0.95
releaseSubagentSlotMethod · 0.95
askUserQuestionMethod · 0.95
computerUseModelCallArgsFunction · 0.90

Tested by

no test coverage detected