44
details: { code?: number; slug?: string } | undefined
45
): boolean => details?.code === 4302 || isNoConnectionSlug(details?.slug);
46
47
+/** The command tree the failing command ran in; connections do not carry over between the two. */
48
+type ConnectionTree = 'root' | 'dev';
49
+
50
+/**
51
+ * The link command of the tree the failure happened in. A root-tree link
52
+ * connects the consumer user, which leaves a `dev` command failing as before.
53
+ */
54
+const linkStep = (toolkit: string, tree: ConnectionTree): string =>
55
+ tree === 'dev'
56
+ ? `Run \`composio dev connected-accounts link ${toolkit}\` (with the same \`--user-id\`, if you passed one), then retry.`
57
+ : `Run \`composio link ${toolkit}\`, then retry.`;
58
+
59
export const buildNoActiveConnectionMessage = (params: {
60
readonly toolkit?: string;
61
readonly toolSlug?: string;
62
+ readonly tree?: ConnectionTree;
63
}) => {
64
+ const tree = params.tree ?? 'root';
65
if (params.toolkit) {
52
- return `No active connection found for toolkit "${params.toolkit}". Run \`composio link ${params.toolkit}\`, then retry.`;
66
+ return `No active connection found for toolkit "${params.toolkit}". ${linkStep(params.toolkit, tree)}`;
67
}
68
if (params.toolSlug) {
69
// Best-effort fallback for callers that could not resolve the toolkit.
72
// bare-slug case.
73
const toolkit = guessToolkitFromToolSlug(params.toolSlug);
74
if (toolkit && toolkit !== 'composio') {
61
- return `No active connection found for toolkit "${toolkit}". Run \`composio link ${toolkit}\`, then retry.`;
75
+ return `No active connection found for toolkit "${toolkit}". ${linkStep(toolkit, tree)}`;
76
}
77
}
78
return 'No active connection found for this tool call. Link the required toolkit/app, then retry.';
83
readonly apiDetails?: ApiErrorDetails;
84
readonly toolkit?: string;
85
readonly toolSlug?: string;
86
+ readonly tree: ConnectionTree;
87
88
constructor(params: {
89
readonly details: unknown;
90
readonly apiDetails?: ApiErrorDetails;
91
readonly toolkit?: string;
92
readonly toolSlug?: string;
93
+ readonly tree?: ConnectionTree;
94
}) {
95
super(
96
buildNoActiveConnectionMessage({
97
toolkit: params.toolkit,
98
toolSlug: params.toolSlug,
99
+ tree: params.tree,
100
})
101
);
102
this.name = 'ComposioNoActiveConnectionError';
104
this.apiDetails = params.apiDetails;
105
this.toolkit = params.toolkit;
106
this.toolSlug = params.toolSlug;
107
+ this.tree = params.tree ?? 'root';
108
}
109
}
110
112
readonly error: unknown;
113
readonly toolkit?: string;
114
readonly toolSlug?: string;
115
+ /** The tree of the command reporting the failure; the root tree when omitted. */
116
+ readonly tree?: ConnectionTree;
117
}) => {
118
const normalized = normalizeCliError(params.error);
119
const apiDetails =
125
normalized instanceof ComposioNoActiveConnectionError ||
126
isNoActiveConnectionApiError(apiDetails)
127
) {
128
+ const tree = params.tree ?? 'root';
129
+ // The executor raises this error without knowing the tree; the command
130
+ // that reports it does, and its message has to name that tree's link.
131
const mapped =
132
normalized instanceof ComposioNoActiveConnectionError
110
- ? normalized
133
+ ? normalized.tree === tree
134
+ ? normalized
135
+ : new ComposioNoActiveConnectionError({
136
+ details: normalized.details,
137
+ apiDetails: normalized.apiDetails,
138
+ toolkit: normalized.toolkit ?? params.toolkit,
139
+ toolSlug: normalized.toolSlug ?? params.toolSlug,
140
+ tree,
141
+ })
142
: new ComposioNoActiveConnectionError({
143
details: apiDetails ?? params.error,
144
apiDetails,
145
toolkit: params.toolkit,
146
toolSlug: params.toolSlug,
147
+ tree,
148
});
149
150
return {