@fallom/trace 0.2.17 → 0.2.18

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 (3) hide show
  1. package/dist/index.js +127 -32
  2. package/dist/index.mjs +127 -32
  3. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -2727,20 +2727,36 @@ function createGenerateTextWrapper(aiModule, sessionCtx, debug = false) {
2727
2727
  tools: params?.tools ? Object.keys(params.tools) : void 0,
2728
2728
  maxSteps: params?.maxSteps
2729
2729
  });
2730
- const mapToolCall = (tc) => ({
2731
- toolCallId: tc?.toolCallId,
2732
- toolName: tc?.toolName,
2733
- args: tc?.args ?? tc?.input,
2734
- // v4: args, v5: input
2735
- type: tc?.type
2736
- });
2737
- const mapToolResult = (tr) => ({
2738
- toolCallId: tr?.toolCallId,
2739
- toolName: tr?.toolName,
2740
- result: tr?.result ?? tr?.output,
2741
- // v4: result, v5: output
2742
- type: tr?.type
2743
- });
2730
+ const mapToolCall = (tc) => {
2731
+ let args2 = tc?.args ?? tc?.input;
2732
+ if (args2 === void 0 && tc) {
2733
+ const { type, toolCallId, toolName, providerExecuted, dynamic, invalid, error, providerMetadata, ...rest } = tc;
2734
+ if (Object.keys(rest).length > 0) {
2735
+ args2 = rest;
2736
+ }
2737
+ }
2738
+ return {
2739
+ toolCallId: tc?.toolCallId,
2740
+ toolName: tc?.toolName,
2741
+ args: args2,
2742
+ type: tc?.type
2743
+ };
2744
+ };
2745
+ const mapToolResult = (tr) => {
2746
+ let result2 = tr?.result ?? tr?.output;
2747
+ if (result2 === void 0 && tr) {
2748
+ const { type, toolCallId, toolName, ...rest } = tr;
2749
+ if (Object.keys(rest).length > 0) {
2750
+ result2 = rest;
2751
+ }
2752
+ }
2753
+ return {
2754
+ toolCallId: tr?.toolCallId,
2755
+ toolName: tr?.toolName,
2756
+ result: result2,
2757
+ type: tr?.type
2758
+ };
2759
+ };
2744
2760
  attributes["fallom.raw.response"] = JSON.stringify({
2745
2761
  text: result?.text,
2746
2762
  finishReason: result?.finishReason,
@@ -2953,7 +2969,9 @@ function createStreamTextWrapper(aiModule, sessionCtx, debug = false) {
2953
2969
  let wrappedParams = params;
2954
2970
  if (params.tools && typeof params.tools === "object") {
2955
2971
  const wrappedTools = {};
2956
- for (const [toolName, tool] of Object.entries(params.tools)) {
2972
+ for (const [toolName, tool] of Object.entries(
2973
+ params.tools
2974
+ )) {
2957
2975
  if (tool && typeof tool.execute === "function") {
2958
2976
  const originalExecute = tool.execute;
2959
2977
  wrappedTools[toolName] = {
@@ -3036,10 +3054,54 @@ function createStreamTextWrapper(aiModule, sessionCtx, debug = false) {
3036
3054
  "\u{1F50D} [Fallom Debug] streamText toolCalls:",
3037
3055
  JSON.stringify(toolCalls, null, 2)
3038
3056
  );
3057
+ if (toolCalls?.[0]) {
3058
+ console.log(
3059
+ "\u{1F50D} [Fallom Debug] streamText toolCalls[0] keys:",
3060
+ Object.keys(toolCalls[0])
3061
+ );
3062
+ console.log(
3063
+ "\u{1F50D} [Fallom Debug] streamText toolCalls[0] full:",
3064
+ JSON.stringify(
3065
+ toolCalls[0],
3066
+ Object.getOwnPropertyNames(toolCalls[0]),
3067
+ 2
3068
+ )
3069
+ );
3070
+ }
3039
3071
  console.log(
3040
3072
  "\u{1F50D} [Fallom Debug] streamText steps count:",
3041
3073
  steps?.length
3042
3074
  );
3075
+ if (steps?.[0]?.toolCalls?.[0]) {
3076
+ const tc = steps[0].toolCalls[0];
3077
+ console.log(
3078
+ "\u{1F50D} [Fallom Debug] steps[0].toolCalls[0] keys:",
3079
+ Object.keys(tc)
3080
+ );
3081
+ console.log(
3082
+ "\u{1F50D} [Fallom Debug] steps[0].toolCalls[0].args (v4):",
3083
+ tc.args
3084
+ );
3085
+ console.log(
3086
+ "\u{1F50D} [Fallom Debug] steps[0].toolCalls[0].input (v5):",
3087
+ tc.input
3088
+ );
3089
+ }
3090
+ if (steps?.[0]?.toolResults?.[0]) {
3091
+ const tr = steps[0].toolResults[0];
3092
+ console.log(
3093
+ "\u{1F50D} [Fallom Debug] steps[0].toolResults[0] keys:",
3094
+ Object.keys(tr)
3095
+ );
3096
+ console.log(
3097
+ "\u{1F50D} [Fallom Debug] steps[0].toolResults[0].result (v4):",
3098
+ typeof tr.result === "string" ? tr.result.slice(0, 200) : tr.result
3099
+ );
3100
+ console.log(
3101
+ "\u{1F50D} [Fallom Debug] steps[0].toolResults[0].output (v5):",
3102
+ typeof tr.output === "string" ? tr.output.slice(0, 200) : tr.output
3103
+ );
3104
+ }
3043
3105
  }
3044
3106
  let providerMetadata = result?.experimental_providerMetadata;
3045
3107
  if (providerMetadata && typeof providerMetadata.then === "function") {
@@ -3055,20 +3117,46 @@ function createStreamTextWrapper(aiModule, sessionCtx, debug = false) {
3055
3117
  "fallom.is_streaming": true
3056
3118
  };
3057
3119
  if (captureContent2) {
3058
- const mapToolCall = (tc) => ({
3059
- toolCallId: tc?.toolCallId,
3060
- toolName: tc?.toolName,
3061
- args: tc?.args ?? tc?.input,
3062
- // v4: args, v5: input
3063
- type: tc?.type
3064
- });
3065
- const mapToolResult = (tr) => ({
3066
- toolCallId: tr?.toolCallId,
3067
- toolName: tr?.toolName,
3068
- result: tr?.result ?? tr?.output,
3069
- // v4: result, v5: output
3070
- type: tr?.type
3071
- });
3120
+ const mapToolCall = (tc) => {
3121
+ let args2 = tc?.args ?? tc?.input;
3122
+ if (args2 === void 0 && tc) {
3123
+ const {
3124
+ type,
3125
+ toolCallId,
3126
+ toolName,
3127
+ providerExecuted,
3128
+ dynamic,
3129
+ invalid,
3130
+ error,
3131
+ providerMetadata: providerMetadata2,
3132
+ ...rest
3133
+ } = tc;
3134
+ if (Object.keys(rest).length > 0) {
3135
+ args2 = rest;
3136
+ }
3137
+ }
3138
+ return {
3139
+ toolCallId: tc?.toolCallId,
3140
+ toolName: tc?.toolName,
3141
+ args: args2,
3142
+ type: tc?.type
3143
+ };
3144
+ };
3145
+ const mapToolResult = (tr) => {
3146
+ let result2 = tr?.result ?? tr?.output;
3147
+ if (result2 === void 0 && tr) {
3148
+ const { type, toolCallId, toolName, ...rest } = tr;
3149
+ if (Object.keys(rest).length > 0) {
3150
+ result2 = rest;
3151
+ }
3152
+ }
3153
+ return {
3154
+ toolCallId: tr?.toolCallId,
3155
+ toolName: tr?.toolName,
3156
+ result: result2,
3157
+ type: tr?.type
3158
+ };
3159
+ };
3072
3160
  attributes["fallom.raw.request"] = JSON.stringify({
3073
3161
  prompt: params?.prompt,
3074
3162
  messages: params?.messages,
@@ -3110,7 +3198,10 @@ function createStreamTextWrapper(aiModule, sessionCtx, debug = false) {
3110
3198
  attributes["fallom.time_to_first_token_ms"] = firstTokenTime - startTime;
3111
3199
  }
3112
3200
  try {
3113
- attributes["fallom.raw.metadata"] = JSON.stringify(result, sanitizeMetadataOnly);
3201
+ attributes["fallom.raw.metadata"] = JSON.stringify(
3202
+ result,
3203
+ sanitizeMetadataOnly
3204
+ );
3114
3205
  } catch {
3115
3206
  }
3116
3207
  const totalDurationMs = endTime - startTime;
@@ -3137,8 +3228,12 @@ function createStreamTextWrapper(aiModule, sessionCtx, debug = false) {
3137
3228
  });
3138
3229
  }
3139
3230
  if (sortedToolTimings.length > 0) {
3140
- const firstToolStart = Math.min(...sortedToolTimings.map((t) => t.startTime));
3141
- const lastToolEnd = Math.max(...sortedToolTimings.map((t) => t.endTime));
3231
+ const firstToolStart = Math.min(
3232
+ ...sortedToolTimings.map((t) => t.startTime)
3233
+ );
3234
+ const lastToolEnd = Math.max(
3235
+ ...sortedToolTimings.map((t) => t.endTime)
3236
+ );
3142
3237
  if (firstToolStart > 10) {
3143
3238
  waterfallTimings.phases.push({
3144
3239
  type: "llm",
package/dist/index.mjs CHANGED
@@ -1567,20 +1567,36 @@ function createGenerateTextWrapper(aiModule, sessionCtx, debug = false) {
1567
1567
  tools: params?.tools ? Object.keys(params.tools) : void 0,
1568
1568
  maxSteps: params?.maxSteps
1569
1569
  });
1570
- const mapToolCall = (tc) => ({
1571
- toolCallId: tc?.toolCallId,
1572
- toolName: tc?.toolName,
1573
- args: tc?.args ?? tc?.input,
1574
- // v4: args, v5: input
1575
- type: tc?.type
1576
- });
1577
- const mapToolResult = (tr) => ({
1578
- toolCallId: tr?.toolCallId,
1579
- toolName: tr?.toolName,
1580
- result: tr?.result ?? tr?.output,
1581
- // v4: result, v5: output
1582
- type: tr?.type
1583
- });
1570
+ const mapToolCall = (tc) => {
1571
+ let args2 = tc?.args ?? tc?.input;
1572
+ if (args2 === void 0 && tc) {
1573
+ const { type, toolCallId, toolName, providerExecuted, dynamic, invalid, error, providerMetadata, ...rest } = tc;
1574
+ if (Object.keys(rest).length > 0) {
1575
+ args2 = rest;
1576
+ }
1577
+ }
1578
+ return {
1579
+ toolCallId: tc?.toolCallId,
1580
+ toolName: tc?.toolName,
1581
+ args: args2,
1582
+ type: tc?.type
1583
+ };
1584
+ };
1585
+ const mapToolResult = (tr) => {
1586
+ let result2 = tr?.result ?? tr?.output;
1587
+ if (result2 === void 0 && tr) {
1588
+ const { type, toolCallId, toolName, ...rest } = tr;
1589
+ if (Object.keys(rest).length > 0) {
1590
+ result2 = rest;
1591
+ }
1592
+ }
1593
+ return {
1594
+ toolCallId: tr?.toolCallId,
1595
+ toolName: tr?.toolName,
1596
+ result: result2,
1597
+ type: tr?.type
1598
+ };
1599
+ };
1584
1600
  attributes["fallom.raw.response"] = JSON.stringify({
1585
1601
  text: result?.text,
1586
1602
  finishReason: result?.finishReason,
@@ -1793,7 +1809,9 @@ function createStreamTextWrapper(aiModule, sessionCtx, debug = false) {
1793
1809
  let wrappedParams = params;
1794
1810
  if (params.tools && typeof params.tools === "object") {
1795
1811
  const wrappedTools = {};
1796
- for (const [toolName, tool] of Object.entries(params.tools)) {
1812
+ for (const [toolName, tool] of Object.entries(
1813
+ params.tools
1814
+ )) {
1797
1815
  if (tool && typeof tool.execute === "function") {
1798
1816
  const originalExecute = tool.execute;
1799
1817
  wrappedTools[toolName] = {
@@ -1876,10 +1894,54 @@ function createStreamTextWrapper(aiModule, sessionCtx, debug = false) {
1876
1894
  "\u{1F50D} [Fallom Debug] streamText toolCalls:",
1877
1895
  JSON.stringify(toolCalls, null, 2)
1878
1896
  );
1897
+ if (toolCalls?.[0]) {
1898
+ console.log(
1899
+ "\u{1F50D} [Fallom Debug] streamText toolCalls[0] keys:",
1900
+ Object.keys(toolCalls[0])
1901
+ );
1902
+ console.log(
1903
+ "\u{1F50D} [Fallom Debug] streamText toolCalls[0] full:",
1904
+ JSON.stringify(
1905
+ toolCalls[0],
1906
+ Object.getOwnPropertyNames(toolCalls[0]),
1907
+ 2
1908
+ )
1909
+ );
1910
+ }
1879
1911
  console.log(
1880
1912
  "\u{1F50D} [Fallom Debug] streamText steps count:",
1881
1913
  steps?.length
1882
1914
  );
1915
+ if (steps?.[0]?.toolCalls?.[0]) {
1916
+ const tc = steps[0].toolCalls[0];
1917
+ console.log(
1918
+ "\u{1F50D} [Fallom Debug] steps[0].toolCalls[0] keys:",
1919
+ Object.keys(tc)
1920
+ );
1921
+ console.log(
1922
+ "\u{1F50D} [Fallom Debug] steps[0].toolCalls[0].args (v4):",
1923
+ tc.args
1924
+ );
1925
+ console.log(
1926
+ "\u{1F50D} [Fallom Debug] steps[0].toolCalls[0].input (v5):",
1927
+ tc.input
1928
+ );
1929
+ }
1930
+ if (steps?.[0]?.toolResults?.[0]) {
1931
+ const tr = steps[0].toolResults[0];
1932
+ console.log(
1933
+ "\u{1F50D} [Fallom Debug] steps[0].toolResults[0] keys:",
1934
+ Object.keys(tr)
1935
+ );
1936
+ console.log(
1937
+ "\u{1F50D} [Fallom Debug] steps[0].toolResults[0].result (v4):",
1938
+ typeof tr.result === "string" ? tr.result.slice(0, 200) : tr.result
1939
+ );
1940
+ console.log(
1941
+ "\u{1F50D} [Fallom Debug] steps[0].toolResults[0].output (v5):",
1942
+ typeof tr.output === "string" ? tr.output.slice(0, 200) : tr.output
1943
+ );
1944
+ }
1883
1945
  }
1884
1946
  let providerMetadata = result?.experimental_providerMetadata;
1885
1947
  if (providerMetadata && typeof providerMetadata.then === "function") {
@@ -1895,20 +1957,46 @@ function createStreamTextWrapper(aiModule, sessionCtx, debug = false) {
1895
1957
  "fallom.is_streaming": true
1896
1958
  };
1897
1959
  if (captureContent2) {
1898
- const mapToolCall = (tc) => ({
1899
- toolCallId: tc?.toolCallId,
1900
- toolName: tc?.toolName,
1901
- args: tc?.args ?? tc?.input,
1902
- // v4: args, v5: input
1903
- type: tc?.type
1904
- });
1905
- const mapToolResult = (tr) => ({
1906
- toolCallId: tr?.toolCallId,
1907
- toolName: tr?.toolName,
1908
- result: tr?.result ?? tr?.output,
1909
- // v4: result, v5: output
1910
- type: tr?.type
1911
- });
1960
+ const mapToolCall = (tc) => {
1961
+ let args2 = tc?.args ?? tc?.input;
1962
+ if (args2 === void 0 && tc) {
1963
+ const {
1964
+ type,
1965
+ toolCallId,
1966
+ toolName,
1967
+ providerExecuted,
1968
+ dynamic,
1969
+ invalid,
1970
+ error,
1971
+ providerMetadata: providerMetadata2,
1972
+ ...rest
1973
+ } = tc;
1974
+ if (Object.keys(rest).length > 0) {
1975
+ args2 = rest;
1976
+ }
1977
+ }
1978
+ return {
1979
+ toolCallId: tc?.toolCallId,
1980
+ toolName: tc?.toolName,
1981
+ args: args2,
1982
+ type: tc?.type
1983
+ };
1984
+ };
1985
+ const mapToolResult = (tr) => {
1986
+ let result2 = tr?.result ?? tr?.output;
1987
+ if (result2 === void 0 && tr) {
1988
+ const { type, toolCallId, toolName, ...rest } = tr;
1989
+ if (Object.keys(rest).length > 0) {
1990
+ result2 = rest;
1991
+ }
1992
+ }
1993
+ return {
1994
+ toolCallId: tr?.toolCallId,
1995
+ toolName: tr?.toolName,
1996
+ result: result2,
1997
+ type: tr?.type
1998
+ };
1999
+ };
1912
2000
  attributes["fallom.raw.request"] = JSON.stringify({
1913
2001
  prompt: params?.prompt,
1914
2002
  messages: params?.messages,
@@ -1950,7 +2038,10 @@ function createStreamTextWrapper(aiModule, sessionCtx, debug = false) {
1950
2038
  attributes["fallom.time_to_first_token_ms"] = firstTokenTime - startTime;
1951
2039
  }
1952
2040
  try {
1953
- attributes["fallom.raw.metadata"] = JSON.stringify(result, sanitizeMetadataOnly);
2041
+ attributes["fallom.raw.metadata"] = JSON.stringify(
2042
+ result,
2043
+ sanitizeMetadataOnly
2044
+ );
1954
2045
  } catch {
1955
2046
  }
1956
2047
  const totalDurationMs = endTime - startTime;
@@ -1977,8 +2068,12 @@ function createStreamTextWrapper(aiModule, sessionCtx, debug = false) {
1977
2068
  });
1978
2069
  }
1979
2070
  if (sortedToolTimings.length > 0) {
1980
- const firstToolStart = Math.min(...sortedToolTimings.map((t) => t.startTime));
1981
- const lastToolEnd = Math.max(...sortedToolTimings.map((t) => t.endTime));
2071
+ const firstToolStart = Math.min(
2072
+ ...sortedToolTimings.map((t) => t.startTime)
2073
+ );
2074
+ const lastToolEnd = Math.max(
2075
+ ...sortedToolTimings.map((t) => t.endTime)
2076
+ );
1982
2077
  if (firstToolStart > 10) {
1983
2078
  waterfallTimings.phases.push({
1984
2079
  type: "llm",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fallom/trace",
3
- "version": "0.2.17",
3
+ "version": "0.2.18",
4
4
  "description": "Model A/B testing and tracing for LLM applications. Zero latency, production-ready.",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",