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

Method prepareDurableToolAttempt

packages/runtime/src/tool-runtime.ts:1631–1812  ·  view source on GitHub ↗
(input: {
    tool: MakaTool;
    startEvent: ToolStartEvent;
    persistedArgs: unknown;
    /** The projection the model replays as its own call. */
    modelFacingArgs: unknown;
    abortSignal: AbortSignal;
    invocationId?: string;
    runId?: string;
  })

Source from the content-addressed store, hash-verified

1629 }
1630
1631 private async prepareDurableToolAttempt(input: {
1632 tool: MakaTool;
1633 startEvent: ToolStartEvent;
1634 persistedArgs: unknown;
1635 /** The projection the model replays as its own call. */
1636 modelFacingArgs: unknown;
1637 abortSignal: AbortSignal;
1638 invocationId?: string;
1639 runId?: string;
1640 }): Promise<DurableToolAttempt | undefined> {
1641 const sink = this.input.runtimeCommitSink;
1642 if (!sink) return undefined;
1643 const runId = input.runId;
1644 const invocationId = input.invocationId;
1645 if (!runId) {
1646 throw new RuntimeCommitBoundaryError(
1647 'T1',
1648 new Error('Durable tool execution requires a run id'),
1649 );
1650 }
1651 if (!invocationId) {
1652 throw new RuntimeCommitBoundaryError(
1653 'T1',
1654 new Error('Durable tool execution requires an invocation id'),
1655 );
1656 }
1657 const operationId = input.startEvent.operationId;
1658 if (!operationId)
1659 throw new RuntimeCommitBoundaryError('T1', new Error('Tool start has no operation id'));
1660 const stateDelta: Record<string, unknown> = {};
1661 if (input.startEvent.activityKind !== undefined)
1662 stateDelta.activityKind = input.startEvent.activityKind;
1663 if (input.startEvent.displayName !== undefined)
1664 stateDelta.displayName = input.startEvent.displayName;
1665 if (input.startEvent.intent !== undefined) stateDelta.intent = input.startEvent.intent;
1666 const callEvent: RuntimeEvent = {
1667 id: input.startEvent.id,
1668 invocationId,
1669 runId,
1670 sessionId: this.input.sessionId,
1671 turnId: input.startEvent.turnId,
1672 ts: input.startEvent.ts,
1673 partial: false,
1674 role: 'model',
1675 author: 'agent',
1676 origin: input.startEvent.origin ?? 'provider',
1677 modelVisibility: input.startEvent.modelVisibility ?? 'visible',
1678 content: {
1679 kind: 'function_call',
1680 id: input.startEvent.toolUseId,
1681 name: input.tool.name,
1682 args: structuredClone(input.modelFacingArgs),
1683 ...(input.startEvent.providerOptions !== undefined
1684 ? { providerOptions: structuredClone(input.startEvent.providerOptions) }
1685 : {}),
1686 },
1687 refs: {
1688 operationId,

Callers 1

executeToolMethod · 0.95

Calls 8

durableAttemptKeyFunction · 0.85
keysMethod · 0.80
canonicalToolArgsHashFunction · 0.70
commitToolPreparedMethod · 0.65
nowMethod · 0.65
commitToolOutcomeMethod · 0.65
deleteMethod · 0.65

Tested by

no test coverage detected