graphlit-client 1.0.20260405003 → 1.0.20260406002
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
|
@@ -6711,6 +6711,31 @@ class Graphlit {
|
|
|
6711
6711
|
let lastContextWindow;
|
|
6712
6712
|
let conversationId = options?.conversationId ?? "";
|
|
6713
6713
|
let resolvedAgentId = agentId ?? "";
|
|
6714
|
+
// Accumulate token usage across all turns from conversation_completed events
|
|
6715
|
+
let accumulatedUsage = {
|
|
6716
|
+
promptTokens: 0,
|
|
6717
|
+
completionTokens: 0,
|
|
6718
|
+
totalTokens: 0,
|
|
6719
|
+
};
|
|
6720
|
+
let lastTurnUsage;
|
|
6721
|
+
// Wrap onEvent to capture per-turn usage from conversation_completed events
|
|
6722
|
+
const wrappedOnEvent = (event) => {
|
|
6723
|
+
if (event.type === 'conversation_completed' && event.usage) {
|
|
6724
|
+
const u = event.usage;
|
|
6725
|
+
lastTurnUsage = {
|
|
6726
|
+
promptTokens: u.promptTokens || 0,
|
|
6727
|
+
completionTokens: u.completionTokens || 0,
|
|
6728
|
+
totalTokens: u.totalTokens || 0,
|
|
6729
|
+
model: u.model,
|
|
6730
|
+
};
|
|
6731
|
+
accumulatedUsage.promptTokens += lastTurnUsage.promptTokens;
|
|
6732
|
+
accumulatedUsage.completionTokens += lastTurnUsage.completionTokens;
|
|
6733
|
+
accumulatedUsage.totalTokens += lastTurnUsage.totalTokens;
|
|
6734
|
+
if (lastTurnUsage.model)
|
|
6735
|
+
accumulatedUsage.model = lastTurnUsage.model;
|
|
6736
|
+
}
|
|
6737
|
+
onEvent(event);
|
|
6738
|
+
};
|
|
6714
6739
|
try {
|
|
6715
6740
|
// ── Phase 1: Setup ─────────────────────────────────────────────────
|
|
6716
6741
|
// Check abort early
|
|
@@ -6723,6 +6748,7 @@ class Graphlit {
|
|
|
6723
6748
|
turnResults,
|
|
6724
6749
|
totalToolCalls,
|
|
6725
6750
|
wallClockMs: Date.now() - runStart,
|
|
6751
|
+
usage: accumulatedUsage.totalTokens > 0 ? accumulatedUsage : undefined,
|
|
6726
6752
|
});
|
|
6727
6753
|
}
|
|
6728
6754
|
// Resolve or create Agent entity
|
|
@@ -6987,7 +7013,7 @@ class Graphlit {
|
|
|
6987
7013
|
// Emit context window event
|
|
6988
7014
|
if (formatDetails?.tokenLimit && formatDetails?.messages) {
|
|
6989
7015
|
const usedTokens = formatDetails.messages.reduce((sum, msg) => sum + (msg?.tokens || 0), 0);
|
|
6990
|
-
|
|
7016
|
+
wrappedOnEvent({
|
|
6991
7017
|
type: "context_window",
|
|
6992
7018
|
usage: {
|
|
6993
7019
|
usedTokens,
|
|
@@ -7004,7 +7030,7 @@ class Graphlit {
|
|
|
7004
7030
|
const modelEnum = fullSpec ? getModelEnum(fullSpec) : undefined;
|
|
7005
7031
|
const serviceType = fullSpec ? getServiceType(fullSpec) : undefined;
|
|
7006
7032
|
const uiAdapter = new UIEventAdapter((event) => {
|
|
7007
|
-
|
|
7033
|
+
wrappedOnEvent(event);
|
|
7008
7034
|
options?.onStreamEvent?.(event);
|
|
7009
7035
|
}, conversationId, {
|
|
7010
7036
|
smoothingEnabled: options?.smoothingEnabled ?? true,
|
|
@@ -7109,7 +7135,10 @@ class Graphlit {
|
|
|
7109
7135
|
? loopResult.contextActions
|
|
7110
7136
|
: undefined,
|
|
7111
7137
|
errors: loopResult.errors.length > 0 ? loopResult.errors : undefined,
|
|
7138
|
+
usage: lastTurnUsage,
|
|
7112
7139
|
};
|
|
7140
|
+
// Reset per-turn usage for next turn
|
|
7141
|
+
lastTurnUsage = undefined;
|
|
7113
7142
|
turnResults.push(turnResult);
|
|
7114
7143
|
totalToolCalls += loopResult.toolCallCount;
|
|
7115
7144
|
finalMessage = loopResult.finalAssistantMessage || loopResult.fullMessage;
|
|
@@ -7185,6 +7214,7 @@ class Graphlit {
|
|
|
7185
7214
|
error: errorMessage,
|
|
7186
7215
|
stuckPattern,
|
|
7187
7216
|
qualityAssessment,
|
|
7217
|
+
usage: accumulatedUsage.totalTokens > 0 ? accumulatedUsage : undefined,
|
|
7188
7218
|
});
|
|
7189
7219
|
}
|
|
7190
7220
|
catch (error) {
|
|
@@ -7210,6 +7240,7 @@ class Graphlit {
|
|
|
7210
7240
|
contextWindowAtEnd: lastContextWindow,
|
|
7211
7241
|
error: errorMessage,
|
|
7212
7242
|
stuckPattern,
|
|
7243
|
+
usage: accumulatedUsage.totalTokens > 0 ? accumulatedUsage : undefined,
|
|
7213
7244
|
});
|
|
7214
7245
|
}
|
|
7215
7246
|
}
|
|
@@ -7418,6 +7449,7 @@ class Graphlit {
|
|
|
7418
7449
|
error: params.error,
|
|
7419
7450
|
stuckPattern: params.stuckPattern,
|
|
7420
7451
|
qualityAssessment: params.qualityAssessment,
|
|
7452
|
+
usage: params.usage,
|
|
7421
7453
|
};
|
|
7422
7454
|
}
|
|
7423
7455
|
/**
|
|
@@ -81,6 +81,10 @@ export const GetAgent = gql `
|
|
|
81
81
|
id
|
|
82
82
|
name
|
|
83
83
|
}
|
|
84
|
+
persona {
|
|
85
|
+
id
|
|
86
|
+
name
|
|
87
|
+
}
|
|
84
88
|
trigger {
|
|
85
89
|
types
|
|
86
90
|
fileTypes
|
|
@@ -327,6 +331,10 @@ export const QueryAgents = gql `
|
|
|
327
331
|
id
|
|
328
332
|
name
|
|
329
333
|
}
|
|
334
|
+
persona {
|
|
335
|
+
id
|
|
336
|
+
name
|
|
337
|
+
}
|
|
330
338
|
trigger {
|
|
331
339
|
types
|
|
332
340
|
fileTypes
|
|
@@ -139,6 +139,8 @@ export type Agent = {
|
|
|
139
139
|
name: Scalars['String']['output'];
|
|
140
140
|
/** The owner of the agent. */
|
|
141
141
|
owner: Owner;
|
|
142
|
+
/** The persona associated with this agent. */
|
|
143
|
+
persona?: Maybe<Persona>;
|
|
142
144
|
/** The execution prompt run on each triggered activation (schedule, webhook, event, manual). */
|
|
143
145
|
prompt?: Maybe<Scalars['String']['output']>;
|
|
144
146
|
/** The relevance score of the agent. */
|
|
@@ -295,6 +297,8 @@ export type AgentInput = {
|
|
|
295
297
|
filter?: InputMaybe<ContentCriteriaInput>;
|
|
296
298
|
/** The name of the agent. */
|
|
297
299
|
name: Scalars['String']['input'];
|
|
300
|
+
/** The persona associated with this agent. */
|
|
301
|
+
persona?: InputMaybe<EntityReferenceInput>;
|
|
298
302
|
/** The execution prompt run on each triggered activation. */
|
|
299
303
|
prompt?: InputMaybe<Scalars['String']['input']>;
|
|
300
304
|
/** The agent research depth. Defaults to STANDARD. */
|
|
@@ -396,6 +400,8 @@ export type AgentUpdateInput = {
|
|
|
396
400
|
id: Scalars['ID']['input'];
|
|
397
401
|
/** The name of the agent. */
|
|
398
402
|
name?: InputMaybe<Scalars['String']['input']>;
|
|
403
|
+
/** The persona associated with this agent. */
|
|
404
|
+
persona?: InputMaybe<EntityReferenceInput>;
|
|
399
405
|
/** The execution prompt run on each triggered activation. */
|
|
400
406
|
prompt?: InputMaybe<Scalars['String']['input']>;
|
|
401
407
|
/** The agent research depth. Defaults to STANDARD. */
|
|
@@ -25353,6 +25359,11 @@ export type GetAgentQuery = {
|
|
|
25353
25359
|
id: string;
|
|
25354
25360
|
name: string;
|
|
25355
25361
|
} | null;
|
|
25362
|
+
persona?: {
|
|
25363
|
+
__typename?: 'Persona';
|
|
25364
|
+
id: string;
|
|
25365
|
+
name: string;
|
|
25366
|
+
} | null;
|
|
25356
25367
|
trigger?: {
|
|
25357
25368
|
__typename?: 'AgentTriggerFilter';
|
|
25358
25369
|
types?: Array<ContentTypes> | null;
|
|
@@ -25664,6 +25675,11 @@ export type QueryAgentsQuery = {
|
|
|
25664
25675
|
id: string;
|
|
25665
25676
|
name: string;
|
|
25666
25677
|
} | null;
|
|
25678
|
+
persona?: {
|
|
25679
|
+
__typename?: 'Persona';
|
|
25680
|
+
id: string;
|
|
25681
|
+
name: string;
|
|
25682
|
+
} | null;
|
|
25667
25683
|
trigger?: {
|
|
25668
25684
|
__typename?: 'AgentTriggerFilter';
|
|
25669
25685
|
types?: Array<ContentTypes> | null;
|
package/dist/types/agent.d.ts
CHANGED
|
@@ -114,6 +114,8 @@ export interface TurnResult {
|
|
|
114
114
|
contextWindowUsage?: ContextWindowUsage;
|
|
115
115
|
contextActions?: ContextManagementAction[];
|
|
116
116
|
errors?: string[];
|
|
117
|
+
/** Token usage for this turn (from native LLM provider). */
|
|
118
|
+
usage?: UsageInfo;
|
|
117
119
|
}
|
|
118
120
|
/** Budget snapshot passed to the onBudgetWarning callback. */
|
|
119
121
|
export interface BudgetSnapshot {
|
|
@@ -181,6 +183,8 @@ export interface RunAgentResult {
|
|
|
181
183
|
error?: string;
|
|
182
184
|
stuckPattern?: string;
|
|
183
185
|
qualityAssessment?: QualityAssessment;
|
|
186
|
+
/** Accumulated token usage across all turns (from native LLM provider). */
|
|
187
|
+
usage?: UsageInfo;
|
|
184
188
|
}
|
|
185
189
|
import type { ReasoningMetadata } from "./ui-events.js";
|
|
186
190
|
import type { TokenBudgetTracker } from "../helpers/context-management.js";
|