@bakers-build/addon-dropsh 0.6.1-next.5 → 0.6.1-next.6

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.
@@ -5,6 +5,8 @@ export interface DropshDispatchOptions extends WorkspaceRecoveryOptions {
5
5
  stdout?: (text: string) => void;
6
6
  stderr?: (text: string) => void;
7
7
  }
8
+ /** A site tool's name for the route: plain on the run's conductor, `tool_api__` on the site. */
9
+ export declare function toolNameFor(name: string, inRun: boolean): string;
8
10
  /** Build the actual plugin registrations after the final connection is ready. */
9
11
  export declare function dispatchBbDropsh(host: BbCommandHost, argv: string[], options?: DropshDispatchOptions): Promise<void>;
10
12
  declare const dropshCommandPlugin: BbCommandPlugin;
package/dist/src/index.js CHANGED
@@ -68,9 +68,28 @@ function invocation(argv) {
68
68
  ].includes(forwarded[i - 1] ?? ''));
69
69
  return { forwarded, explicit, connection, format, yes, profile, positional };
70
70
  }
71
+ const SITE_TOOL = 'tool_api__';
72
+ /** A site tool's name for the route: plain on the run's conductor, `tool_api__` on the site. */
73
+ export function toolNameFor(name, inRun) {
74
+ if (inRun)
75
+ return name.startsWith(SITE_TOOL) ? name.slice(SITE_TOOL.length) : name;
76
+ return name.startsWith('bakers_') ? `${SITE_TOOL}${name}` : name;
77
+ }
71
78
  /** Build the actual plugin registrations after the final connection is ready. */
72
79
  export async function dispatchBbDropsh(host, argv, options = {}) {
73
80
  const args = invocation(argv);
81
+ // Inside a conductor run, tools go to the run's own `bakers` server with the
82
+ // run token, never to the site with the operator's credentials.
83
+ const runUrl = process.env.BB_CONDUCTOR_URL;
84
+ const runToken = process.env.BB_CONDUCTOR_TOKEN;
85
+ const run = args.positional[0] === 'tool' && runUrl && runToken
86
+ ? { url: runUrl, token: runToken }
87
+ : undefined;
88
+ const name = args.positional[0] === 'tool' ? args.positional[1] : undefined;
89
+ if (name !== undefined) {
90
+ const at = args.forwarded.indexOf(name);
91
+ args.forwarded[at] = toolNameFor(name, run !== undefined);
92
+ }
74
93
  const opts = {
75
94
  ...options,
76
95
  ...(args.explicit ? { explicit: args.explicit } : {}),
@@ -94,7 +113,7 @@ export async function dispatchBbDropsh(host, argv, options = {}) {
94
113
  stdout(`${JSON.stringify(rows, null, 2)}\n`);
95
114
  return;
96
115
  }
97
- const connection = help
116
+ const connection = help || run
98
117
  ? undefined
99
118
  : auth
100
119
  ? await loadBbConnectionBootstrap(host, opts)
@@ -102,11 +121,30 @@ export async function dispatchBbDropsh(host, argv, options = {}) {
102
121
  const plugins = connection?.plugins ?? [];
103
122
  const program = buildDropshProgram({
104
123
  // `dropsh tool` (MCP, default endpoint /mcp) rides the same connection and auth profile.
105
- plugins: plugins.some((plugin) => plugin.id === 'tool')
106
- ? plugins
107
- : [...plugins, toolPlugin()],
124
+ plugins: run
125
+ ? [toolPlugin({ endpoint: '/' })]
126
+ : plugins.some((plugin) => plugin.id === 'tool')
127
+ ? plugins
128
+ : [...plugins, toolPlugin()],
108
129
  ...(options.stdout ? { stdout: options.stdout } : {}),
109
130
  ...(options.stderr ? { stderr: options.stderr } : {}),
131
+ ...(run
132
+ ? {
133
+ // The tool command reads only `auth` and `baseUrl` from its context.
134
+ contextFactory: async () => ({
135
+ baseUrl: run.url,
136
+ auth: {
137
+ apply: async (request) => ({
138
+ ...request,
139
+ headers: {
140
+ ...request.headers,
141
+ authorization: `Bearer ${run.token}`,
142
+ },
143
+ }),
144
+ },
145
+ }),
146
+ }
147
+ : {}),
110
148
  ...(connection
111
149
  ? {
112
150
  contextFactory: () => createBbConnectionContext(connection, {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bakers-build/addon-dropsh",
3
- "version": "0.6.1-next.5",
3
+ "version": "0.6.1-next.6",
4
4
  "description": "bakers.build tools and auth command plugins using the shared connection config.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -27,10 +27,10 @@
27
27
  "dropsh": "^0.8.2"
28
28
  },
29
29
  "peerDependencies": {
30
- "@bakers-build/core": "^0.6.1-next.5"
30
+ "@bakers-build/core": "^0.6.1-next.6"
31
31
  },
32
32
  "bakersBuild": {
33
- "commit": "314f28982940df736bea55293a81435d37864b31",
33
+ "commit": "12b97ff4aa2422d69dab286141f3234609f32351",
34
34
  "channel": "next"
35
35
  }
36
36
  }