Skip to content

Commit 2243ed1

Browse files
Askirclaude
andcommitted
feat(core): auto-select sole integration connection at runtime
When a node needs an integration and no connection is configured, automatically use the only available connection instead of requiring manual selection in the Dev UI. Persists the choice as a global default. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 2e50973 commit 2243ed1

File tree

1 file changed

+24
-7
lines changed

1 file changed

+24
-7
lines changed

packages/core/src/workflow.ts

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import { z } from "zod";
33
import { DBOS } from "@dbos-inc/dbos-sdk";
44
import type { Executable, WorkflowContext, LogLevel, ConnectionCredentials } from "./types.js";
5-
import { resolveConnectionId } from "./connections/index.js";
5+
import { resolveConnectionId, upsertConnection } from "./connections/index.js";
66
import type { IntegrationProvider } from "./connections/integration-provider.js";
77
import type pg from "pg";
88

@@ -87,7 +87,7 @@ function createDurableContext(config?: WorkflowRuntimeConfig): WorkflowContext {
8787
);
8888
}
8989

90-
const connectionId = await resolveConnectionId(
90+
let connectionId = await resolveConnectionId(
9191
config.sql,
9292
config.workflowName,
9393
_currentNodeName,
@@ -96,11 +96,28 @@ function createDurableContext(config?: WorkflowRuntimeConfig): WorkflowContext {
9696
);
9797

9898
if (!connectionId) {
99-
throw new Error(
100-
`No connection configured for integration "${integrationId}" ` +
101-
`(workflow="${config.workflowName}", node="${_currentNodeName}"). ` +
102-
`Configure it in the Dev UI or set a global default.`,
103-
);
99+
// Auto-select if exactly one connection exists for this integration
100+
const available = await config.integrationProvider.listConnections(integrationId);
101+
if (available.length === 1) {
102+
connectionId = available[0].connection_id;
103+
// Persist as global default so subsequent calls skip this lookup
104+
await upsertConnection(
105+
config.sql,
106+
{ workflow_name: "*", node_name: "*", integration_id: integrationId, connection_id: connectionId },
107+
config.appSchema,
108+
);
109+
} else if (available.length === 0) {
110+
throw new Error(
111+
`No connections available for integration "${integrationId}". ` +
112+
`Set up a connection in the Dev UI first.`,
113+
);
114+
} else {
115+
throw new Error(
116+
`Multiple connections available for integration "${integrationId}" ` +
117+
`(${available.map(c => c.connection_id).join(", ")}). ` +
118+
`Select one in the Dev UI or set a global default.`,
119+
);
120+
}
104121
}
105122

106123
return config.integrationProvider.fetchCredentials(integrationId, connectionId);

0 commit comments

Comments
 (0)