graphlit-client 1.0.20250613007 → 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 +35 -1
- package/dist/streaming/providers.js +36 -5
- package/dist/types/agent.d.ts +15 -0
- package/package.json +1 -1
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 {
|
@@ -11,6 +11,27 @@ function isValidJSON(str) {
|
|
11
11
|
return false;
|
12
12
|
}
|
13
13
|
}
|
14
|
+
/**
|
15
|
+
* Clean schema for Google Gemini by removing unsupported fields
|
16
|
+
*/
|
17
|
+
function cleanSchemaForGoogle(schema) {
|
18
|
+
if (typeof schema !== "object" || schema === null) {
|
19
|
+
return schema;
|
20
|
+
}
|
21
|
+
if (Array.isArray(schema)) {
|
22
|
+
return schema.map((item) => cleanSchemaForGoogle(item));
|
23
|
+
}
|
24
|
+
const cleaned = {};
|
25
|
+
for (const [key, value] of Object.entries(schema)) {
|
26
|
+
// Skip fields that Google doesn't support
|
27
|
+
if (key === "$schema" || key === "additionalProperties") {
|
28
|
+
continue;
|
29
|
+
}
|
30
|
+
// Recursively clean nested objects
|
31
|
+
cleaned[key] = cleanSchemaForGoogle(value);
|
32
|
+
}
|
33
|
+
return cleaned;
|
34
|
+
}
|
14
35
|
/**
|
15
36
|
* Stream with OpenAI SDK
|
16
37
|
*/
|
@@ -665,11 +686,21 @@ onEvent, onComplete) {
|
|
665
686
|
const googleTools = tools && tools.length > 0
|
666
687
|
? [
|
667
688
|
{
|
668
|
-
functionDeclarations: tools.map((tool) =>
|
669
|
-
|
670
|
-
|
671
|
-
|
672
|
-
|
689
|
+
functionDeclarations: tools.map((tool) => {
|
690
|
+
const rawSchema = tool.schema ? JSON.parse(tool.schema) : {};
|
691
|
+
const cleanedSchema = cleanSchemaForGoogle(rawSchema);
|
692
|
+
if (process.env.DEBUG_GRAPHLIT_SDK_STREAMING) {
|
693
|
+
const hadCleanup = JSON.stringify(rawSchema) !== JSON.stringify(cleanedSchema);
|
694
|
+
if (hadCleanup) {
|
695
|
+
console.log(`[Google] Cleaned schema for tool ${tool.name} - removed unsupported fields`);
|
696
|
+
}
|
697
|
+
}
|
698
|
+
return {
|
699
|
+
name: tool.name,
|
700
|
+
description: tool.description,
|
701
|
+
parameters: cleanedSchema,
|
702
|
+
};
|
703
|
+
}),
|
673
704
|
},
|
674
705
|
]
|
675
706
|
: undefined;
|
package/dist/types/agent.d.ts
CHANGED
@@ -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 {
|