@dereekb/firebase-server 13.13.0 → 13.14.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.
@@ -1,4 +1,4 @@
1
- import { type AuthRole, type Maybe } from '@dereekb/util';
1
+ import { type AuthRole, type Maybe, type PromiseOrValue } from '@dereekb/util';
2
2
  import { type OnCallFunctionType, type OnCallTypedModelParams, type FirestoreModelType, type ModelFirebaseCrudFunctionSpecifier } from '@dereekb/firebase';
3
3
  import { type FirebaseServerAuthData } from '../controller/auth.context.server';
4
4
  import { type OnCallModelFunctionAnalyticsDetails } from './analytics.details';
@@ -132,43 +132,40 @@ export interface McpToolDetailsBuilderResult {
132
132
  */
133
133
  export type McpToolDetailsBuilder = (input: McpToolDetailsBuilderInput) => McpToolDetailsBuilderResult;
134
134
  /**
135
- * MCP-specific customization for a model function.
136
- *
137
- * When omitted, defaults are auto-generated from the handler's position in the call model tree.
135
+ * Context object passed as the second argument to the {@link OnCallModelFunctionMcpDetails}
136
+ * response tiers (`summarizeResponse` / `formatResponse`).
138
137
  *
139
- * Response formatting uses a tiered system:
140
- * - **Tier 1 (default)**: Auto-generated summary from the result shape. No config needed.
141
- * - **Tier 2**: Provide {@link summarizeResponse} to return a natural language string. The framework wraps it into MCP content + structuredContent automatically.
142
- * - **Tier 3**: Provide {@link formatResponse} for complete control over the MCP response content blocks.
138
+ * Exposes both the raw, pre-mapped handler result and the effective value the tiers operate on,
139
+ * plus the dispatched params — so a formatter can reach the original data even when a
140
+ * `mapSuccessfulResult` mapper has already trimmed/enriched it.
143
141
  *
144
- * Resolution order: formatResponse > summarizeResponse > auto-generated default.
142
+ * @typeParam R - The raw handler return type.
143
+ * @typeParam V - The effective value type (the mapper's output, or `R` when no mapper is defined).
145
144
  */
146
- export interface OnCallModelFunctionMcpDetails {
145
+ export interface McpToolResponseContext<R = unknown, V = R> {
147
146
  /**
148
- * Custom tool name override.
147
+ * The raw, pre-mapped handler result.
149
148
  */
150
- readonly name?: string;
149
+ readonly raw: R;
151
150
  /**
152
- * Tier 2 response formatter: returns a natural language summary string.
153
- *
154
- * The framework wraps the string into a text content block and attaches the raw result
155
- * as structuredContent automatically.
156
- *
157
- * @param result - The handler's return value.
158
- * @param params - The OnCallTypedModelParams that were dispatched.
159
- * @returns A human-readable summary of the operation result.
151
+ * The effective value: the `mapSuccessfulResult` output when a mapper is defined, otherwise the
152
+ * raw result. Always identical to the tier callback's first argument.
160
153
  */
161
- readonly summarizeResponse?: (result: unknown, params: OnCallTypedModelParams) => McpToolResponseSummary;
154
+ readonly value: V;
162
155
  /**
163
- * Tier 3 response formatter: complete control over the MCP tool response.
164
- *
165
- * When provided, takes precedence over {@link summarizeResponse} and the auto-generated default.
166
- *
167
- * @param result - The handler's return value.
168
- * @param params - The OnCallTypedModelParams that were dispatched.
169
- * @returns The full MCP tool response content.
156
+ * The OnCallTypedModelParams that were dispatched.
170
157
  */
171
- readonly formatResponse?: (result: unknown, params: OnCallTypedModelParams) => McpToolResponseContent;
158
+ readonly params: OnCallTypedModelParams;
159
+ }
160
+ /**
161
+ * Fields shared by both {@link OnCallModelFunctionMcpDetails} variants — everything that does not
162
+ * depend on the handler's result type.
163
+ */
164
+ export interface OnCallModelFunctionMcpDetailsCommon {
165
+ /**
166
+ * Custom tool name override.
167
+ */
168
+ readonly name?: string;
172
169
  /**
173
170
  * Controls whether this handler's tool is advertised on `tools/list` for a given request.
174
171
  *
@@ -193,13 +190,101 @@ export interface OnCallModelFunctionMcpDetails {
193
190
  */
194
191
  readonly toolDetails?: McpToolDetailsBuilder;
195
192
  }
193
+ /**
194
+ * MCP-details variant for handlers that do NOT remap their success result. The response tiers see
195
+ * the raw handler result `R` directly.
196
+ *
197
+ * @typeParam R - The raw handler return type.
198
+ */
199
+ export interface BaseOnCallModelFunctionMcpDetails<R = unknown> extends OnCallModelFunctionMcpDetailsCommon {
200
+ /**
201
+ * Discriminant — absent on this variant. Keeps the {@link OnCallModelFunctionMcpDetails} union exclusive.
202
+ */
203
+ readonly mapSuccessfulResult?: never;
204
+ /**
205
+ * Tier 2 response formatter: returns a natural language summary string. The framework wraps the
206
+ * string into a text content block and exposes the result as `structuredContent` automatically.
207
+ *
208
+ * @param value - The handler's result (no mapper is defined on this variant, so this is the raw result).
209
+ * @param context - The {@link McpToolResponseContext} carrying the raw result + params.
210
+ * @returns A human-readable summary of the operation result.
211
+ */
212
+ readonly summarizeResponse?: (value: R, context: McpToolResponseContext<R, R>) => McpToolResponseSummary;
213
+ /**
214
+ * Tier 3 response formatter: complete control over the MCP tool response. Takes precedence over
215
+ * {@link summarizeResponse} and the auto-generated default.
216
+ *
217
+ * @param value - The handler's result (no mapper is defined on this variant, so this is the raw result).
218
+ * @param context - The {@link McpToolResponseContext} carrying the raw result + params.
219
+ * @returns The full MCP tool response content.
220
+ */
221
+ readonly formatResponse?: (value: R, context: McpToolResponseContext<R, R>) => McpToolResponseContent;
222
+ }
223
+ /**
224
+ * MCP-details variant for handlers that remap their success result before it is exposed via MCP.
225
+ *
226
+ * `mapSuccessfulResult` runs first (success path only, async-capable); the response tiers and the
227
+ * default Tier-1 path then operate on the mapped value `M`. `context.raw` still exposes the
228
+ * original `R`. Declare the mapped type in the model's `.api.ts` and tag the CRUD leaf with
229
+ * `@dbxModelApiMcpResult <TypeName>` so the generated MCP manifest output schema matches.
230
+ *
231
+ * @typeParam R - The raw handler return type.
232
+ * @typeParam M - The mapped result type exposed via MCP.
233
+ */
234
+ export interface OnCallModelFunctionMcpDetailsWithMappedResult<R = unknown, M = unknown> extends OnCallModelFunctionMcpDetailsCommon {
235
+ /**
236
+ * Maps the handler's raw success result to the shape exposed via MCP. Async-capable. Runs before
237
+ * `summarizeResponse` / `formatResponse` / the default path, and only on success (errors are
238
+ * formatted separately).
239
+ *
240
+ * @param result - The handler's raw return value.
241
+ * @param params - The OnCallTypedModelParams that were dispatched.
242
+ * @returns The mapped value (or a promise of it).
243
+ */
244
+ readonly mapSuccessfulResult: (result: R, params: OnCallTypedModelParams) => PromiseOrValue<M>;
245
+ /**
246
+ * Tier 2 response formatter: returns a natural language summary string. The framework wraps the
247
+ * string into a text content block and exposes the mapped value as `structuredContent` automatically.
248
+ *
249
+ * @param value - The mapped result (the `mapSuccessfulResult` output).
250
+ * @param context - The {@link McpToolResponseContext} carrying both the raw + mapped values and params.
251
+ * @returns A human-readable summary of the operation result.
252
+ */
253
+ readonly summarizeResponse?: (value: M, context: McpToolResponseContext<R, M>) => McpToolResponseSummary;
254
+ /**
255
+ * Tier 3 response formatter: complete control over the MCP tool response. Takes precedence over
256
+ * {@link summarizeResponse} and the auto-generated default.
257
+ *
258
+ * @param value - The mapped result (the `mapSuccessfulResult` output).
259
+ * @param context - The {@link McpToolResponseContext} carrying both the raw + mapped values and params.
260
+ * @returns The full MCP tool response content.
261
+ */
262
+ readonly formatResponse?: (value: M, context: McpToolResponseContext<R, M>) => McpToolResponseContent;
263
+ }
264
+ /**
265
+ * MCP-specific customization for a model function.
266
+ *
267
+ * When omitted, defaults are auto-generated from the handler's position in the call model tree.
268
+ *
269
+ * Response formatting uses a tiered system, with an optional pre-map step:
270
+ * - **mapSuccessfulResult** (optional): remap the raw success result before the tiers run. See {@link OnCallModelFunctionMcpDetailsWithMappedResult}.
271
+ * - **Tier 1 (default)**: Auto-generated summary from the (possibly mapped) result shape. No config needed.
272
+ * - **Tier 2**: Provide `summarizeResponse` to return a natural language string. The framework wraps it into MCP content + structuredContent automatically.
273
+ * - **Tier 3**: Provide `formatResponse` for complete control over the MCP response content blocks.
274
+ *
275
+ * Resolution order: formatResponse > summarizeResponse > auto-generated default.
276
+ *
277
+ * @typeParam R - The raw handler return type.
278
+ * @typeParam M - The mapped result type exposed via MCP (when `mapSuccessfulResult` is used).
279
+ */
280
+ export type OnCallModelFunctionMcpDetails<R = unknown, M = unknown> = BaseOnCallModelFunctionMcpDetails<R> | OnCallModelFunctionMcpDetailsWithMappedResult<R, M>;
196
281
  /**
197
282
  * API details metadata for a single model call handler function.
198
283
  *
199
284
  * Carries schema info (input/output types) and MCP-specific customization.
200
285
  * Attached to handler functions via withApiDetails().
201
286
  */
202
- export interface OnCallModelFunctionApiDetails {
287
+ export interface OnCallModelFunctionApiDetails<R = unknown, M = unknown> {
203
288
  /**
204
289
  * The input parameter type. Must implement toJsonSchema() for MCP tool input schema generation.
205
290
  */
@@ -211,7 +296,7 @@ export interface OnCallModelFunctionApiDetails {
211
296
  /**
212
297
  * MCP-specific customization. Auto-generated if omitted.
213
298
  */
214
- readonly mcp?: OnCallModelFunctionMcpDetails;
299
+ readonly mcp?: OnCallModelFunctionMcpDetails<R, M>;
215
300
  /**
216
301
  * Analytics lifecycle configuration for this handler.
217
302
  * When provided, the dispatch chain will call lifecycle hooks around handler execution.
@@ -305,7 +390,7 @@ export declare function isActualSpecifier(details: OnCallModelTypeApiDetails): b
305
390
  *
306
391
  * Combines API metadata, auth configuration, and the handler function into a single config object.
307
392
  */
308
- export interface WithApiDetailsConfig<F extends (...args: any[]) => any> extends OnCallModelFunctionApiDetails {
393
+ export interface WithApiDetailsConfig<F extends (...args: any[]) => any> extends OnCallModelFunctionApiDetails<Awaited<ReturnType<F>>> {
309
394
  /**
310
395
  * When true, marks the handler as not requiring auth (equivalent to optionalAuthContext).
311
396
  * Sets `_requireAuth = false` on the function, allowing it to be called without auth data.
package/test/package.json CHANGED
@@ -1,16 +1,16 @@
1
1
  {
2
2
  "name": "@dereekb/firebase-server/test",
3
- "version": "13.13.0",
3
+ "version": "13.14.0",
4
4
  "peerDependencies": {
5
- "@dereekb/analytics": "13.13.0",
6
- "@dereekb/date": "13.13.0",
7
- "@dereekb/firebase": "13.13.0",
8
- "@dereekb/firebase-server": "13.13.0",
9
- "@dereekb/firebase-server/oidc": "13.13.0",
10
- "@dereekb/model": "13.13.0",
11
- "@dereekb/nestjs": "13.13.0",
12
- "@dereekb/rxjs": "13.13.0",
13
- "@dereekb/util": "13.13.0",
5
+ "@dereekb/analytics": "13.14.0",
6
+ "@dereekb/date": "13.14.0",
7
+ "@dereekb/firebase": "13.14.0",
8
+ "@dereekb/firebase-server": "13.14.0",
9
+ "@dereekb/firebase-server/oidc": "13.14.0",
10
+ "@dereekb/model": "13.14.0",
11
+ "@dereekb/nestjs": "13.14.0",
12
+ "@dereekb/rxjs": "13.14.0",
13
+ "@dereekb/util": "13.14.0",
14
14
  "@google-cloud/firestore": "^7.11.6",
15
15
  "@google-cloud/storage": "^7.19.0",
16
16
  "@nestjs/common": "^11.1.19",
@@ -23,7 +23,7 @@
23
23
  "supertest": "^7.2.2"
24
24
  },
25
25
  "devDependencies": {
26
- "@dereekb/nestjs": "13.13.0"
26
+ "@dereekb/nestjs": "13.14.0"
27
27
  },
28
28
  "exports": {
29
29
  "./package.json": "./package.json",
@@ -1,14 +1,14 @@
1
1
  {
2
2
  "name": "@dereekb/firebase-server/twilio",
3
- "version": "13.13.0",
3
+ "version": "13.14.0",
4
4
  "peerDependencies": {
5
- "@dereekb/date": "13.13.0",
6
- "@dereekb/firebase": "13.13.0",
7
- "@dereekb/firebase-server": "13.13.0",
8
- "@dereekb/model": "13.13.0",
9
- "@dereekb/nestjs": "13.13.0",
10
- "@dereekb/rxjs": "13.13.0",
11
- "@dereekb/util": "13.13.0"
5
+ "@dereekb/date": "13.14.0",
6
+ "@dereekb/firebase": "13.14.0",
7
+ "@dereekb/firebase-server": "13.14.0",
8
+ "@dereekb/model": "13.14.0",
9
+ "@dereekb/nestjs": "13.14.0",
10
+ "@dereekb/rxjs": "13.14.0",
11
+ "@dereekb/util": "13.14.0"
12
12
  },
13
13
  "exports": {
14
14
  "./package.json": "./package.json",
package/zoho/package.json CHANGED
@@ -1,15 +1,15 @@
1
1
  {
2
2
  "name": "@dereekb/firebase-server/zoho",
3
- "version": "13.13.0",
3
+ "version": "13.14.0",
4
4
  "peerDependencies": {
5
- "@dereekb/analytics": "13.13.0",
6
- "@dereekb/date": "13.13.0",
7
- "@dereekb/model": "13.13.0",
8
- "@dereekb/nestjs": "13.13.0",
9
- "@dereekb/rxjs": "13.13.0",
10
- "@dereekb/firebase": "13.13.0",
11
- "@dereekb/util": "13.13.0",
12
- "@dereekb/zoho": "13.13.0"
5
+ "@dereekb/analytics": "13.14.0",
6
+ "@dereekb/date": "13.14.0",
7
+ "@dereekb/model": "13.14.0",
8
+ "@dereekb/nestjs": "13.14.0",
9
+ "@dereekb/rxjs": "13.14.0",
10
+ "@dereekb/firebase": "13.14.0",
11
+ "@dereekb/util": "13.14.0",
12
+ "@dereekb/zoho": "13.14.0"
13
13
  },
14
14
  "exports": {
15
15
  "./package.json": "./package.json",