graphlit-client 1.0.20250613008 → 1.0.20250613009

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.
package/dist/client.js CHANGED
@@ -1499,13 +1499,17 @@ class Graphlit {
1499
1499
  // 3. Tool calling loop
1500
1500
  const allToolCalls = [];
1501
1501
  let rounds = 0;
1502
- let totalTokens = 0;
1502
+ let totalTokens = currentMessage?.tokens || 0;
1503
+ const toolStartTime = Date.now();
1504
+ let toolTime = 0;
1503
1505
  while (currentMessage.toolCalls?.length &&
1504
1506
  rounds < maxRounds &&
1505
1507
  !abortController.signal.aborted) {
1506
1508
  rounds++;
1507
1509
  // Execute tools
1510
+ const toolExecStart = Date.now();
1508
1511
  const toolResults = await this.executeToolsForPromptAgent(currentMessage.toolCalls.filter((tc) => tc !== null), toolHandlers || {}, allToolCalls, abortController.signal);
1512
+ toolTime += Date.now() - toolExecStart;
1509
1513
  if (abortController.signal.aborted) {
1510
1514
  throw new Error("Operation timed out");
1511
1515
  }
@@ -1519,9 +1523,31 @@ class Graphlit {
1519
1523
  totalTokens += continueResponse.continueConversation.message.tokens;
1520
1524
  }
1521
1525
  }
1526
+ // Calculate metrics
1527
+ const totalTime = Date.now() - startTime;
1528
+ const llmTime = totalTime - toolTime;
1529
+ const metrics = {
1530
+ totalTime,
1531
+ llmTime,
1532
+ toolTime,
1533
+ toolExecutions: allToolCalls.length,
1534
+ rounds,
1535
+ };
1536
+ // Build usage info if we have token data
1537
+ const usage = totalTokens > 0 ? {
1538
+ promptTokens: 0, // We don't have this breakdown from the API
1539
+ completionTokens: totalTokens,
1540
+ totalTokens: totalTokens,
1541
+ model: currentMessage?.model || undefined,
1542
+ } : undefined;
1522
1543
  return {
1523
1544
  message: currentMessage?.message || "",
1524
1545
  conversationId: actualConversationId,
1546
+ conversationMessage: currentMessage ? currentMessage : undefined,
1547
+ toolCalls: currentMessage?.toolCalls?.filter((tc) => tc !== null),
1548
+ toolResults: allToolCalls,
1549
+ metrics,
1550
+ usage,
1525
1551
  };
1526
1552
  }
1527
1553
  catch (error) {
@@ -1536,6 +1562,14 @@ class Graphlit {
1536
1562
  recoverable: isTimeout || error.code === "RATE_LIMIT",
1537
1563
  details: error.response?.data,
1538
1564
  },
1565
+ // Include partial metrics if available
1566
+ metrics: {
1567
+ totalTime: Date.now() - startTime,
1568
+ llmTime: 0,
1569
+ toolTime: 0,
1570
+ toolExecutions: 0,
1571
+ rounds: 0,
1572
+ },
1539
1573
  };
1540
1574
  }
1541
1575
  finally {
@@ -1,11 +1,26 @@
1
+ import { ConversationMessage, ConversationToolCall } from "../generated/graphql-types.js";
1
2
  export type ToolHandler = (args: any) => Promise<any>;
2
3
  export interface AgentOptions {
3
4
  maxToolRounds?: number;
4
5
  timeout?: number;
5
6
  }
7
+ export interface AgentMetrics {
8
+ totalTime: number;
9
+ llmTime?: number;
10
+ toolTime?: number;
11
+ ttft?: number;
12
+ tokensPerSecond?: number;
13
+ toolExecutions?: number;
14
+ rounds?: number;
15
+ }
6
16
  export interface AgentResult {
7
17
  message: string;
8
18
  conversationId: string;
19
+ conversationMessage?: ConversationMessage;
20
+ toolCalls?: ConversationToolCall[];
21
+ toolResults?: ToolCallResult[];
22
+ metrics?: AgentMetrics;
23
+ usage?: UsageInfo;
9
24
  error?: AgentError;
10
25
  }
11
26
  export interface StreamAgentOptions {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "graphlit-client",
3
- "version": "1.0.20250613008",
3
+ "version": "1.0.20250613009",
4
4
  "description": "Graphlit API Client for TypeScript",
5
5
  "type": "module",
6
6
  "main": "./dist/client.js",