@koda-sl/baker-bridge 0.118.0-dev.fc1af4da8 → 0.118.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (81) hide show
  1. package/README.md +2 -0
  2. package/dist/broker/baker-api.d.ts +9 -0
  3. package/dist/broker/baker-api.d.ts.map +1 -1
  4. package/dist/broker/baker-api.js +14 -0
  5. package/dist/broker/baker-api.js.map +1 -1
  6. package/dist/broker/ca.d.ts +8 -0
  7. package/dist/broker/ca.d.ts.map +1 -1
  8. package/dist/broker/ca.js +13 -2
  9. package/dist/broker/ca.js.map +1 -1
  10. package/dist/broker/ca.test.js +18 -2
  11. package/dist/broker/ca.test.js.map +1 -1
  12. package/dist/broker/credential-cache.d.ts +2 -7
  13. package/dist/broker/credential-cache.d.ts.map +1 -1
  14. package/dist/broker/credential-cache.js +45 -12
  15. package/dist/broker/credential-cache.js.map +1 -1
  16. package/dist/broker/credential-cache.test.js +47 -1
  17. package/dist/broker/credential-cache.test.js.map +1 -1
  18. package/dist/broker/credential-text.d.ts.map +1 -1
  19. package/dist/broker/credential-text.js +3 -0
  20. package/dist/broker/credential-text.js.map +1 -1
  21. package/dist/broker/credential-text.test.js +2 -0
  22. package/dist/broker/credential-text.test.js.map +1 -1
  23. package/dist/broker/proxy.d.ts.map +1 -1
  24. package/dist/broker/proxy.integration.test.js +73 -0
  25. package/dist/broker/proxy.integration.test.js.map +1 -1
  26. package/dist/broker/proxy.js +28 -18
  27. package/dist/broker/proxy.js.map +1 -1
  28. package/dist/broker/rewrite.d.ts +7 -1
  29. package/dist/broker/rewrite.d.ts.map +1 -1
  30. package/dist/broker/rewrite.js +21 -5
  31. package/dist/broker/rewrite.js.map +1 -1
  32. package/dist/broker/socket-service.d.ts.map +1 -1
  33. package/dist/broker/socket-service.js +20 -1
  34. package/dist/broker/socket-service.js.map +1 -1
  35. package/dist/broker/socket-service.test.js +13 -2
  36. package/dist/broker/socket-service.test.js.map +1 -1
  37. package/dist/hono/agent.d.ts.map +1 -1
  38. package/dist/hono/agent.js +1 -0
  39. package/dist/hono/agent.js.map +1 -1
  40. package/dist/hono/avatar-casting.d.ts.map +1 -1
  41. package/dist/hono/avatar-casting.js +3 -2
  42. package/dist/hono/avatar-casting.js.map +1 -1
  43. package/dist/hono/baker-ui-tool-schemas.test.js +26 -5
  44. package/dist/hono/baker-ui-tool-schemas.test.js.map +1 -1
  45. package/dist/hono/blocking-card.d.ts +12 -0
  46. package/dist/hono/blocking-card.d.ts.map +1 -0
  47. package/dist/hono/blocking-card.js +12 -0
  48. package/dist/hono/blocking-card.js.map +1 -0
  49. package/dist/hono/bridge-job.d.ts +29 -1
  50. package/dist/hono/bridge-job.d.ts.map +1 -1
  51. package/dist/hono/bridge-job.js +73 -3
  52. package/dist/hono/bridge-job.js.map +1 -1
  53. package/dist/hono/bridge-job.test.js +130 -0
  54. package/dist/hono/bridge-job.test.js.map +1 -1
  55. package/dist/hono/connection-input.d.ts +155 -12
  56. package/dist/hono/connection-input.d.ts.map +1 -1
  57. package/dist/hono/connection-input.js +131 -15
  58. package/dist/hono/connection-input.js.map +1 -1
  59. package/dist/hono/connection-input.test.js +78 -9
  60. package/dist/hono/connection-input.test.js.map +1 -1
  61. package/dist/hono/credential-input.d.ts.map +1 -1
  62. package/dist/hono/credential-input.js +3 -2
  63. package/dist/hono/credential-input.js.map +1 -1
  64. package/dist/hono/flow-input.d.ts.map +1 -1
  65. package/dist/hono/flow-input.js +3 -2
  66. package/dist/hono/flow-input.js.map +1 -1
  67. package/dist/hono/mcp-servers.d.ts +8 -1
  68. package/dist/hono/mcp-servers.d.ts.map +1 -1
  69. package/dist/hono/mcp-servers.js +17 -6
  70. package/dist/hono/mcp-servers.js.map +1 -1
  71. package/dist/hono/mcp-servers.test.js +25 -0
  72. package/dist/hono/mcp-servers.test.js.map +1 -1
  73. package/dist/hono/prompt-context.test.js +4 -1
  74. package/dist/hono/prompt-context.test.js.map +1 -1
  75. package/dist/hono/tag-input.d.ts +41 -2
  76. package/dist/hono/tag-input.d.ts.map +1 -1
  77. package/dist/hono/tag-input.js +8 -4
  78. package/dist/hono/tag-input.js.map +1 -1
  79. package/dist/hono/tag-input.test.js +5 -1
  80. package/dist/hono/tag-input.test.js.map +1 -1
  81. package/package.json +1 -1
@@ -12,11 +12,12 @@ export declare const CONNECTION_INPUT_TOOL_NAME = "mcp__baker_ui__request_connec
12
12
  * backend: a platform live in one and missing from another is a door that
