@dexto/core 1.9.3 → 1.9.4

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.
@@ -0,0 +1,286 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var model_request_diagnostics_exports = {};
20
+ __export(model_request_diagnostics_exports, {
21
+ createModelRequestDiagnostics: () => createModelRequestDiagnostics,
22
+ modelRequestDiagnosticAttributes: () => modelRequestDiagnosticAttributes
23
+ });
24
+ module.exports = __toCommonJS(model_request_diagnostics_exports);
25
+ function createModelRequestDiagnostics(input) {
26
+ const messageJson = measureMessagesJson(input.formattedMessages);
27
+ const toolJson = safeJsonUtf8Bytes(input.toolDefinitions);
28
+ const providerOptionsJson = safeJsonUtf8Bytes(input.providerOptions);
29
+ const reasoningJson = safeJsonUtf8Bytes(input.reasoning);
30
+ const media = summarizeModelMessageMedia(input.formattedMessages);
31
+ return {
32
+ ...media,
33
+ compacted: input.compacted,
34
+ estimatedInputTokens: input.estimatedInputTokens,
35
+ formattedMessageCount: input.formattedMessages.length,
36
+ formattedMessagesJsonBytes: messageJson.bytes,
37
+ maxFormattedMessageJsonBytes: messageJson.maxMessageBytes,
38
+ model: input.model,
39
+ preparedHistoryCount: input.preparedHistoryCount,
40
+ preparedHistoryFilteredCount: input.preparedHistoryStats.filteredCount,
41
+ preparedHistoryOriginalCount: input.preparedHistoryStats.originalCount,
42
+ preparedHistoryPrunedToolCount: input.preparedHistoryStats.prunedToolCount,
43
+ provider: input.provider,
44
+ providerOptionsJsonBytes: providerOptionsJson.bytes,
45
+ ...input.reasoning?.reasoningBudgetTokens === void 0 ? {} : { reasoningBudgetTokens: input.reasoning.reasoningBudgetTokens },
46
+ reasoningJsonBytes: reasoningJson.bytes,
47
+ ...input.reasoning?.reasoningVariant === void 0 ? {} : { reasoningVariant: input.reasoning.reasoningVariant },
48
+ serializationErrorCount: messageJson.errorCount + toolJson.errorCount + providerOptionsJson.errorCount + reasoningJson.errorCount,
49
+ streaming: input.streaming,
50
+ systemPromptBytes: utf8ByteLength(input.systemPrompt),
51
+ toolCount: Object.keys(input.toolDefinitions).length,
52
+ toolDefinitionsJsonBytes: toolJson.bytes
53
+ };
54
+ }
55
+ function modelRequestDiagnosticAttributes(diagnostics) {
56
+ return {
57
+ "context.estimated_input_tokens": diagnostics.estimatedInputTokens,
58
+ "llm.model": diagnostics.model,
59
+ "llm.provider": diagnostics.provider,
60
+ "model_request.binary_media_bytes": diagnostics.binaryMediaBytes,
61
+ "model_request.binary_media_part_count": diagnostics.binaryMediaPartCount,
62
+ "model_request.compacted": diagnostics.compacted,
63
+ "model_request.file_part_count": diagnostics.filePartCount,
64
+ "model_request.formatted_message_count": diagnostics.formattedMessageCount,
65
+ "model_request.formatted_messages_json_bytes": diagnostics.formattedMessagesJsonBytes,
66
+ "model_request.image_part_count": diagnostics.imagePartCount,
67
+ "model_request.inline_file_payload_chars": diagnostics.inlineFilePayloadChars,
68
+ "model_request.inline_file_payload_decoded_bytes": diagnostics.inlineFilePayloadDecodedBytes,
69
+ "model_request.inline_file_part_count": diagnostics.inlineFilePartCount,
70
+ "model_request.inline_image_payload_chars": diagnostics.inlineImagePayloadChars,
71
+ "model_request.inline_image_payload_decoded_bytes": diagnostics.inlineImagePayloadDecodedBytes,
72
+ "model_request.inline_image_part_count": diagnostics.inlineImagePartCount,
73
+ "model_request.max_formatted_message_json_bytes": diagnostics.maxFormattedMessageJsonBytes,
74
+ "model_request.max_inline_file_payload_chars": diagnostics.maxInlineFilePayloadChars,
75
+ "model_request.max_inline_image_payload_chars": diagnostics.maxInlineImagePayloadChars,
76
+ "model_request.prepared_history_count": diagnostics.preparedHistoryCount,
77
+ "model_request.prepared_history_filtered_count": diagnostics.preparedHistoryFilteredCount,
78
+ "model_request.prepared_history_original_count": diagnostics.preparedHistoryOriginalCount,
79
+ "model_request.prepared_history_pruned_tool_count": diagnostics.preparedHistoryPrunedToolCount,
80
+ "model_request.provider_options_json_bytes": diagnostics.providerOptionsJsonBytes,
81
+ ...diagnostics.reasoningBudgetTokens === void 0 ? {} : {
82
+ "model_request.reasoning_budget_tokens": diagnostics.reasoningBudgetTokens
83
+ },
84
+ "model_request.reasoning_json_bytes": diagnostics.reasoningJsonBytes,
85
+ ...diagnostics.reasoningVariant === void 0 ? {} : {
86
+ "model_request.reasoning_variant": diagnostics.reasoningVariant
87
+ },
88
+ "model_request.remote_media_part_count": diagnostics.remoteMediaPartCount,
89
+ "model_request.resource_media_part_count": diagnostics.resourceMediaPartCount,
90
+ "model_request.serialization_error_count": diagnostics.serializationErrorCount,
91
+ "model_request.streaming": diagnostics.streaming,
92
+ "model_request.system_prompt_bytes": diagnostics.systemPromptBytes,
93
+ "model_request.text_chars": diagnostics.textChars,
94
+ "model_request.text_part_count": diagnostics.textPartCount,
95
+ "model_request.tool_count": diagnostics.toolCount,
96
+ "model_request.tool_definitions_json_bytes": diagnostics.toolDefinitionsJsonBytes
97
+ };
98
+ }
99
+ function measureMessagesJson(messages) {
100
+ let bodyBytes = 0;
101
+ let errorCount = 0;
102
+ let maxMessageBytes = 0;
103
+ for (const message of messages) {
104
+ const measurement = safeJsonUtf8Bytes(message);
105
+ bodyBytes += measurement.bytes;
106
+ errorCount += measurement.errorCount;
107
+ maxMessageBytes = Math.max(maxMessageBytes, measurement.bytes);
108
+ }
109
+ return {
110
+ bytes: messages.length === 0 ? 2 : bodyBytes + messages.length + 1,
111
+ errorCount,
112
+ maxMessageBytes
113
+ };
114
+ }
115
+ function safeJsonUtf8Bytes(value) {
116
+ if (value === void 0) {
117
+ return { bytes: 0, errorCount: 0 };
118
+ }
119
+ try {
120
+ return {
121
+ bytes: utf8ByteLength(JSON.stringify(value, diagnosticJsonReplacer) ?? ""),
122
+ errorCount: 0
123
+ };
124
+ } catch {
125
+ return { bytes: 0, errorCount: 1 };
126
+ }
127
+ }
128
+ function diagnosticJsonReplacer(_key, value) {
129
+ if (value instanceof Uint8Array) {
130
+ return { diagnosticType: "Uint8Array", byteLength: value.byteLength };
131
+ }
132
+ if (value instanceof ArrayBuffer) {
133
+ return { diagnosticType: "ArrayBuffer", byteLength: value.byteLength };
134
+ }
135
+ return value;
136
+ }
137
+ function summarizeModelMessageMedia(messages) {
138
+ const summary = {
139
+ binaryMediaBytes: 0,
140
+ binaryMediaPartCount: 0,
141
+ filePartCount: 0,
142
+ imagePartCount: 0,
143
+ inlineFilePayloadChars: 0,
144
+ inlineFilePayloadDecodedBytes: 0,
145
+ inlineFilePartCount: 0,
146
+ inlineImagePayloadChars: 0,
147
+ inlineImagePayloadDecodedBytes: 0,
148
+ inlineImagePartCount: 0,
149
+ maxInlineFilePayloadChars: 0,
150
+ maxInlineImagePayloadChars: 0,
151
+ remoteMediaPartCount: 0,
152
+ resourceMediaPartCount: 0,
153
+ textChars: 0,
154
+ textPartCount: 0
155
+ };
156
+ for (const message of messages) {
157
+ summarizeContent(message.content, summary);
158
+ }
159
+ return summary;
160
+ }
161
+ function summarizeContent(content, summary) {
162
+ if (typeof content === "string") {
163
+ summary.textPartCount += 1;
164
+ summary.textChars += content.length;
165
+ return;
166
+ }
167
+ if (!Array.isArray(content)) {
168
+ return;
169
+ }
170
+ for (const part of content) {
171
+ if (!isRecord(part) || typeof part.type !== "string") {
172
+ continue;
173
+ }
174
+ switch (part.type) {
175
+ case "text":
176
+ case "reasoning":
177
+ summarizeTextLikePart(part, summary);
178
+ break;
179
+ case "image":
180
+ summary.imagePartCount += 1;
181
+ summarizeMediaPayload(part.image, "image", summary);
182
+ break;
183
+ case "file":
184
+ summary.filePartCount += 1;
185
+ summarizeMediaPayload(part.data, "file", summary);
186
+ break;
187
+ case "resource":
188
+ case "ui-resource":
189
+ summary.resourceMediaPartCount += 1;
190
+ break;
191
+ }
192
+ }
193
+ }
194
+ function summarizeTextLikePart(part, summary) {
195
+ if (typeof part.text !== "string") {
196
+ return;
197
+ }
198
+ summary.textPartCount += 1;
199
+ summary.textChars += part.text.length;
200
+ }
201
+ function summarizeMediaPayload(payload, kind, summary) {
202
+ if (payload instanceof URL || isRemoteUrlString(payload)) {
203
+ summary.remoteMediaPartCount += 1;
204
+ return;
205
+ }
206
+ if (typeof payload === "string") {
207
+ summarizeInlinePayload(payload, kind, summary);
208
+ return;
209
+ }
210
+ const binaryBytes = getBinaryByteLength(payload);
211
+ if (binaryBytes !== void 0) {
212
+ summary.binaryMediaPartCount += 1;
213
+ summary.binaryMediaBytes += binaryBytes;
214
+ }
215
+ }
216
+ function summarizeInlinePayload(payload, kind, summary) {
217
+ const payloadChars = extractInlinePayload(payload).length;
218
+ const decodedBytes = estimateBase64DecodedBytes(payload);
219
+ if (kind === "image") {
220
+ summary.inlineImagePartCount += 1;
221
+ summary.inlineImagePayloadChars += payloadChars;
222
+ summary.inlineImagePayloadDecodedBytes += decodedBytes;
223
+ summary.maxInlineImagePayloadChars = Math.max(
224
+ summary.maxInlineImagePayloadChars,
225
+ payloadChars
226
+ );
227
+ return;
228
+ }
229
+ summary.inlineFilePartCount += 1;
230
+ summary.inlineFilePayloadChars += payloadChars;
231
+ summary.inlineFilePayloadDecodedBytes += decodedBytes;
232
+ summary.maxInlineFilePayloadChars = Math.max(summary.maxInlineFilePayloadChars, payloadChars);
233
+ }
234
+ function extractInlinePayload(payload) {
235
+ const trimmed = payload.trim();
236
+ const dataUriMatch = /^data:[^,]*,(.*)$/is.exec(trimmed);
237
+ return (dataUriMatch?.[1] ?? trimmed).replace(/\s/g, "");
238
+ }
239
+ function estimateBase64DecodedBytes(payload) {
240
+ const normalized = extractInlinePayload(payload);
241
+ if (normalized.length === 0) {
242
+ return 0;
243
+ }
244
+ const padding = normalized.endsWith("==") ? 2 : normalized.endsWith("=") ? 1 : 0;
245
+ return Math.max(0, Math.floor(normalized.length * 3 / 4) - padding);
246
+ }
247
+ function getBinaryByteLength(value) {
248
+ if (value instanceof Uint8Array) {
249
+ return value.byteLength;
250
+ }
251
+ if (value instanceof ArrayBuffer) {
252
+ return value.byteLength;
253
+ }
254
+ return void 0;
255
+ }
256
+ function isRemoteUrlString(value) {
257
+ return typeof value === "string" && /^https?:\/\//i.test(value);
258
+ }
259
+ function isRecord(value) {
260
+ return typeof value === "object" && value !== null;
261
+ }
262
+ function utf8ByteLength(value) {
263
+ let bytes = 0;
264
+ for (let index = 0; index < value.length; index += 1) {
265
+ const codePoint = value.codePointAt(index);
266
+ if (codePoint === void 0) {
267
+ continue;
268
+ }
269
+ if (codePoint <= 127) {
270
+ bytes += 1;
271
+ } else if (codePoint <= 2047) {
272
+ bytes += 2;
273
+ } else if (codePoint <= 65535) {
274
+ bytes += 3;
275
+ } else {
276
+ bytes += 4;
277
+ index += 1;
278
+ }
279
+ }
280
+ return bytes;
281
+ }
282
+ // Annotate the CommonJS export names for ESM import in node:
283
+ 0 && (module.exports = {
284
+ createModelRequestDiagnostics,
285
+ modelRequestDiagnosticAttributes
286
+ });
@@ -0,0 +1,63 @@
1
+ import type { SharedV2ProviderOptions } from '@ai-sdk/provider';
2
+ import type { ModelMessage } from 'ai';
3
+ import type { ReasoningVariant } from '@dexto/llm';
4
+ import type { PreparedHistoryResult } from '../../context/manager.js';
5
+ import type { ToolSet } from '../../tools/types.js';
6
+ export type ModelRequestDiagnostics = {
7
+ readonly binaryMediaBytes: number;
8
+ readonly binaryMediaPartCount: number;
9
+ readonly compacted: boolean;
10
+ readonly estimatedInputTokens: number;
11
+ readonly filePartCount: number;
12
+ readonly formattedMessageCount: number;
13
+ readonly formattedMessagesJsonBytes: number;
14
+ readonly imagePartCount: number;
15
+ readonly inlineFilePayloadChars: number;
16
+ readonly inlineFilePayloadDecodedBytes: number;
17
+ readonly inlineFilePartCount: number;
18
+ readonly inlineImagePayloadChars: number;
19
+ readonly inlineImagePayloadDecodedBytes: number;
20
+ readonly inlineImagePartCount: number;
21
+ readonly maxFormattedMessageJsonBytes: number;
22
+ readonly maxInlineFilePayloadChars: number;
23
+ readonly maxInlineImagePayloadChars: number;
24
+ readonly model: string;
25
+ readonly preparedHistoryCount: number;
26
+ readonly preparedHistoryFilteredCount: number;
27
+ readonly preparedHistoryOriginalCount: number;
28
+ readonly preparedHistoryPrunedToolCount: number;
29
+ readonly provider: string;
30
+ readonly providerOptionsJsonBytes: number;
31
+ readonly reasoningBudgetTokens?: number;
32
+ readonly reasoningJsonBytes: number;
33
+ readonly reasoningVariant?: ReasoningVariant;
34
+ readonly remoteMediaPartCount: number;
35
+ readonly resourceMediaPartCount: number;
36
+ readonly serializationErrorCount: number;
37
+ readonly streaming: boolean;
38
+ readonly systemPromptBytes: number;
39
+ readonly textChars: number;
40
+ readonly textPartCount: number;
41
+ readonly toolCount: number;
42
+ readonly toolDefinitionsJsonBytes: number;
43
+ };
44
+ export type ModelRequestDiagnosticAttributes = Record<string, string | number | boolean>;
45
+ export declare function createModelRequestDiagnostics(input: {
46
+ compacted: boolean;
47
+ estimatedInputTokens: number;
48
+ formattedMessages: readonly ModelMessage[];
49
+ model: string;
50
+ preparedHistoryCount: number;
51
+ preparedHistoryStats: PreparedHistoryResult['stats'];
52
+ provider: string;
53
+ providerOptions: SharedV2ProviderOptions | undefined;
54
+ reasoning: {
55
+ reasoningVariant?: ReasoningVariant;
56
+ reasoningBudgetTokens?: number;
57
+ } | undefined;
58
+ streaming: boolean;
59
+ systemPrompt: string;
60
+ toolDefinitions: ToolSet;
61
+ }): ModelRequestDiagnostics;
62
+ export declare function modelRequestDiagnosticAttributes(diagnostics: ModelRequestDiagnostics): ModelRequestDiagnosticAttributes;
63
+ //# sourceMappingURL=model-request-diagnostics.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"model-request-diagnostics.d.ts","sourceRoot":"","sources":["../../../src/llm/executor/model-request-diagnostics.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,kBAAkB,CAAC;AAChE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,IAAI,CAAC;AACvC,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AACnD,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,0BAA0B,CAAC;AACtE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAEpD,MAAM,MAAM,uBAAuB,GAAG;IAClC,QAAQ,CAAC,gBAAgB,EAAE,MAAM,CAAC;IAClC,QAAQ,CAAC,oBAAoB,EAAE,MAAM,CAAC;IACtC,QAAQ,CAAC,SAAS,EAAE,OAAO,CAAC;IAC5B,QAAQ,CAAC,oBAAoB,EAAE,MAAM,CAAC;IACtC,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;IAC/B,QAAQ,CAAC,qBAAqB,EAAE,MAAM,CAAC;IACvC,QAAQ,CAAC,0BAA0B,EAAE,MAAM,CAAC;IAC5C,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAC;IAChC,QAAQ,CAAC,sBAAsB,EAAE,MAAM,CAAC;IACxC,QAAQ,CAAC,6BAA6B,EAAE,MAAM,CAAC;IAC/C,QAAQ,CAAC,mBAAmB,EAAE,MAAM,CAAC;IACrC,QAAQ,CAAC,uBAAuB,EAAE,MAAM,CAAC;IACzC,QAAQ,CAAC,8BAA8B,EAAE,MAAM,CAAC;IAChD,QAAQ,CAAC,oBAAoB,EAAE,MAAM,CAAC;IACtC,QAAQ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B,iBAAiB,EAAE,SAAS,YAAY,EAAE,CAAC;IAC3C,KAAK,EAAE,MAAM,CAAC;IACd,oBAAoB,EAAE,MAAM,CAAC;IAC7B,oBAAoB,EAAE,qBAAqB,CAAC,OAAO,CAAC,CAAC;IACrD,QAAQ,EAAE,MAAM,CAAC;IACjB,eAAe,EAAE,uBAAuB,GAAG,SAAS,CAAC;IACrD,SAAS,EACH;QACI,gBAAgB,CAAC,EAAE,gBAAgB,CAAC;QACpC,qBAAqB,CAAC,EAAE,MAAM,CAAC;KAClC,GACD,SAAS,CAAC;IAChB,SAAS,EAAE,OAAO,CAAC;IACnB,YAAY,EAAE,MAAM,CAAC;IACrB,eAAe,EAAE,OAAO,CAAC;CAC5B,GAAG,uBAAuB,CAsC1B;AAED,wBAAgB,gCAAgC,CAC5C,WAAW,EAAE,uBAAuB,GACrC,gCAAgC,CAkDlC"}
@@ -0,0 +1,262 @@
1
+ import "../../chunk-C6A6W6XS.js";
2
+ function createModelRequestDiagnostics(input) {
3
+ const messageJson = measureMessagesJson(input.formattedMessages);
4
+ const toolJson = safeJsonUtf8Bytes(input.toolDefinitions);
5
+ const providerOptionsJson = safeJsonUtf8Bytes(input.providerOptions);
6
+ const reasoningJson = safeJsonUtf8Bytes(input.reasoning);
7
+ const media = summarizeModelMessageMedia(input.formattedMessages);
8
+ return {
9
+ ...media,
10
+ compacted: input.compacted,
11
+ estimatedInputTokens: input.estimatedInputTokens,
12
+ formattedMessageCount: input.formattedMessages.length,
13
+ formattedMessagesJsonBytes: messageJson.bytes,
14
+ maxFormattedMessageJsonBytes: messageJson.maxMessageBytes,
15
+ model: input.model,
16
+ preparedHistoryCount: input.preparedHistoryCount,
17
+ preparedHistoryFilteredCount: input.preparedHistoryStats.filteredCount,
18
+ preparedHistoryOriginalCount: input.preparedHistoryStats.originalCount,
19
+ preparedHistoryPrunedToolCount: input.preparedHistoryStats.prunedToolCount,
20
+ provider: input.provider,
21
+ providerOptionsJsonBytes: providerOptionsJson.bytes,
22
+ ...input.reasoning?.reasoningBudgetTokens === void 0 ? {} : { reasoningBudgetTokens: input.reasoning.reasoningBudgetTokens },
23
+ reasoningJsonBytes: reasoningJson.bytes,
24
+ ...input.reasoning?.reasoningVariant === void 0 ? {} : { reasoningVariant: input.reasoning.reasoningVariant },
25
+ serializationErrorCount: messageJson.errorCount + toolJson.errorCount + providerOptionsJson.errorCount + reasoningJson.errorCount,
26
+ streaming: input.streaming,
27
+ systemPromptBytes: utf8ByteLength(input.systemPrompt),
28
+ toolCount: Object.keys(input.toolDefinitions).length,
29
+ toolDefinitionsJsonBytes: toolJson.bytes
30
+ };
31
+ }
32
+ function modelRequestDiagnosticAttributes(diagnostics) {
33
+ return {
34
+ "context.estimated_input_tokens": diagnostics.estimatedInputTokens,
35
+ "llm.model": diagnostics.model,
36
+ "llm.provider": diagnostics.provider,
37
+ "model_request.binary_media_bytes": diagnostics.binaryMediaBytes,
38
+ "model_request.binary_media_part_count": diagnostics.binaryMediaPartCount,
39
+ "model_request.compacted": diagnostics.compacted,
40
+ "model_request.file_part_count": diagnostics.filePartCount,
41
+ "model_request.formatted_message_count": diagnostics.formattedMessageCount,
42
+ "model_request.formatted_messages_json_bytes": diagnostics.formattedMessagesJsonBytes,
43
+ "model_request.image_part_count": diagnostics.imagePartCount,
44
+ "model_request.inline_file_payload_chars": diagnostics.inlineFilePayloadChars,
45
+ "model_request.inline_file_payload_decoded_bytes": diagnostics.inlineFilePayloadDecodedBytes,
46
+ "model_request.inline_file_part_count": diagnostics.inlineFilePartCount,
47
+ "model_request.inline_image_payload_chars": diagnostics.inlineImagePayloadChars,
48
+ "model_request.inline_image_payload_decoded_bytes": diagnostics.inlineImagePayloadDecodedBytes,
49
+ "model_request.inline_image_part_count": diagnostics.inlineImagePartCount,
50
+ "model_request.max_formatted_message_json_bytes": diagnostics.maxFormattedMessageJsonBytes,
51
+ "model_request.max_inline_file_payload_chars": diagnostics.maxInlineFilePayloadChars,
52
+ "model_request.max_inline_image_payload_chars": diagnostics.maxInlineImagePayloadChars,
53
+ "model_request.prepared_history_count": diagnostics.preparedHistoryCount,
54
+ "model_request.prepared_history_filtered_count": diagnostics.preparedHistoryFilteredCount,
55
+ "model_request.prepared_history_original_count": diagnostics.preparedHistoryOriginalCount,
56
+ "model_request.prepared_history_pruned_tool_count": diagnostics.preparedHistoryPrunedToolCount,
57
+ "model_request.provider_options_json_bytes": diagnostics.providerOptionsJsonBytes,
58
+ ...diagnostics.reasoningBudgetTokens === void 0 ? {} : {
59
+ "model_request.reasoning_budget_tokens": diagnostics.reasoningBudgetTokens
60
+ },
61
+ "model_request.reasoning_json_bytes": diagnostics.reasoningJsonBytes,
62
+ ...diagnostics.reasoningVariant === void 0 ? {} : {
63
+ "model_request.reasoning_variant": diagnostics.reasoningVariant
64
+ },
65
+ "model_request.remote_media_part_count": diagnostics.remoteMediaPartCount,
66
+ "model_request.resource_media_part_count": diagnostics.resourceMediaPartCount,
67
+ "model_request.serialization_error_count": diagnostics.serializationErrorCount,
68
+ "model_request.streaming": diagnostics.streaming,
69
+ "model_request.system_prompt_bytes": diagnostics.systemPromptBytes,
70
+ "model_request.text_chars": diagnostics.textChars,
71
+ "model_request.text_part_count": diagnostics.textPartCount,
72
+ "model_request.tool_count": diagnostics.toolCount,
73
+ "model_request.tool_definitions_json_bytes": diagnostics.toolDefinitionsJsonBytes
74
+ };
75
+ }
76
+ function measureMessagesJson(messages) {
77
+ let bodyBytes = 0;
78
+ let errorCount = 0;
79
+ let maxMessageBytes = 0;
80
+ for (const message of messages) {
81
+ const measurement = safeJsonUtf8Bytes(message);
82
+ bodyBytes += measurement.bytes;
83
+ errorCount += measurement.errorCount;
84
+ maxMessageBytes = Math.max(maxMessageBytes, measurement.bytes);
85
+ }
86
+ return {
87
+ bytes: messages.length === 0 ? 2 : bodyBytes + messages.length + 1,
88
+ errorCount,
89
+ maxMessageBytes
90
+ };
91
+ }
92
+ function safeJsonUtf8Bytes(value) {
93
+ if (value === void 0) {
94
+ return { bytes: 0, errorCount: 0 };
95
+ }
96
+ try {
97
+ return {
98
+ bytes: utf8ByteLength(JSON.stringify(value, diagnosticJsonReplacer) ?? ""),
99
+ errorCount: 0
100
+ };
101
+ } catch {
102
+ return { bytes: 0, errorCount: 1 };
103
+ }
104
+ }
105
+ function diagnosticJsonReplacer(_key, value) {
106
+ if (value instanceof Uint8Array) {
107
+ return { diagnosticType: "Uint8Array", byteLength: value.byteLength };
108
+ }
109
+ if (value instanceof ArrayBuffer) {
110
+ return { diagnosticType: "ArrayBuffer", byteLength: value.byteLength };
111
+ }
112
+ return value;
113
+ }
114
+ function summarizeModelMessageMedia(messages) {
115
+ const summary = {
116
+ binaryMediaBytes: 0,
117
+ binaryMediaPartCount: 0,
118
+ filePartCount: 0,
119
+ imagePartCount: 0,
120
+ inlineFilePayloadChars: 0,
121
+ inlineFilePayloadDecodedBytes: 0,
122
+ inlineFilePartCount: 0,
123
+ inlineImagePayloadChars: 0,
124
+ inlineImagePayloadDecodedBytes: 0,
125
+ inlineImagePartCount: 0,
126
+ maxInlineFilePayloadChars: 0,
127
+ maxInlineImagePayloadChars: 0,
128
+ remoteMediaPartCount: 0,
129
+ resourceMediaPartCount: 0,
130
+ textChars: 0,
131
+ textPartCount: 0
132
+ };
133
+ for (const message of messages) {
134
+ summarizeContent(message.content, summary);
135
+ }
136
+ return summary;
137
+ }
138
+ function summarizeContent(content, summary) {
139
+ if (typeof content === "string") {
140
+ summary.textPartCount += 1;
141
+ summary.textChars += content.length;
142
+ return;
143
+ }
144
+ if (!Array.isArray(content)) {
145
+ return;
146
+ }
147
+ for (const part of content) {
148
+ if (!isRecord(part) || typeof part.type !== "string") {
149
+ continue;
150
+ }
151
+ switch (part.type) {
152
+ case "text":
153
+ case "reasoning":
154
+ summarizeTextLikePart(part, summary);
155
+ break;
156
+ case "image":
157
+ summary.imagePartCount += 1;
158
+ summarizeMediaPayload(part.image, "image", summary);
159
+ break;
160
+ case "file":
161
+ summary.filePartCount += 1;
162
+ summarizeMediaPayload(part.data, "file", summary);
163
+ break;
164
+ case "resource":
165
+ case "ui-resource":
166
+ summary.resourceMediaPartCount += 1;
167
+ break;
168
+ }
169
+ }
170
+ }
171
+ function summarizeTextLikePart(part, summary) {
172
+ if (typeof part.text !== "string") {
173
+ return;
174
+ }
175
+ summary.textPartCount += 1;
176
+ summary.textChars += part.text.length;
177
+ }
178
+ function summarizeMediaPayload(payload, kind, summary) {
179
+ if (payload instanceof URL || isRemoteUrlString(payload)) {
180
+ summary.remoteMediaPartCount += 1;
181
+ return;
182
+ }
183
+ if (typeof payload === "string") {
184
+ summarizeInlinePayload(payload, kind, summary);
185
+ return;
186
+ }
187
+ const binaryBytes = getBinaryByteLength(payload);
188
+ if (binaryBytes !== void 0) {
189
+ summary.binaryMediaPartCount += 1;
190
+ summary.binaryMediaBytes += binaryBytes;
191
+ }
192
+ }
193
+ function summarizeInlinePayload(payload, kind, summary) {
194
+ const payloadChars = extractInlinePayload(payload).length;
195
+ const decodedBytes = estimateBase64DecodedBytes(payload);
196
+ if (kind === "image") {
197
+ summary.inlineImagePartCount += 1;
198
+ summary.inlineImagePayloadChars += payloadChars;
199
+ summary.inlineImagePayloadDecodedBytes += decodedBytes;
200
+ summary.maxInlineImagePayloadChars = Math.max(
201
+ summary.maxInlineImagePayloadChars,
202
+ payloadChars
203
+ );
204
+ return;
205
+ }
206
+ summary.inlineFilePartCount += 1;
207
+ summary.inlineFilePayloadChars += payloadChars;
208
+ summary.inlineFilePayloadDecodedBytes += decodedBytes;
209
+ summary.maxInlineFilePayloadChars = Math.max(summary.maxInlineFilePayloadChars, payloadChars);
210
+ }
211
+ function extractInlinePayload(payload) {
212
+ const trimmed = payload.trim();
213
+ const dataUriMatch = /^data:[^,]*,(.*)$/is.exec(trimmed);
214
+ return (dataUriMatch?.[1] ?? trimmed).replace(/\s/g, "");
215
+ }
216
+ function estimateBase64DecodedBytes(payload) {
217
+ const normalized = extractInlinePayload(payload);
218
+ if (normalized.length === 0) {
219
+ return 0;
220
+ }
221
+ const padding = normalized.endsWith("==") ? 2 : normalized.endsWith("=") ? 1 : 0;
222
+ return Math.max(0, Math.floor(normalized.length * 3 / 4) - padding);
223
+ }
224
+ function getBinaryByteLength(value) {
225
+ if (value instanceof Uint8Array) {
226
+ return value.byteLength;
227
+ }
228
+ if (value instanceof ArrayBuffer) {
229
+ return value.byteLength;
230
+ }
231
+ return void 0;
232
+ }
233
+ function isRemoteUrlString(value) {
234
+ return typeof value === "string" && /^https?:\/\//i.test(value);
235
+ }
236
+ function isRecord(value) {
237
+ return typeof value === "object" && value !== null;
238
+ }
239
+ function utf8ByteLength(value) {
240
+ let bytes = 0;
241
+ for (let index = 0; index < value.length; index += 1) {
242
+ const codePoint = value.codePointAt(index);
243
+ if (codePoint === void 0) {
244
+ continue;
245
+ }
246
+ if (codePoint <= 127) {
247
+ bytes += 1;
248
+ } else if (codePoint <= 2047) {
249
+ bytes += 2;
250
+ } else if (codePoint <= 65535) {
251
+ bytes += 3;
252
+ } else {
253
+ bytes += 4;
254
+ index += 1;
255
+ }
256
+ }
257
+ return bytes;
258
+ }
259
+ export {
260
+ createModelRequestDiagnostics,
261
+ modelRequestDiagnosticAttributes
262
+ };
@@ -47,6 +47,7 @@ var import_provider_error = require("./provider-error.js");
47
47
  var import_error_conversion = require("../../utils/error-conversion.js");
