(input: {
readonly path: readonly string[];
readonly role?: string | undefined;
readonly bindings: ArtifactBindings | null;
})
| 376 | * through this door. |
| 377 | */ |
| 378 | export const resolveCallAddress = (input: { |
| 379 | readonly path: readonly string[]; |
| 380 | readonly role?: string | undefined; |
| 381 | readonly bindings: ArtifactBindings | null; |
| 382 | }): CallAddressResolution => { |
| 383 | const [root, ...rest] = input.path; |
| 384 | if (root === undefined) { |
| 385 | return { |
| 386 | ok: false, |
| 387 | error: "binding_unresolved", |
| 388 | role: "", |
| 389 | integration: "", |
| 390 | message: "This artifact made a tool call with no path.", |
| 391 | }; |
| 392 | } |
| 393 | |
| 394 | if (input.role === undefined && RESERVED_TOOL_ROOTS.has(root)) { |
| 395 | return { ok: true, path: input.path }; |
| 396 | } |
| 397 | |
| 398 | const role = input.role ?? root; |
| 399 | const binding = input.bindings?.[role]; |
| 400 | if (binding) { |
| 401 | return { ok: true, path: [binding.integration, binding.owner, binding.connection, ...rest] }; |
| 402 | } |
| 403 | |
| 404 | if (input.role === undefined && input.bindings === null && isFullAddressPath(input.path)) { |
| 405 | return { ok: true, path: input.path }; |
| 406 | } |
| 407 | |
| 408 | const known = Object.keys(input.bindings ?? {}); |
| 409 | return { |
| 410 | ok: false, |
| 411 | error: "binding_unresolved", |
| 412 | role, |
| 413 | integration: root, |
| 414 | message: [ |
| 415 | `This artifact has no connection bound for the role "${role}" (${root}).`, |
| 416 | known.length > 0 |
| 417 | ? `It is bound for ${known.map((name) => `"${name}"`).join(", ")}.` |
| 418 | : "It has no connection bindings at all.", |
| 419 | "The connection may have been renamed or deleted since the artifact was saved — recreate it, or reconnect the integration.", |
| 420 | ].join(" "), |
| 421 | }; |
| 422 | }; |
no test coverage detected