graphlit-client 1.0.20260226003 → 1.0.20260226004

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.d.ts CHANGED
@@ -5,7 +5,7 @@ import { AgentOptions, AgentResult, StreamAgentOptions, ToolHandler } from "./ty
5
5
  import { AgentStreamEvent } from "./types/ui-events.js";
6
6
  export type { AgentOptions, AgentResult, ArtifactCollector, ContextStrategy, ContextManagementAction, StreamAgentOptions, ToolCallResult, UsageInfo, AgentError, } from "./types/agent.js";
7
7
  export { TokenBudgetTracker, truncateToolResult, estimateTokens, isAccurateTokenCounting, } from "./helpers/context-management.js";
8
- export type { AgentStreamEvent } from "./types/ui-events.js";
8
+ export type { AgentStreamEvent, ReasoningFormat, ReasoningMetadata, } from "./types/ui-events.js";
9
9
  export interface RetryConfig {
10
10
  /** Maximum number of retry attempts (default: 5) */
11
11
  maxAttempts?: number;
@@ -66,6 +66,11 @@ export declare class UIEventAdapter {
66
66
  private handleReasoningStart;
67
67
  private handleReasoningDelta;
68
68
  private handleReasoningEnd;
69
+ /**
70
+ * Build a ReasoningMetadata object from accumulated reasoning state.
71
+ * Returns undefined when no reasoning content has been captured.
72
+ */
73
+ private buildReasoningMetadata;
69
74
  /**
70
75
  * Clean up any pending timers
71
76
  */
@@ -107,6 +107,11 @@ export class UIEventAdapter {
107
107
  this.lastTokenTime = 0;
108
108
  this.tokenCount = 0;
109
109
  this.tokenDelays = [];
110
+ // Reset reasoning state so stale thinking from a prior round doesn't leak
111
+ this.reasoningContent = "";
112
+ this.reasoningFormat = undefined;
113
+ this.reasoningSignature = undefined;
114
+ this.isInReasoning = false;
110
115
  // Reset tool call tracking flags
111
116
  this.hasToolCallsInProgress = false;
112
117
  this.hadToolCallsBeforeResume = false;
@@ -436,12 +441,21 @@ export class UIEventAdapter {
436
441
  }
437
442
  return; // Exit without emitting conversation_completed
438
443
  }
444
+ // Attach reasoning metadata to the final message
445
+ const reasoning = this.buildReasoningMetadata();
446
+ if (reasoning) {
447
+ finalMessage.isThinking = true;
448
+ finalMessage.thinkingContent = reasoning.content;
449
+ }
439
450
  // Include context window usage if available
440
451
  const event = {
441
452
  type: "conversation_completed",
442
453
  message: finalMessage,
443
454
  metrics: finalMetrics,
444
455
  };
456
+ if (reasoning) {
457
+ event.reasoning = reasoning;
458
+ }
445
459
  if (this.contextWindowUsage) {
446
460
  event.contextWindow = this.contextWindowUsage;
447
461
  }
@@ -599,12 +613,22 @@ export class UIEventAdapter {
599
613
  metrics.streamingThroughput = Math.round((this.currentMessage.length / streamingTime) * 1000);
600
614
  }
601
615
  }
602
- this.emitUIEvent({
616
+ // Attach reasoning metadata to the message and event
617
+ const reasoning = this.buildReasoningMetadata();
618
+ if (reasoning) {
619
+ message.isThinking = true;
620
+ message.thinkingContent = reasoning.content;
621
+ }
622
+ const event = {
603
623
  type: "message_update",
604
624
  message,
605
625
  isStreaming,
606
626
  metrics,
607
- });
627
+ };
628
+ if (reasoning) {
629
+ event.reasoning = reasoning;
630
+ }
631
+ this.emitUIEvent(event);
608
632
  }
609
633
  emitUIEvent(event) {
610
634
  this.onEvent(event);
@@ -674,6 +698,23 @@ export class UIEventAdapter {
674
698
  });
675
699
  }
676
700
  }
701
+ /**
702
+ * Build a ReasoningMetadata object from accumulated reasoning state.
703
+ * Returns undefined when no reasoning content has been captured.
704
+ */
705
+ buildReasoningMetadata() {
706
+ if (!this.reasoningContent || !this.reasoningFormat) {
707
+ return undefined;
708
+ }
709
+ const metadata = {
710
+ content: this.reasoningContent,
711
+ format: this.reasoningFormat,
712
+ };
713
+ if (this.reasoningSignature) {
714
+ metadata.signature = this.reasoningSignature;
715
+ }
716
+ return metadata;
717
+ }
677
718
  /**
678
719
  * Clean up any pending timers
679
720
  */
@@ -21,12 +21,24 @@ export type ContextWindowEvent = {
21
21
  };
22
22
  timestamp: Date;
23
23
  };
24
+ /**
25
+ * Structured reasoning/thinking metadata.
26
+ * Provides a canonical representation across all providers so the UI
27
+ * can decide whether and how to render model reasoning.
28
+ */
29
+ export type ReasoningMetadata = {
30
+ content: string;
31
+ format: ReasoningFormat;
32
+ signature?: string;
33
+ };
24
34
  /**
25
35
  * Extended conversation message with additional streaming metadata
26
36
  */
27
37
  export type StreamingConversationMessage = Partial<ConversationMessage> & {
28
38
  message: string;
29
39
  modelName?: string;
40
+ isThinking?: boolean;
41
+ thinkingContent?: string;
30
42
  };
31
43
  /**
32
44
  * Simplified UI-focused streaming events using GraphQL types
@@ -58,6 +70,7 @@ export type AgentStreamEvent = {
58
70
  type: "message_update";
59
71
  message: StreamingConversationMessage;
60
72
  isStreaming: boolean;
73
+ reasoning?: ReasoningMetadata;
61
74
  metrics?: {
62
75
  ttft?: number;
63
76
  elapsedTime: number;
@@ -80,6 +93,7 @@ export type AgentStreamEvent = {
80
93
  } | {
81
94
  type: "conversation_completed";
82
95
  message: StreamingConversationMessage;
96
+ reasoning?: ReasoningMetadata;
83
97
  metrics?: {
84
98
  ttft?: number;
85
99
  totalTime: number;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "graphlit-client",
3
- "version": "1.0.20260226003",
3
+ "version": "1.0.20260226004",
4
4
  "description": "Graphlit API Client for TypeScript",
5
5
  "type": "module",
6
6
  "main": "./dist/client.js",