48
48
  var import_codex_base_url = require("../providers/codex-base-url.js");
49
49
  var import_tool_definitions = require("./tool-definitions.js");
50
+ var import_model_request_diagnostics = require("./model-request-diagnostics.js");
50
51
  var import_types3 = require("../../approval/types.js");
51
52
  var import_content_audit = require("../../context/content-audit.js");
52
53
  var import_content_clone = require("../../context/content-clone.js");
@@ -966,7 +967,7 @@ class TurnExecutor {
966
967
  () => this.contextManager.getSystemPrompt(input.contributorContext),
967
968
  this.logger
968
969
  );
969
- let { preparedHistory, formattedMessages } = await (0, import_operation_span.recordOperationSpan)(
970
+ let { preparedHistory, preparedHistoryStats, formattedMessages } = await (0, import_operation_span.recordOperationSpan)(
970
971
  {
971
972
  name: "context.build_messages",
972
973
  componentName: "TurnExecutor",
@@ -976,14 +977,19 @@ class TurnExecutor {
976
977
  }
977
978
  },
978
979
  async () => {
979
- const preparedHistory2 = (await this.contextManager.prepareModelHistory()).preparedHistory;
980
+ const preparedHistoryResult = await this.contextManager.prepareModelHistory();
981
+ const preparedHistory2 = preparedHistoryResult.preparedHistory;
980
982
  const formattedMessages2 = await this.contextManager.getFormattedMessages(
981
983
  input.contributorContext,
982
984
  this.llmContext,
983
985
  systemPrompt,
984
986
  preparedHistory2
985
987
  );
986
- return { preparedHistory: preparedHistory2, formattedMessages: formattedMessages2 };
988
+ return {
989
+ preparedHistory: preparedHistory2,
990
+ preparedHistoryStats: preparedHistoryResult.stats,
991
+ formattedMessages: formattedMessages2
992
+ };
987
993
  },
988
994
  this.logger
989
995
  );
@@ -1047,7 +1053,7 @@ class TurnExecutor {
1047
1053
  () => this.contextManager.getSystemPrompt(input.contributorContext),
1048
1054
  this.logger
1049
1055
  );
1050
- ({ preparedHistory, formattedMessages } = await (0, import_operation_span.recordOperationSpan)(
1056
+ ({ preparedHistory, preparedHistoryStats, formattedMessages } = await (0, import_operation_span.recordOperationSpan)(
1051
1057
  {
1052
1058
  name: "context.build_messages",
1053
1059
  componentName: "TurnExecutor",
@@ -1058,14 +1064,19 @@ class TurnExecutor {
1058
1064
  }
1059
1065
  },
1060
1066
  async () => {
1061
- const preparedHistory2 = (await this.contextManager.prepareModelHistory()).preparedHistory;
1067
+ const preparedHistoryResult = await this.contextManager.prepareModelHistory();
1068
+ const preparedHistory2 = preparedHistoryResult.preparedHistory;
1062
1069
  const formattedMessages2 = await this.contextManager.getFormattedMessages(
1063
1070
  input.contributorContext,
1064
1071
  this.llmContext,
1065
1072
  systemPrompt,
1066
1073
  preparedHistory2
1067
1074
  );
1068
- return { preparedHistory: preparedHistory2, formattedMessages: formattedMessages2 };
1075
+ return {
1076
+ preparedHistory: preparedHistory2,
1077
+ preparedHistoryStats: preparedHistoryResult.stats,
1078
+ formattedMessages: formattedMessages2
1079
+ };
1069
1080
  },
1070
1081
  this.logger
1071
1082
  ));
@@ -1124,6 +1135,30 @@ class TurnExecutor {
1124
1135
  ...reasoningVariant !== void 0 && { reasoningVariant },
1125
1136
  ...reasoningBudgetTokens !== void 0 && { reasoningBudgetTokens }
1126
1137
  } : void 0;
1138
+ const requestProviderOptions = providerOptions;
1139
+ const requestDiagnostics = (0, import_model_request_diagnostics.createModelRequestDiagnostics)({
1140
+ compacted,
1141
+ estimatedInputTokens,
1142
+ formattedMessages,
1143
+ model: this.llmContext.model,
1144
+ preparedHistoryCount: preparedHistory.length,
1145
+ preparedHistoryStats,
1146
+ provider: this.llmContext.provider,
1147
+ providerOptions: requestProviderOptions,
1148
+ reasoning,
1149
+ streaming: input.streaming,
1150
+ systemPrompt,
1151
+ toolDefinitions
1152
+ });
1153
+ await (0, import_operation_span.recordOperationSpan)(
1154
+ {
1155
+ name: "llm.request_diagnostics",
1156
+ componentName: "TurnExecutor",
1157
+ attributes: (0, import_model_request_diagnostics.modelRequestDiagnosticAttributes)(requestDiagnostics)
1158
+ },
1159
+ () => void 0,
1160
+ this.logger
1161
+ );
1127
1162
  this.logger.info("Model request context prepared", {
1128
1163
  sessionId: this.sessionId,
1129
1164
  provider: this.llmContext.provider,
@@ -1134,6 +1169,7 @@ class TurnExecutor {
1134
1169
  formattedMessageCount: formattedMessages.length,
1135
1170
  preparedHistoryCount: preparedHistory.length,
1136
1171
  compacted,
1172
+ requestDiagnostics,
1137
1173
  ...this.runContext?.hostRuntime?.ids !== void 0 && {
1138
1174
  hostRuntimeIds: this.runContext.hostRuntime.ids
1139
1175
  },
@@ -1145,7 +1181,7 @@ class TurnExecutor {
1145
1181
  toolDefinitions,
1146
1182
  estimatedInputTokens,
1147
1183
  reasoning,
1148
- providerOptions,
1184
+ providerOptions: requestProviderOptions,
1149
1185
  streaming: input.streaming
1150
1186
  };
1151
1187
  }
@@ -1 +1 @@
1
- {"version":3,"file":"turn-executor.d.ts","sourceRoot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AoD5B;;;OAGG;YACW,oBAAoB;IAqBlC;;;;;;;;OAQG;YACW,mBAAmB;YA4HnB,uBAAuB;YAmRvB,2BAA2B;YA2B3B,YAAY;YAuDZ,qBAAqB;IAoCnC,OAAO,CAAC,oBAAoB;YAOd,oBAAoB;YAqDpB,qBAAqB;YA+DrB,oBAAoB;YA+CpB,4BAA4B;IA6C1C,OAAO,CAAC,oBAAoB;YAad,gCAAgC;YA+BhC,gCAAgC;IA6C9C,OAAO,CAAC,mBAAmB;IAY3B,OAAO,CAAC,gBAAgB;IAexB,OAAO,CAAC,2BAA2B;YAkBrB,sBAAsB;IAgDpC,OAAO,CAAC,YAAY;IAsBpB,OAAO,CAAC,2BAA2B;IAanC,OAAO,CAAC,iCAAiC;IAUzC,OAAO,CAAC,uBAAuB;IAwB/B,OAAO,CAAC,wBAAwB;IA6BhC,OAAO,CAAC,yBAAyB;IAIjC,OAAO,CAAC,4BAA4B;IAQpC,OAAO,CAAC,wBAAwB;IAMhC,OAAO,CAAC,6BAA6B;IAYrC;;OAEG;IACH,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,aAAa,CAAU;IAC/C,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,aAAa,CAAU;IAE/C;;;;;;;;;;;OAWG;YACW,mBAAmB;IAkDjC;;;;;;OAMG;IACH,OAAO,CAAC,kBAAkB;IAgB1B;;;OAGG;IACH,OAAO,CAAC,OAAO;IASf;;;;;;OAMG;IACH,OAAO,CAAC,aAAa;IAOrB;;;;;;OAMG;IACH,OAAO,CAAC,uBAAuB;IAO/B;;;;;;;;;;;OAWG;YACW,cAAc;IAwF5B;;OAEG;IACH,OAAO,CAAC,sBAAsB;IAoB9B,OAAO,CAAC,qBAAqB;IAK7B;;OAEG;IACH,OAAO,CAAC,gBAAgB;CAQ3B"}
@@ -21,6 +21,10 @@ import {
21
21
  import { toError } from "../../utils/error-conversion.js";
22
22
  import { isCodexBaseURL } from "../providers/codex-base-url.js";
23
23
  import { createModelToolDefinitions } from "./tool-definitions.js";
24
+ import {
25
+ createModelRequestDiagnostics,
26
+ modelRequestDiagnosticAttributes
27
+ } from "./model-request-diagnostics.js";
24
28
  import { ApprovalStatus } from "../../approval/types.js";
25
29
  import {
26
30
  describeContentPartsForAudit,
@@ -943,7 +947,7 @@ class TurnExecutor {
943
947
  () => this.contextManager.getSystemPrompt(input.contributorContext),
944
948
  this.logger
945
949
  );
946
- let { preparedHistory, formattedMessages } = await recordOperationSpan(
950
+ let { preparedHistory, preparedHistoryStats, formattedMessages } = await recordOperationSpan(
947
951
  {
948
952
  name: "context.build_messages",
949
953
  componentName: "TurnExecutor",
@@ -953,14 +957,19 @@ class TurnExecutor {
953
957
  }
954
958
  },
955
959
  async () => {
956
- const preparedHistory2 = (await this.contextManager.prepareModelHistory()).preparedHistory;
960
+ const preparedHistoryResult = await this.contextManager.prepareModelHistory();
961
+ const preparedHistory2 = preparedHistoryResult.preparedHistory;
957
962
  const formattedMessages2 = await this.contextManager.getFormattedMessages(
958
963
  input.contributorContext,
959
964
  this.llmContext,
960
965
  systemPrompt,
961
966
  preparedHistory2
962
967
  );
963
- return { preparedHistory: preparedHistory2, formattedMessages: formattedMessages2 };
968
+ return {
969
+ preparedHistory: preparedHistory2,
970
+ preparedHistoryStats: preparedHistoryResult.stats,
971
+ formattedMessages: formattedMessages2
972
+ };
964
973
  },
965
974
  this.logger
966
975
  );
@@ -1024,7 +1033,7 @@ class TurnExecutor {
1024
1033
  () => this.contextManager.getSystemPrompt(input.contributorContext),
1025
1034
  this.logger
1026
1035
  );
1027
- ({ preparedHistory, formattedMessages } = await recordOperationSpan(
1036
+ ({ preparedHistory, preparedHistoryStats, formattedMessages } = await recordOperationSpan(
1028
1037
  {
1029
1038
  name: "context.build_messages",
1030
1039
  componentName: "TurnExecutor",
@@ -1035,14 +1044,19 @@ class TurnExecutor {
1035
1044
  }
1036
1045
  },
1037
1046
  async () => {
1038
- const preparedHistory2 = (await this.contextManager.prepareModelHistory()).preparedHistory;
1047
+ const preparedHistoryResult = await this.contextManager.prepareModelHistory();
1048
+ const preparedHistory2 = preparedHistoryResult.preparedHistory;
1039
1049
  const formattedMessages2 = await this.contextManager.getFormattedMessages(
1040
1050
  input.contributorContext,
1041
1051
  this.llmContext,
1042
1052
  systemPrompt,
1043
1053
  preparedHistory2
1044
1054
  );
1045
- return { preparedHistory: preparedHistory2, formattedMessages: formattedMessages2 };
1055
+ return {
1056
+ preparedHistory: preparedHistory2,
1057
+ preparedHistoryStats: preparedHistoryResult.stats,
1058
+ formattedMessages: formattedMessages2
1059
+ };
1046
1060
  },
1047
1061
  this.logger
1048
1062
  ));
@@ -1101,6 +1115,30 @@ class TurnExecutor {
1101
1115
  ...reasoningVariant !== void 0 && { reasoningVariant },
1102
1116
  ...reasoningBudgetTokens !== void 0 && { reasoningBudgetTokens }
1103
1117
  } : void 0;
1118
+ const requestProviderOptions = providerOptions;
1119
+ const requestDiagnostics = createModelRequestDiagnostics({
1120
+ compacted,
1121
+ estimatedInputTokens,
1122
+ formattedMessages,
1123
+ model: this.llmContext.model,
1124
+ preparedHistoryCount: preparedHistory.length,
1125
+ preparedHistoryStats,
1126
+ provider: this.llmContext.provider,
1127
+ providerOptions: requestProviderOptions,
1128
+ reasoning,
1129
+ streaming: input.streaming,
1130
+ systemPrompt,
1131
+ toolDefinitions
1132
+ });
1133
+ await recordOperationSpan(
1134
+ {
1135
+ name: "llm.request_diagnostics",
1136
+ componentName: "TurnExecutor",
1137
+ attributes: modelRequestDiagnosticAttributes(requestDiagnostics)
1138
+ },
1139
+ () => void 0,
1140
+ this.logger
1141
+ );
1104
1142
  this.logger.info("Model request context prepared", {
1105
1143
  sessionId: this.sessionId,
1106
1144
  provider: this.llmContext.provider,
@@ -1111,6 +1149,7 @@ class TurnExecutor {
1111
1149
  formattedMessageCount: formattedMessages.length,
1112
1150
  preparedHistoryCount: preparedHistory.length,
1113
1151
  compacted,
1152
+ requestDiagnostics,
1114
1153
  ...this.runContext?.hostRuntime?.ids !== void 0 && {
1115
1154
  hostRuntimeIds: this.runContext.hostRuntime.ids
1116
1155
  },
@@ -1122,7 +1161,7 @@ class TurnExecutor {
1122
1161
  toolDefinitions,
1123
1162
  estimatedInputTokens,
1124
1163
  reasoning,
1125
- providerOptions,
1164
+ providerOptions: requestProviderOptions,
1126
1165
  streaming: input.streaming
1127
1166
  };
1128
1167
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dexto/core",
3
- "version": "1.9.3",
3
+ "version": "1.9.4",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -162,7 +162,7 @@
162
162
  "nanoid": "^5.1.6",
163
163
  "winston": "^3.17.0",
164
164
  "yaml": "^2.8.3",
165
- "@dexto/llm": "1.9.3"
165
+ "@dexto/llm": "1.9.4"
166
166
  },
167
167
  "devDependencies": {
168
168
  "@opentelemetry/context-async-hooks": "^1.28.0",