13
13
  * looks open from one side only.
14
14
  */
15
- export declare const CONNECTION_PLATFORMS: readonly ["google-ads", "linkedin", "meta", "google-analytics", "google-search-console", "google-tag-manager", "x-ads", "hubspot", "google-drive", "highlevel", "pipedrive", "calendly", "savvycal"];
15
+ export declare const CONNECTION_PLATFORMS: readonly ["google-ads", "linkedin", "meta", "google-analytics", "google-search-console", "google-tag-manager", "x-ads", "hubspot", "google-drive", "highlevel", "pipedrive", "calendly", "savvycal", "chatgpt-ads"];
16
16
  export type ConnectionPlatform = (typeof CONNECTION_PLATFORMS)[number];
17
- declare const connectionRequestShape: z.ZodObject<{
17
+ declare const connectionRequestShape: z.ZodUnion<readonly [z.ZodObject<{
18
18
  platform: z.ZodEnum<{
19
19
  calendly: "calendly";
20
+ "chatgpt-ads": "chatgpt-ads";
20
21
  "google-ads": "google-ads";
21
22
  "google-analytics": "google-analytics";
22
23
  "google-drive": "google-drive";
@@ -32,11 +33,33 @@ declare const connectionRequestShape: z.ZodObject<{
32
33
  }>;
33
34
  reason: z.ZodString;
34
35
  choose: z.ZodOptional<z.ZodLiteral<"media-folder">>;
35
- }, z.core.$strip>;
36
+ }, z.core.$strip>, z.ZodObject<{
37
+ app: z.ZodString;
38
+ reason: z.ZodString;
39
+ }, z.core.$strip>, z.ZodObject<{
40
+ server: z.ZodObject<{
41
+ name: z.ZodString;
42
+ url: z.ZodString;
43
+ auth: z.ZodOptional<z.ZodEnum<{
44
+ key: "key";
45
+ none: "none";
46
+ "sign-in": "sign-in";
47
+ }>>;
48
+ keyHeader: z.ZodOptional<z.ZodString>;
49
+ scope: z.ZodOptional<z.ZodEnum<{
50
+ company: "company";
51
+ org: "org";
52
+ user: "user";
53
+ user_org: "user_org";
54
+ }>>;
55
+ }, z.core.$strip>;
56
+ reason: z.ZodString;
57
+ }, z.core.$strip>]>;
36
58
  export declare const connectionInputToolShape: {
37
- connections: z.ZodArray<z.ZodObject<{
59
+ connections: z.ZodArray<z.ZodUnion<readonly [z.ZodObject<{
38
60
  platform: z.ZodEnum<{
39
61
  calendly: "calendly";
62
+ "chatgpt-ads": "chatgpt-ads";
40
63
  "google-ads": "google-ads";
41
64
  "google-analytics": "google-analytics";
42
65
  "google-drive": "google-drive";
@@ -52,13 +75,35 @@ export declare const connectionInputToolShape: {
52
75
  }>;
53
76
  reason: z.ZodString;
54
77
  choose: z.ZodOptional<z.ZodLiteral<"media-folder">>;
55
- }, z.core.$strip>>;
78
+ }, z.core.$strip>, z.ZodObject<{
79
+ app: z.ZodString;
80
+ reason: z.ZodString;
81
+ }, z.core.$strip>, z.ZodObject<{
82
+ server: z.ZodObject<{
83
+ name: z.ZodString;
84
+ url: z.ZodString;
85
+ auth: z.ZodOptional<z.ZodEnum<{
86
+ key: "key";
87
+ none: "none";
88
+ "sign-in": "sign-in";
89
+ }>>;
90
+ keyHeader: z.ZodOptional<z.ZodString>;
91
+ scope: z.ZodOptional<z.ZodEnum<{
92
+ company: "company";
93
+ org: "org";
94
+ user: "user";
95
+ user_org: "user_org";
96
+ }>>;
97
+ }, z.core.$strip>;
98
+ reason: z.ZodString;
99
+ }, z.core.$strip>]>>;
56
100
  resolution: z.ZodOptional<z.ZodObject<{}, z.core.$catchall<z.ZodUnknown>>>;
57
101
  };
58
- export declare const connectionInputResultSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
102
+ export declare const connectionInputResultSchema: z.ZodUnion<readonly [z.ZodObject<{
59
103
  status: z.ZodLiteral<"connected">;
60
104
  platform: z.ZodEnum<{
61
105
  calendly: "calendly";
106
+ "chatgpt-ads": "chatgpt-ads";
62
107
  "google-ads": "google-ads";
63
108
  "google-analytics": "google-analytics";
64
109
  "google-drive": "google-drive";
@@ -80,6 +125,7 @@ export declare const connectionInputResultSchema: z.ZodDiscriminatedUnion<[z.Zod
80
125
  status: z.ZodLiteral<"declined">;
81
126
  platform: z.ZodEnum<{
82
127
  calendly: "calendly";
128
+ "chatgpt-ads": "chatgpt-ads";
83
129
  "google-ads": "google-ads";
84
130
  "google-analytics": "google-analytics";
85
131
  "google-drive": "google-drive";
@@ -94,13 +140,43 @@ export declare const connectionInputResultSchema: z.ZodDiscriminatedUnion<[z.Zod
94
140
  "x-ads": "x-ads";
95
141
  }>;
96
142
  reason: z.ZodOptional<z.ZodString>;
97
- }, z.core.$strip>], "status">;
143
+ }, z.core.$strip>, z.ZodObject<{
144
+ status: z.ZodLiteral<"connected">;
145
+ app: z.ZodString;
146
+ scope: z.ZodEnum<{
147
+ company: "company";
148
+ org: "org";
149
+ user: "user";
150
+ user_org: "user_org";
151
+ }>;
152
+ accountLabel: z.ZodOptional<z.ZodString>;
153
+ readOnly: z.ZodOptional<z.ZodBoolean>;
154
+ }, z.core.$strip>, z.ZodObject<{
155
+ status: z.ZodLiteral<"declined">;
156
+ app: z.ZodString;
157
+ reason: z.ZodOptional<z.ZodString>;
158
+ }, z.core.$strip>, z.ZodObject<{
159
+ status: z.ZodLiteral<"connected">;
160
+ server: z.ZodString;
161
+ scope: z.ZodEnum<{
162
+ company: "company";
163
+ org: "org";
164
+ user: "user";
165
+ user_org: "user_org";
166
+ }>;
167
+ problem: z.ZodOptional<z.ZodString>;
168
+ }, z.core.$strip>, z.ZodObject<{
169
+ status: z.ZodLiteral<"declined">;
170
+ server: z.ZodString;
171
+ reason: z.ZodOptional<z.ZodString>;
172
+ }, z.core.$strip>]>;
98
173
  export type ConnectionInputResult = z.infer<typeof connectionInputResultSchema>;
99
174
  export declare const connectionInputResolutionSchema: z.ZodObject<{
100
- results: z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
175
+ results: z.ZodArray<z.ZodUnion<readonly [z.ZodObject<{
101
176
  status: z.ZodLiteral<"connected">;
102
177
  platform: z.ZodEnum<{
103
178
  calendly: "calendly";
179
+ "chatgpt-ads": "chatgpt-ads";
104
180
  "google-ads": "google-ads";
105
181
  "google-analytics": "google-analytics";
106
182
  "google-drive": "google-drive";
@@ -122,6 +198,7 @@ export declare const connectionInputResolutionSchema: z.ZodObject<{
122
198
  status: z.ZodLiteral<"declined">;
123
199
  platform: z.ZodEnum<{
124
200
  calendly: "calendly";
201
+ "chatgpt-ads": "chatgpt-ads";
125
202
  "google-ads": "google-ads";
126
203
  "google-analytics": "google-analytics";
127
204
  "google-drive": "google-drive";
@@ -136,9 +213,52 @@ export declare const connectionInputResolutionSchema: z.ZodObject<{
136
213
  "x-ads": "x-ads";
137
214
  }>;
138
215
  reason: z.ZodOptional<z.ZodString>;
139
- }, z.core.$strip>], "status">>;
216
+ }, z.core.$strip>, z.ZodObject<{
217
+ status: z.ZodLiteral<"connected">;
218
+ app: z.ZodString;
219
+ scope: z.ZodEnum<{
220
+ company: "company";
221
+ org: "org";
222
+ user: "user";
223
+ user_org: "user_org";
224
+ }>;
225
+ accountLabel: z.ZodOptional<z.ZodString>;
226
+ readOnly: z.ZodOptional<z.ZodBoolean>;
227
+ }, z.core.$strip>, z.ZodObject<{
228
+ status: z.ZodLiteral<"declined">;
229
+ app: z.ZodString;
230
+ reason: z.ZodOptional<z.ZodString>;
231
+ }, z.core.$strip>, z.ZodObject<{
232
+ status: z.ZodLiteral<"connected">;
233
+ server: z.ZodString;
234
+ scope: z.ZodEnum<{
235
+ company: "company";
236
+ org: "org";
237
+ user: "user";
238
+ user_org: "user_org";
239
+ }>;
240
+ problem: z.ZodOptional<z.ZodString>;
241
+ }, z.core.$strip>, z.ZodObject<{
242
+ status: z.ZodLiteral<"declined">;
243
+ server: z.ZodString;
244
+ reason: z.ZodOptional<z.ZodString>;
245
+ }, z.core.$strip>]>>;
140
246
  }, z.core.$strip>;
141
247
  export type ConnectionInputResolution = z.infer<typeof connectionInputResolutionSchema>;
248
+ /**
249
+ * Whether the user connected something that brings MCP tools — an app or a
250
+ * server. Only then is the turn's server set reloaded: a platform is read with
251
+ * `baker` commands and adds no tool, and reloading for nothing would rewrite
252
+ * the tool list, and the prompt cache with it.
253
+ */
254
+ export declare function toolsConnected(resolution: ConnectionInputResolution): boolean;
255
+ /**
256
+ * What the user connected that the reloaded server set does not carry, by the
257
+ * name the agent knows it by. An app arrives inside its scope's managed server
258
+ * (`composio_<scope>`), which is absent when the company has managed apps
259
+ * switched off or the session for them could not be made.
260
+ */
261
+ export declare function connectedButNotLoaded(resolution: ConnectionInputResolution, loaded: readonly string[]): string[];
142
262
  /** Parse-at-boundary for the resolution posted to `POST /connection-input-decision`. */
143
263
  export declare function parseConnectionInputResolution(value: unknown): ConnectionInputResolution | null;
144
264
  export type ConnectionInputRequest = z.infer<typeof connectionRequestShape>;
@@ -146,13 +266,15 @@ export type ConnectionInputRequest = z.infer<typeof connectionRequestShape>;
146
266
  * `canUseTool` sees the RAW model input — MCP validation hasn't run yet — so the
147
267
  * requests are normalized here before anything downstream trusts them. Unknown
148
268
  * platforms (TikTok Ads, a hallucinated id) are dropped rather than shown as a
149
- * dead tab.
269
+ * dead tab. The dashboard applies the same rules (`connectionRequestsFromToolInput`)
270
+ * because it resolves tabs by index into this list.
150
271
  */
151
272
  export declare function normalizeConnectionInputToolInput(input: unknown): ConnectionInputRequest[];
152
273
  export declare function createConnectionInputTool(): import("@anthropic-ai/claude-agent-sdk").SdkMcpToolDefinition<{
153
- connections: z.ZodArray<z.ZodObject<{
274
+ connections: z.ZodArray<z.ZodUnion<readonly [z.ZodObject<{
154
275
  platform: z.ZodEnum<{
155
276
  calendly: "calendly";
277
+ "chatgpt-ads": "chatgpt-ads";
156
278
  "google-ads": "google-ads";
157
279
  "google-analytics": "google-analytics";
158
280
  "google-drive": "google-drive";
@@ -168,7 +290,28 @@ export declare function createConnectionInputTool(): import("@anthropic-ai/claud
168
290
  }>;
169
291
  reason: z.ZodString;
170
292
  choose: z.ZodOptional<z.ZodLiteral<"media-folder">>;
171
- }, z.core.$strip>>;
293
+ }, z.core.$strip>, z.ZodObject<{
294
+ app: z.ZodString;
295
+ reason: z.ZodString;
296
+ }, z.core.$strip>, z.ZodObject<{
297
+ server: z.ZodObject<{
298
+ name: z.ZodString;
299
+ url: z.ZodString;
300
+ auth: z.ZodOptional<z.ZodEnum<{
301
+ key: "key";
302
+ none: "none";
303
+ "sign-in": "sign-in";
304
+ }>>;
305
+ keyHeader: z.ZodOptional<z.ZodString>;
306
+ scope: z.ZodOptional<z.ZodEnum<{
307
+ company: "company";
308
+ org: "org";
309
+ user: "user";
310
+ user_org: "user_org";
311
+ }>>;
312
+ }, z.core.$strip>;
313
+ reason: z.ZodString;
314
+ }, z.core.$strip>]>>;
172
315
  resolution: z.ZodOptional<z.ZodObject<{}, z.core.$catchall<z.ZodUnknown>>>;
173
316
  }>;
174
317
  export {};
@@ -1 +1 @@
1
- {"version":3,"file":"connection-input.d.ts","sourceRoot":"","sources":["../../src/hono/connection-input.ts"],"names":[],"mappings":"AAmBA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAGxB,eAAO,MAAM,0BAA0B,sCAAsC,CAAC;AAE9E;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,oBAAoB,YAC/B,YAAY,EACZ,UAAU,EACV,MAAM,EACN,kBAAkB,EAClB,uBAAuB,EACvB,oBAAoB,EACpB,OAAO,EACP,SAAS,EACT,cAAc,EACd,WAAW,EACX,WAAW,EACX,UAAU,EACV,UAAU,CACF,CAAC;AAEX,MAAM,MAAM,kBAAkB,GAAG,CAAC,OAAO,oBAAoB,CAAC,CAAC,MAAM,CAAC,CAAC;AAEvE,QAAA,MAAM,sBAAsB;;;;;;;;;;;;;;;;;;iBAW1B,CAAC;AAEH,eAAO,MAAM,wBAAwB;IACnC,WAAW;;;;;;;;;;;;;;;;;;;IAK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al),
8
8
  * where connecting is the whole answer — without the user leaving the chat.
9
+ * It also adds tools: a remote MCP server the user described (`{ server }`,
10
+ * filled in from their instructions) or, when the vendor has none, a managed
11
+ * app from the catalog (`{ app }`). Those load into the running query once the
12
+ * card resolves (`BridgeJobExecutor.reloadMcpServers`), so the agent can call
13
+ * them in the same turn.
9
14
  *
10
15
  * Nothing confidential passes through the model: the bridge parks the turn in
11
16
  * `canUseTool`, the dashboard runs the OAuth popup and writes the selection onto
@@ -18,6 +23,7 @@
18
23
  */
19
24
  import { tool } from "@anthropic-ai/claude-agent-sdk";
20
25
  import { z } from "zod";
26
+ import { answeredInTheCard } from "./blocking-card.js";
21
27
  import { toToolInputArray } from "./tool-input.js";
22
28
  export const CONNECTION_INPUT_TOOL_NAME = "mcp__baker_ui__request_connection";
23
29
  /**
@@ -46,8 +52,9 @@ export const CONNECTION_PLATFORMS = [
46
52
  "pipedrive",
47
53
  "calendly",
48
54
  "savvycal",
55
+ "chatgpt-ads",
49
56
  ];
50
- const connectionRequestShape = z.object({
57
+ const platformRequestShape = z.object({
51
58
  platform: z.enum(CONNECTION_PLATFORMS).describe("Which platform the user needs to connect"),
52
59
  reason: z
53
60
  .string()
@@ -57,12 +64,50 @@ const connectionRequestShape = z.object({
57
64
  .optional()
58
65
  .describe("Google Drive only: the user picks a folder whose images and videos Baker imports into the libraries (a media source). Set it whenever the user wants a Drive folder's photos or videos in Baker."),
59
66
  });
67
+ /** Who reaches a connected app or server — mirrors the custom-MCP scope model. */
68
+ const REACH = ["user", "user_org", "company", "org"];
69
+ const serverShape = z.object({
70
+ name: z
71
+ .string()
72
+ .min(1)
73
+ .describe("Short lowercase slug for the server, e.g. `acme` — its tools become mcp__<name>__*"),
74
+ url: z.string().min(1).describe("The FULL https endpoint, usually ending in /mcp — never just the domain"),
75
+ auth: z
76
+ .enum(["none", "key", "sign-in"])
77
+ .optional()
78
+ .describe("How it signs in, from the vendor's instructions: `none` (public), `key` (a required API key sent in a header — the user types it into the card, never into the chat; a key the docs call optional is `none`), `sign-in` (the server runs its own sign-in popup). Omit when unsure: the card tries a sign-in and falls back to nothing."),
79
+ keyHeader: z
80
+ .string()
81
+ .min(1)
82
+ .optional()
83
+ .describe("`key` only: the header the key goes in, e.g. `Authorization` or `X-API-Key`"),
84
+ scope: z
85
+ .enum(REACH)
86
+ .optional()
87
+ .describe("Who reaches it: `company` (everyone in this company — the default), `user` (only the person asking, here), `user_org` (only them, in every company of the organization), `org` (everyone in every company — admins only). The user can change it in the card."),
88
+ });
89
+ const appRequestShape = z.object({
90
+ app: z
91
+ .string()
92
+ .min(1)
93
+ .describe("A managed app's slug from `baker mcp catalog --search <name>` — the fallback when the vendor has no MCP server"),
94
+ reason: z
95
+ .string()
96
+ .describe("One short sentence, in the user's terms, saying what you'll be able to do once it's connected"),
97
+ });
98
+ const serverRequestShape = z.object({
99
+ server: serverShape,
100
+ reason: z
101
+ .string()
102
+ .describe("One short sentence, in the user's terms, saying what you'll be able to do once it's connected"),
103
+ });
104
+ const connectionRequestShape = z.union([platformRequestShape, appRequestShape, serverRequestShape]);
60
105
  export const connectionInputToolShape = {
61
106
  connections: z
62
107
  .array(connectionRequestShape)
63
108
  .min(1)
64
109
  .max(5)
65
- .describe("Platforms to ask for; each becomes a tab the user resolves in one form"),
110
+ .describe("Platforms, apps and servers to ask for; each becomes a tab the user resolves in one form"),
66
111
  resolution: z
67
112
  .object({})
68
113
  .catchall(z.unknown())
@@ -70,7 +115,7 @@ export const connectionInputToolShape = {
70
115
  .describe("Internal — injected by the bridge after the user resolves the form. Never set this yourself."),
71
116
  };
72
117
  // --- Redacted resolution echoed back to the model ---
73
- export const connectionInputResultSchema = z.discriminatedUnion("status", [
118
+ export const connectionInputResultSchema = z.union([
74
119
  z.object({
75
120
  status: z.literal("connected"),
76
121
  platform: z.enum(CONNECTION_PLATFORMS),
@@ -88,18 +133,84 @@ export const connectionInputResultSchema = z.discriminatedUnion("status", [
88
133
  platform: z.enum(CONNECTION_PLATFORMS),
89
134
  reason: z.string().optional(),
90
135
  }),
136
+ z.object({
137
+ status: z.literal("connected"),
138
+ app: z.string(),
139
+ scope: z.enum(REACH),
140
+ accountLabel: z.string().optional(),
141
+ readOnly: z.boolean().optional(),
142
+ }),
143
+ z.object({ status: z.literal("declined"), app: z.string(), reason: z.string().optional() }),
144
+ z.object({
145
+ status: z.literal("connected"),
146
+ server: z.string(),
147
+ scope: z.enum(REACH),
148
+ /** What a person has to fix before its tools answer — the address, the sign-in or the key. */
149
+ problem: z.string().optional(),
150
+ }),
151
+ z.object({ status: z.literal("declined"), server: z.string(), reason: z.string().optional() }),
91
152
  ]);
92
153
  export const connectionInputResolutionSchema = z.object({ results: z.array(connectionInputResultSchema) });
154
+ /**
155
+ * Whether the user connected something that brings MCP tools — an app or a
156
+ * server. Only then is the turn's server set reloaded: a platform is read with
157
+ * `baker` commands and adds no tool, and reloading for nothing would rewrite
158
+ * the tool list, and the prompt cache with it.
159
+ */
160
+ export function toolsConnected(resolution) {
161
+ return resolution.results.some((result) => result.status === "connected" && ("app" in result || "server" in result));
162
+ }
163
+ /**
164
+ * What the user connected that the reloaded server set does not carry, by the
165
+ * name the agent knows it by. An app arrives inside its scope's managed server
166
+ * (`composio_<scope>`), which is absent when the company has managed apps
167
+ * switched off or the session for them could not be made.
168
+ */
169
+ export function connectedButNotLoaded(resolution, loaded) {
170
+ return resolution.results.flatMap((result) => {
171
+ if (result.status !== "connected")
172
+ return [];
173
+ if ("app" in result)
174
+ return loaded.includes(`composio_${result.scope}`) ? [] : [result.app];
175
+ if ("server" in result)
176
+ return loaded.includes(result.server) ? [] : [result.server];
177
+ return [];
178
+ });
179
+ }
93
180
  /** Parse-at-boundary for the resolution posted to `POST /connection-input-decision`. */
94
181
  export function parseConnectionInputResolution(value) {
95
182
  const parsed = connectionInputResolutionSchema.safeParse(value);
96
183
  return parsed.success ? parsed.data : null;
97
184
  }
185
+ /** The tab's identity, for collapsing the same ask made twice. */
186
+ function requestKey(request) {
187
+ if ("app" in request)
188
+ return `app:${request.app}`;
189
+ if ("server" in request)
190
+ return `server:${request.server.name}`;
191
+ return `platform:${request.platform}`;
192
+ }
193
+ /** Drop what a request's own kind does not use, so the card never asks for it. */
194
+ function trimRequest(request) {
195
+ if ("server" in request) {
196
+ const { keyHeader, ...server } = request.server;
197
+ // A key header only means something on a server that signs in with a key.
198
+ const keepHeader = keyHeader && (server.auth === undefined || server.auth === "key");
199
+ return { ...request, server: keepHeader ? { ...server, keyHeader } : server };
200
+ }
201
+ if ("app" in request)
202
+ return request;
203
+ // Choosing a folder is a Google Drive thing; on any other platform it would
204
+ // ask the dashboard for a picker that does not exist.
205
+ const { choose, ...platform } = request;
206
+ return choose && platform.platform === "google-drive" ? { ...platform, choose } : platform;
207
+ }
98
208
  /**
99
209
  * `canUseTool` sees the RAW model input — MCP validation hasn't run yet — so the
100
210
  * requests are normalized here before anything downstream trusts them. Unknown
101
211
  * platforms (TikTok Ads, a hallucinated id) are dropped rather than shown as a
102
- * dead tab.
212
+ * dead tab. The dashboard applies the same rules (`connectionRequestsFromToolInput`)
213
+ * because it resolves tabs by index into this list.
103
214
  */
104
215
  export function normalizeConnectionInputToolInput(input) {
105
216
  if (typeof input !== "object" || input === null) {
@@ -110,28 +221,33 @@ export function normalizeConnectionInputToolInput(input) {
110
221
  const requests = [];
111
222
  for (const entry of raw) {
112
223
  const parsed = connectionRequestShape.safeParse(entry);
113
- if (!parsed.success || seen.has(parsed.data.platform)) {
224
+ if (!parsed.success) {
225
+ continue;
226
+ }
227
+ const key = requestKey(parsed.data);
228
+ if (seen.has(key)) {
114
229
  continue;
115
230
  }
116
- seen.add(parsed.data.platform);
117
- // Choosing a folder is a Google Drive thing; on any other platform it would
118
- // ask the dashboard for a picker that does not exist.
119
- const { choose, ...request } = parsed.data;
120
- requests.push(choose && request.platform === "google-drive" ? { ...request, choose } : request);
231
+ seen.add(key);
232
+ requests.push(trimRequest(parsed.data));
121
233
  }
122
234
  return requests;
123
235
  }
124
236
  const CONNECTION_INPUT_TOOL_DESCRIPTION = [
125
- "Ask the user to connect — or reconnect — one of Baker's connections, inside the chat: an ad or data platform (Google Ads, LinkedIn Ads, Meta Ads, X Ads, Google Analytics 4, Google Search Console, Google Tag Manager), where they also pick which accounts Baker may read, or a tool (HubSpot, Google Drive, GoHighLevel, Pipedrive, Calendly, SavvyCal). BLOCKS until they resolve it in the dashboard.",
126
- "Use it the moment a command tells you a platform isn't connected, OR that it is connected but does not allow what you asked (a `request_connection` fix, `HUBSPOT_RECONNECT_REQUIRED`, a read-only connection) — the card shows Reconnect when the connection exists. Never tell the user to go to Settings instead. Each entry in `connections` becomes a tab, so ask for everything the task needs in ONE call.",
237
+ "Ask the user to connect — or reconnect — something inside the chat. BLOCKS until they resolve it in the dashboard. Three kinds of entry, mixed freely in one call:",
238
+ "(1) `{ platform }` — one of Baker's connections: an ad or data platform (Google Ads, LinkedIn Ads, Meta Ads, X Ads, Google Analytics 4, Google Search Console, Google Tag Manager), where they also pick which accounts Baker may read; ChatGPT Ads (`chatgpt-ads`), where they paste its API key into the card; or a tool (HubSpot, Google Drive, GoHighLevel, Pipedrive, Calendly, SavvyCal). ALWAYS first for these: Baker's own connection wins even when the vendor publishes an MCP server or the user names one — never ask for one of them as (2) or (3).",
239
+ "(2) `{ server: { name, url, auth, keyHeader, scope } }` — a remote MCP server. Use it whenever the user gives you an MCP server's address or setup instructions, or asks for any tool that is not connected: always try the vendor's real server FIRST. No address given? Find it yourself before asking the user anything — WebSearch '<vendor> MCP server', WebFetch the vendor's own docs, and take the official remote https endpoint and how it signs in from there. Official = on the vendor's own domain or in the vendor's own docs; never a server someone else hosts (a GitHub project, a directory listing) unless the user named it — with no official one, use (3). Fill in everything you know from their instructions — the card opens with it filled in and the user only confirms, types a key if there is one, or signs in. Never ask for a key in the chat.",
240
+ "(3) `{ app }` — the FALLBACK when the vendor has no MCP server: a managed app from `baker mcp catalog --search <name>`, which the user signs in to from the card.",
241
+ "Use it the moment a command tells you a platform isn't connected, OR that it is connected but does not allow what you asked (a `request_connection` fix, `HUBSPOT_RECONNECT_REQUIRED`, a read-only connection) — the card shows Reconnect when the connection exists. Never tell the user to go to Settings or the Integrations page instead. Each entry becomes a tab, so ask for everything the task needs in ONE call.",
127
242
  "`reason` is shown to the user: say what connecting unlocks in their terms ('so I can see which campaigns are actually converting', 'so I can count a contact becoming a customer'), never in technical terms.",
128
243
  'When the user wants a Google Drive folder\'s photos or videos in Baker, ask for `google-drive` with `choose: "media-folder"`: the card lets them pick the folder, Baker imports it as a media source (weekly by default), and the result carries its `mediaSourceKey` for `baker media-sources`. The import runs in the background — tell the user the library is filling, never that it is ready. A Drive folder is never added by link.',
129
- "A declined tab is not an error — carry on with what you can do without it and say what stays unavailable. A connected result may list `cannotRead`: things the connection still does not allow — do not promise those. Results name only the account and what was selected; no credentials ever reach you.",
244
+ "A connected app or server's tools load straight after the card resolves, in this same turn, when the result says `toolsReady: true` — call them right away (a server's tools are mcp__<name>__*, an app's ride mcp__composio_*). A server result with `problem` will not answer until a person fixes what it names; relay it plainly. `toolsReady: false` means they arrive with the user's next message — unless the app or server is named in `failedToLoad`: it did not load, so say plainly it isn't working yet and never promise it for later.",
245
+ "A declined tab is not an error — carry on with what you can do without it and say what stays unavailable. A declined key server: the key goes into the card, never the chat — offer to open the card again. A connected result may list `cannotRead`: things the connection still does not allow — do not promise those. Results name only the account and what was selected; no credentials ever reach you.",
130
246
  ].join(" ");
131
247
  export function createConnectionInputTool() {
132
- return tool("request_connection", CONNECTION_INPUT_TOOL_DESCRIPTION, connectionInputToolShape, (args) => {
248
+ return answeredInTheCard(tool("request_connection", CONNECTION_INPUT_TOOL_DESCRIPTION, connectionInputToolShape, (args) => {
133
249
  const resolution = args.resolution ?? { results: [] };
134
250
  return Promise.resolve({ content: [{ type: "text", text: JSON.stringify(resolution) }] });
135
- });
251
+ }));
136
252
  }
137
253
  //# sourceMappingURL=connection-input.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"connection-input.js","sourceRoot":"","sources":["../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G,GAAG,UAAU,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;QACpC,IAAI,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC;YAClB,SAAS;QACX,CAAC;QACD,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QACd,QAAQ,CAAC,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC;IAC1C,CAAC;IACD,OAAO,QAAQ,CAAC;AAClB,CAAC;AAED,MAAM,iCAAiC,GAAG;IACxC,oKAAoK;IACpK,miBAAmiB;IACniB,g1BAAg1B;IACh1B,mKAAmK;IACnK,2ZAA2Z;IAC3Z,+MAA+M;IAC/M,2aAA2a;IAC3a,shBAAshB;IACthB,8YAA8Y;CAC/Y,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAEZ,MAAM,UAAU,yBAAyB;IACvC,OAAO,iBAAiB,CACtB,IAAI,CACF,oBAAoB,EACpB,iCAAiC,EACjC,wBAAwB,EACxB,CAAC,IAAI,EAA+D,EAAE;QACpE,MAAM,UAAU,GAAG,IAAI,CAAC,UAAU,IAAK,EAAE,OAAO,EAAE,EAAE,EAAuC,CAAC;QAC5F,OAAO,OAAO,CAAC,OAAO,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC;IAC5F,CAAC,CACF,CACF,CAAC;AACJ,CAAC"}
@@ -1,6 +1,6 @@
1
1
  import { readFile } from "node:fs/promises";
2
2
  import { describe, expect, it } from "vitest";
3
- import { CONNECTION_PLATFORMS, normalizeConnectionInputToolInput, parseConnectionInputResolution, } from "./connection-input.js";
3
+ import { CONNECTION_PLATFORMS, normalizeConnectionInputToolInput, parseConnectionInputResolution, toolsConnected, } from "./connection-input.js";
4
4
  describe("normalizeConnectionInputToolInput", () => {
5
5
  it("keeps well-formed requests in the order the agent asked for them", () => {
6
6
  expect(normalizeConnectionInputToolInput({
@@ -22,6 +22,11 @@ describe("normalizeConnectionInputToolInput", () => {
22
22
  ],
23
23
  })).toEqual([{ platform: "linkedin", reason: "so I can read your LinkedIn campaigns" }]);
24
24
  });
25
+ it("keeps ChatGPT Ads, which the user connects by pasting its key into the card", () => {
26
+ expect(normalizeConnectionInputToolInput({
27
+ connections: [{ platform: "chatgpt-ads", reason: "so I can read your ads" }],
28
+ })).toEqual([{ platform: "chatgpt-ads", reason: "so I can read your ads" }]);
29
+ });
25
30
  it("collapses a platform the agent asked for twice into one tab", () => {
26
31
  const requests = normalizeConnectionInputToolInput({
27
32
  connections: [
@@ -54,6 +59,66 @@ describe("normalizeConnectionInputToolInput", () => {
54
59
  expect(normalizeConnectionInputToolInput(null)).toEqual([]);
55
60
  });
56
61
  });
62
+ describe("normalizeConnectionInputToolInput — apps and servers", () => {
63
+ it("keeps a server the user described, filled in as far as the agent knows it", () => {
64
+ expect(normalizeConnectionInputToolInput({
65
+ connections: [
66
+ {
67
+ server: { name: "acme", url: "https://acme.dev/mcp", auth: "key", keyHeader: "X-Api-Key", scope: "user" },
68
+ reason: "so I can read your Acme orders",
69
+ },
70
+ ],
71
+ })).toEqual([
72
+ {
73
+ server: { name: "acme", url: "https://acme.dev/mcp", auth: "key", keyHeader: "X-Api-Key", scope: "user" },
74
+ reason: "so I can read your Acme orders",
75
+ },
76
+ ]);
77
+ });
78
+ it("keeps an app from the catalog next to a platform", () => {
79
+ expect(normalizeConnectionInputToolInput({
80
+ connections: [
81
+ { app: "notion", reason: "so I can read your briefs" },
82
+ { platform: "hubspot", reason: "so I can count a deal won" },
83
+ ],
84
+ })).toEqual([
85
+ { app: "notion", reason: "so I can read your briefs" },
86
+ { platform: "hubspot", reason: "so I can count a deal won" },
87
+ ]);
88
+ });
89
+ it("drops a key header on a server that signs in without one, so the card never asks for a key it will not use", () => {
90
+ expect(normalizeConnectionInputToolInput({
91
+ connections: [
92
+ { server: { name: "acme", url: "https://acme.dev/mcp", auth: "none", keyHeader: "X" }, reason: "r" },
93
+ ],
94
+ })).toEqual([{ server: { name: "acme", url: "https://acme.dev/mcp", auth: "none" }, reason: "r" }]);
95
+ });
96
+ it("collapses the same app or server asked for twice into one tab", () => {
97
+ const requests = normalizeConnectionInputToolInput({
98
+ connections: [
99
+ { app: "notion", reason: "first" },
100
+ { app: "notion", reason: "second" },
101
+ { server: { name: "acme", url: "https://acme.dev/mcp" }, reason: "first" },
102
+ { server: { name: "acme", url: "https://acme.dev/mcp" }, reason: "second" },
103
+ ],
104
+ });
105
+ expect(requests.map((request) => request.reason)).toEqual(["first", "first"]);
106
+ });
107
+ });
108
+ describe("toolsConnected", () => {
109
+ it("is true when an app or a server came through, which is when the turn's tools must be reloaded", () => {
110
+ expect(toolsConnected({ results: [{ status: "connected", server: "acme", scope: "company" }] })).toBe(true);
111
+ expect(toolsConnected({ results: [{ status: "connected", app: "notion", scope: "user" }] })).toBe(true);
112
+ });
113
+ it("is false for a platform or a skipped tab, so the tool list — and the prompt cache — stay untouched", () => {
114
+ expect(toolsConnected({
115
+ results: [
116
+ { status: "connected", platform: "hubspot", selected: [] },
117
+ { status: "declined", server: "acme" },
118
+ ],
119
+ })).toBe(false);
120
+ });
121
+ });
57
122
  describe("parseConnectionInputResolution", () => {
58
123
  it("accepts a connected result carrying only the account and what was selected", () => {
59
124
  expect(parseConnectionInputResolution({
@@ -85,15 +150,19 @@ describe("parseConnectionInputResolution", () => {
85
150
  describe("CONNECTION_PLATFORMS", () => {
86
151
  it("matches the platforms the backend will accept — every connection Baker has", async () => {
87
152
  // Three lists gate one door — this schema, the backend's
88
- // `connectionPlatformValidator` (every `OAUTH_PROVIDER_TYPES` entry), and
89
- // the dashboard's `comingSoon`. Meta was live in the backend for months
90
- // while this list still refused it, so the agent could not ask for the one
91
- // platform it could already read.
153
+ // `CONNECTION_PLATFORMS` (every `OAUTH_PROVIDER_TYPES` entry plus the
154
+ // key-pasted ChatGPT Ads), and the dashboard's `comingSoon`. Meta was live
155
+ // in the backend for months while this list still refused it, so the agent
156
+ // could not ask for the one platform it could already read.
92
157
  const validators = await readFile(new URL("../../../backend/convex/lib/validators.ts", import.meta.url), "utf8");
93
- expect(validators).toMatch(/export const connectionPlatformValidator = oauthProviderTypeValidator;/);
94
- const block = validators.match(/export const OAUTH_PROVIDER_TYPES = \[([\s\S]*?)\] as const;/);
95
- expect(block).not.toBeNull();
96
- const backendPlatforms = [...block[1].matchAll(/"([^"]+)"/g)].map((m) => m[1]);
158
+ const quoted = (block) => {
159
+ expect(block).not.toBeNull();
160
+ return [...block[1].matchAll(/"([^"]+)"/g)].map((m) => m[1]);
161
+ };
162
+ const backendPlatforms = [
163
+ ...quoted(validators.match(/export const OAUTH_PROVIDER_TYPES = \[([\s\S]*?)\] as const;/)),
164
+ ...quoted(validators.match(/export const CONNECTION_PLATFORMS = \[\.\.\.OAUTH_PROVIDER_TYPES,([\s\S]*?)\] as const;/)),
165
+ ];
97
166
  expect([...CONNECTION_PLATFORMS].sort()).toEqual(backendPlatforms.sort());
98
167
  });
99
168
  it("offers HubSpot and the other tools, so the agent never sends the user to Settings for one", () => {