@juspay/neurolink 8.26.0 → 8.27.0

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 (101) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/README.md +47 -25
  3. package/dist/adapters/providerImageAdapter.js +11 -0
  4. package/dist/cli/commands/config.js +16 -23
  5. package/dist/cli/commands/setup-anthropic.js +3 -26
  6. package/dist/cli/commands/setup-azure.js +3 -22
  7. package/dist/cli/commands/setup-bedrock.js +3 -26
  8. package/dist/cli/commands/setup-google-ai.js +3 -22
  9. package/dist/cli/commands/setup-mistral.js +3 -31
  10. package/dist/cli/commands/setup-openai.js +3 -22
  11. package/dist/cli/factories/commandFactory.js +32 -0
  12. package/dist/cli/factories/ollamaCommandFactory.js +5 -17
  13. package/dist/cli/loop/optionsSchema.d.ts +1 -1
  14. package/dist/cli/loop/optionsSchema.js +13 -0
  15. package/dist/config/modelSpecificPrompts.d.ts +9 -0
  16. package/dist/config/modelSpecificPrompts.js +38 -0
  17. package/dist/constants/enums.d.ts +8 -0
  18. package/dist/constants/enums.js +8 -0
  19. package/dist/constants/tokens.d.ts +25 -0
  20. package/dist/constants/tokens.js +18 -0
  21. package/dist/core/analytics.js +7 -28
  22. package/dist/core/baseProvider.js +1 -0
  23. package/dist/core/constants.d.ts +1 -0
  24. package/dist/core/constants.js +1 -0
  25. package/dist/core/modules/GenerationHandler.js +43 -5
  26. package/dist/core/streamAnalytics.d.ts +1 -0
  27. package/dist/core/streamAnalytics.js +8 -16
  28. package/dist/lib/adapters/providerImageAdapter.js +11 -0
  29. package/dist/lib/config/modelSpecificPrompts.d.ts +9 -0
  30. package/dist/lib/config/modelSpecificPrompts.js +39 -0
  31. package/dist/lib/constants/enums.d.ts +8 -0
  32. package/dist/lib/constants/enums.js +8 -0
  33. package/dist/lib/constants/tokens.d.ts +25 -0
  34. package/dist/lib/constants/tokens.js +18 -0
  35. package/dist/lib/core/analytics.js +7 -28
  36. package/dist/lib/core/baseProvider.js +1 -0
  37. package/dist/lib/core/constants.d.ts +1 -0
  38. package/dist/lib/core/constants.js +1 -0
  39. package/dist/lib/core/modules/GenerationHandler.js +43 -5
  40. package/dist/lib/core/streamAnalytics.d.ts +1 -0
  41. package/dist/lib/core/streamAnalytics.js +8 -16
  42. package/dist/lib/providers/googleAiStudio.d.ts +15 -0
  43. package/dist/lib/providers/googleAiStudio.js +659 -3
  44. package/dist/lib/providers/googleVertex.d.ts +25 -0
  45. package/dist/lib/providers/googleVertex.js +978 -3
  46. package/dist/lib/providers/sagemaker/language-model.d.ts +2 -2
  47. package/dist/lib/types/analytics.d.ts +4 -0
  48. package/dist/lib/types/cli.d.ts +16 -0
  49. package/dist/lib/types/conversation.d.ts +72 -4
  50. package/dist/lib/types/conversation.js +30 -0
  51. package/dist/lib/types/generateTypes.d.ts +135 -0
  52. package/dist/lib/types/groundingTypes.d.ts +231 -0
  53. package/dist/lib/types/groundingTypes.js +12 -0
  54. package/dist/lib/types/providers.d.ts +29 -0
  55. package/dist/lib/types/streamTypes.d.ts +54 -0
  56. package/dist/lib/utils/analyticsUtils.js +22 -2
  57. package/dist/lib/utils/errorHandling.d.ts +65 -0
  58. package/dist/lib/utils/errorHandling.js +268 -0
  59. package/dist/lib/utils/modelChoices.d.ts +82 -0
  60. package/dist/lib/utils/modelChoices.js +402 -0
  61. package/dist/lib/utils/modelDetection.d.ts +9 -0
  62. package/dist/lib/utils/modelDetection.js +81 -0
  63. package/dist/lib/utils/parameterValidation.d.ts +59 -1
  64. package/dist/lib/utils/parameterValidation.js +196 -0
  65. package/dist/lib/utils/schemaConversion.d.ts +12 -0
  66. package/dist/lib/utils/schemaConversion.js +90 -0
  67. package/dist/lib/utils/thinkingConfig.d.ts +108 -0
  68. package/dist/lib/utils/thinkingConfig.js +105 -0
  69. package/dist/lib/utils/tokenUtils.d.ts +124 -0
  70. package/dist/lib/utils/tokenUtils.js +240 -0
  71. package/dist/lib/utils/transformationUtils.js +15 -26
  72. package/dist/providers/googleAiStudio.d.ts +15 -0
  73. package/dist/providers/googleAiStudio.js +659 -3
  74. package/dist/providers/googleVertex.d.ts +25 -0
  75. package/dist/providers/googleVertex.js +978 -3
  76. package/dist/types/analytics.d.ts +4 -0
  77. package/dist/types/cli.d.ts +16 -0
  78. package/dist/types/conversation.d.ts +72 -4
  79. package/dist/types/conversation.js +30 -0
  80. package/dist/types/generateTypes.d.ts +135 -0
  81. package/dist/types/groundingTypes.d.ts +231 -0
  82. package/dist/types/groundingTypes.js +11 -0
  83. package/dist/types/providers.d.ts +29 -0
  84. package/dist/types/streamTypes.d.ts +54 -0
  85. package/dist/utils/analyticsUtils.js +22 -2
  86. package/dist/utils/errorHandling.d.ts +65 -0
  87. package/dist/utils/errorHandling.js +268 -0
  88. package/dist/utils/modelChoices.d.ts +82 -0
  89. package/dist/utils/modelChoices.js +401 -0
  90. package/dist/utils/modelDetection.d.ts +9 -0
  91. package/dist/utils/modelDetection.js +80 -0
  92. package/dist/utils/parameterValidation.d.ts +59 -1
  93. package/dist/utils/parameterValidation.js +196 -0
  94. package/dist/utils/schemaConversion.d.ts +12 -0
  95. package/dist/utils/schemaConversion.js +90 -0
  96. package/dist/utils/thinkingConfig.d.ts +108 -0
  97. package/dist/utils/thinkingConfig.js +104 -0
  98. package/dist/utils/tokenUtils.d.ts +124 -0
  99. package/dist/utils/tokenUtils.js +239 -0
  100. package/dist/utils/transformationUtils.js +15 -26
  101. package/package.json +4 -3
@@ -131,7 +131,7 @@ export declare class SageMakerLanguageModel implements LanguageModelV1 {
131
131
  provider: string;
132
132
  specificationVersion: string;
133
133
  endpointName: string;
134
- modelType: "huggingface" | "mistral" | "llama" | "claude" | "jumpstart" | "custom" | undefined;
134
+ modelType: "huggingface" | "mistral" | "custom" | "llama" | "claude" | "jumpstart" | undefined;
135
135
  region: string;
136
136
  };
137
137
  /**
@@ -178,7 +178,7 @@ export declare class SageMakerLanguageModel implements LanguageModelV1 {
178
178
  provider: string;
179
179
  specificationVersion: string;
180
180
  endpointName: string;
181
- modelType: "huggingface" | "mistral" | "llama" | "claude" | "jumpstart" | "custom" | undefined;
181
+ modelType: "huggingface" | "mistral" | "custom" | "llama" | "claude" | "jumpstart" | undefined;
182
182
  region: string;
183
183
  };
184
184
  }
@@ -10,6 +10,10 @@ export type TokenUsage = {
10
10
  input: number;
11
11
  output: number;
12
12
  total: number;
13
+ cacheCreationTokens?: number;
14
+ cacheReadTokens?: number;
15
+ reasoning?: number;
16
+ cacheSavingsPercent?: number;
13
17
  };
14
18
  /**
15
19
  * Error info type for analytics
@@ -60,6 +60,14 @@ export type GenerateCommandArgs = BaseCommandArgs & {
60
60
  maxSteps?: number;
61
61
  /** Output file */
62
62
  output?: string;
63
+ /** Enable extended thinking/reasoning */
64
+ thinking?: boolean;
65
+ /** Token budget for thinking */
66
+ thinkingBudget?: number;
67
+ /** Thinking level for extended reasoning */
68
+ thinkingLevel?: "minimal" | "low" | "medium" | "high";
69
+ /** Vertex AI region */
70
+ region?: string;
63
71
  };
64
72
  /**
65
73
  * Stream command arguments
@@ -79,6 +87,14 @@ export type StreamCommandArgs = BaseCommandArgs & {
79
87
  maxTokens?: number;
80
88
  /** Disable tools */
81
89
  disableTools?: boolean;
90
+ /** Enable extended thinking/reasoning */
91
+ thinking?: boolean;
92
+ /** Token budget for thinking */
93
+ thinkingBudget?: number;
94
+ /** Thinking level for extended reasoning */
95
+ thinkingLevel?: "minimal" | "low" | "medium" | "high";
96
+ /** Vertex AI region */
97
+ region?: string;
82
98
  };
83
99
  /**
84
100
  * Batch command arguments
@@ -1,6 +1,36 @@
1
1
  /**
2
2
  * Conversation Memory Types for NeuroLink
3
3
  * Provides type-safe conversation storage and context management
4
+ *
5
+ * ## Timestamp Conventions
6
+ *
7
+ * NeuroLink uses two timestamp formats throughout the conversation system:
8
+ *
9
+ * ### Unix Milliseconds (number)
10
+ * Used for internal storage, event timestamps, and performance-critical operations.
11
+ * - `SessionMemory.createdAt` - Session creation time as Unix epoch milliseconds
12
+ * - `SessionMemory.lastActivity` - Last activity time as Unix epoch milliseconds
13
+ * - `SessionMemory.lastCountedAt` - Token count timestamp as Unix epoch milliseconds
14
+ * - `ConversationMemoryEvents.*.timestamp` - Event timestamps as Unix epoch milliseconds
15
+ * - `ChatMessage.metadata.timestamp` - Optional numeric timestamp for internal tracking
16
+ *
17
+ * Example: `1735689600000` represents January 1, 2025, 00:00:00 UTC
18
+ *
19
+ * ### ISO 8601 String (string)
20
+ * Used for human-readable fields and API responses.
21
+ * - `ChatMessage.timestamp` - Message timestamp as ISO 8601 string
22
+ * - `ConversationBase.createdAt` - Conversation creation as ISO 8601 string
23
+ * - `ConversationBase.updatedAt` - Last update as ISO 8601 string
24
+ * - `ConversationSummary.firstMessage.timestamp` - Message preview timestamp
25
+ * - `ConversationSummary.lastMessage.timestamp` - Message preview timestamp
26
+ *
27
+ * Example: `"2025-01-01T00:00:00.000Z"`
28
+ *
29
+ * ### Conversion Guidelines
30
+ * - Unix ms to ISO: `new Date(unixMs).toISOString()`
31
+ * - ISO to Unix ms: `new Date(isoString).getTime()`
32
+ * - Current time (Unix ms): `Date.now()`
33
+ * - Current time (ISO): `new Date().toISOString()`
4
34
  */
5
35
  import type { Mem0Config } from "../memory/mem0Initializer.js";
6
36
  /**
@@ -45,9 +75,17 @@ export type SessionMemory = {
45
75
  title?: string;
46
76
  /** Direct message storage - ready for immediate AI consumption */
47
77
  messages: ChatMessage[];
48
- /** When this session was created */
78
+ /**
79
+ * When this session was created.
80
+ * Format: Unix epoch milliseconds (number).
81
+ * Example: 1735689600000 for January 1, 2025, 00:00:00 UTC.
82
+ */
49
83
  createdAt: number;
50
- /** When this session was last active */
84
+ /**
85
+ * When this session was last active.
86
+ * Format: Unix epoch milliseconds (number).
87
+ * Updated on every message addition or session interaction.
88
+ */
51
89
  lastActivity: number;
52
90
  /** Pointer to last summarized message ID (NEW - for token-based memory) */
53
91
  summarizedUpToMessageId?: string;
@@ -88,7 +126,12 @@ export type ChatMessage = {
88
126
  role: "user" | "assistant" | "system" | "tool_call" | "tool_result";
89
127
  /** Content of the message */
90
128
  content: string;
91
- /** Timestamp (ISO string) */
129
+ /**
130
+ * Message timestamp.
131
+ * Format: ISO 8601 string (e.g., "2025-01-01T12:30:00.000Z").
132
+ * Optional - may be omitted for system-generated messages.
133
+ * Use `metadata.timestamp` for numeric Unix ms representation.
134
+ */
92
135
  timestamp?: string;
93
136
  /** Tool name (optional) - for tool_call/tool_result messages */
94
137
  tool?: string;
@@ -112,6 +155,27 @@ export type ChatMessage = {
112
155
  summarizesTo?: string;
113
156
  /** Was this message truncated due to token limits? */
114
157
  truncated?: boolean;
158
+ /** Source of the message (e.g., provider name, user input) */
159
+ source?: string;
160
+ /** Language of the message content */
161
+ language?: string;
162
+ /** Confidence score for AI-generated content */
163
+ confidence?: number;
164
+ /**
165
+ * Numeric timestamp for internal tracking and efficient comparisons.
166
+ * Format: Unix epoch milliseconds (number).
167
+ * Complements the ISO string `ChatMessage.timestamp` field.
168
+ * Use this for sorting, filtering, and performance-critical operations.
169
+ */
170
+ timestamp?: number;
171
+ /** Model used to generate this message */
172
+ modelUsed?: string;
173
+ /** Unique signature identifying thought/reasoning patterns */
174
+ thoughtSignature?: string;
175
+ /** Hash of the thinking/reasoning content for deduplication */
176
+ thoughtHash?: string;
177
+ /** Whether extended thinking was used for this message */
178
+ thinkingExpanded?: boolean;
115
179
  };
116
180
  };
117
181
  /**
@@ -123,10 +187,14 @@ export type { MessageContent, MultimodalChatMessage } from "./multimodal.js";
123
187
  * Events emitted by conversation memory system
124
188
  */
125
189
  export type ConversationMemoryEvents = {
126
- /** Emitted when a new session is created */
190
+ /**
191
+ * Emitted when a new session is created.
192
+ * The timestamp field is Unix epoch milliseconds.
193
+ */
127
194
  "session:created": {
128
195
  sessionId: string;
129
196
  userId?: string;
197
+ /** Event timestamp as Unix epoch milliseconds */
130
198
  timestamp: number;
131
199
  };
132
200
  /** Emitted when a conversation turn is stored */
@@ -1,6 +1,36 @@
1
1
  /**
2
2
  * Conversation Memory Types for NeuroLink
3
3
  * Provides type-safe conversation storage and context management
4
+ *
5
+ * ## Timestamp Conventions
6
+ *
7
+ * NeuroLink uses two timestamp formats throughout the conversation system:
8
+ *
9
+ * ### Unix Milliseconds (number)
10
+ * Used for internal storage, event timestamps, and performance-critical operations.
11
+ * - `SessionMemory.createdAt` - Session creation time as Unix epoch milliseconds
12
+ * - `SessionMemory.lastActivity` - Last activity time as Unix epoch milliseconds
13
+ * - `SessionMemory.lastCountedAt` - Token count timestamp as Unix epoch milliseconds
14
+ * - `ConversationMemoryEvents.*.timestamp` - Event timestamps as Unix epoch milliseconds
15
+ * - `ChatMessage.metadata.timestamp` - Optional numeric timestamp for internal tracking
16
+ *
17
+ * Example: `1735689600000` represents January 1, 2025, 00:00:00 UTC
18
+ *
19
+ * ### ISO 8601 String (string)
20
+ * Used for human-readable fields and API responses.
21
+ * - `ChatMessage.timestamp` - Message timestamp as ISO 8601 string
22
+ * - `ConversationBase.createdAt` - Conversation creation as ISO 8601 string
23
+ * - `ConversationBase.updatedAt` - Last update as ISO 8601 string
24
+ * - `ConversationSummary.firstMessage.timestamp` - Message preview timestamp
25
+ * - `ConversationSummary.lastMessage.timestamp` - Message preview timestamp
26
+ *
27
+ * Example: `"2025-01-01T00:00:00.000Z"`
28
+ *
29
+ * ### Conversion Guidelines
30
+ * - Unix ms to ISO: `new Date(unixMs).toISOString()`
31
+ * - ISO to Unix ms: `new Date(isoString).getTime()`
32
+ * - Current time (Unix ms): `Date.now()`
33
+ * - Current time (ISO): `new Date().toISOString()`
4
34
  */
5
35
  /**
6
36
  * Error types specific to conversation memory
@@ -120,6 +120,54 @@ export type GenerateOptions = {
120
120
  * ```
121
121
  */
122
122
  tts?: TTSOptions;
123
+ /**
124
+ * Thinking/reasoning configuration for extended thinking models
125
+ *
126
+ * Enables extended thinking capabilities for supported models.
127
+ *
128
+ * **Gemini 3 Models** (gemini-3-pro-preview, gemini-3-flash-preview):
129
+ * Use `thinkingLevel` to control reasoning depth:
130
+ * - `minimal` - Near-zero thinking (Flash only)
131
+ * - `low` - Fast reasoning for simple tasks
132
+ * - `medium` - Balanced reasoning/latency
133
+ * - `high` - Maximum reasoning depth (default for Pro)
134
+ *
135
+ * **Anthropic Claude** (claude-3-7-sonnet, etc.):
136
+ * Use `budgetTokens` to set token budget for thinking.
137
+ *
138
+ * @example Gemini 3 with thinking level
139
+ * ```typescript
140
+ * const result = await neurolink.generate({
141
+ * input: { text: "Solve this complex problem..." },
142
+ * provider: "google-ai",
143
+ * model: "gemini-3-pro-preview",
144
+ * thinkingConfig: {
145
+ * thinkingLevel: "high"
146
+ * }
147
+ * });
148
+ * ```
149
+ *
150
+ * @example Anthropic with budget tokens
151
+ * ```typescript
152
+ * const result = await neurolink.generate({
153
+ * input: { text: "Solve this complex math problem..." },
154
+ * provider: "anthropic",
155
+ * model: "claude-3-7-sonnet-20250219",
156
+ * thinkingConfig: {
157
+ * enabled: true,
158
+ * budgetTokens: 10000
159
+ * }
160
+ * });
161
+ * ```
162
+ */
163
+ thinkingConfig?: {
164
+ enabled?: boolean;
165
+ type?: "enabled" | "disabled";
166
+ /** Token budget for thinking (Anthropic models) */
167
+ budgetTokens?: number;
168
+ /** Thinking level for Gemini 3 models: minimal, low, medium, high */
169
+ thinkingLevel?: "minimal" | "low" | "medium" | "high";
170
+ };
123
171
  provider?: AIProviderName | string;
124
172
  model?: string;
125
173
  region?: string;
@@ -408,6 +456,93 @@ export type TextGenerationOptions = {
408
456
  includeHeaders?: boolean;
409
457
  };
410
458
  enableSummarization?: boolean;
459
+ /**
460
+ * ## Extended Thinking Options
461
+ *
462
+ * NeuroLink provides multiple ways to configure extended thinking/reasoning.
463
+ * These options interact as follows:
464
+ *
465
+ * ### Option Hierarchy (Priority: thinkingConfig > individual options)
466
+ *
467
+ * 1. **`thinkingConfig`** (recommended) - Full configuration object, highest priority
468
+ * 2. **`thinking`**, **`thinkingBudget`**, **`thinkingLevel`** - Simplified CLI-friendly options
469
+ *
470
+ * When both are provided, `thinkingConfig` takes precedence. The simplified options
471
+ * are automatically merged into `thinkingConfig` internally.
472
+ *
473
+ * ### Provider-Specific Behavior
474
+ *
475
+ * **Anthropic Claude (claude-3-7-sonnet, etc.):**
476
+ * - Use `thinkingConfig.budgetTokens` or `thinkingBudget`
477
+ * - Range: 5000-100000 tokens
478
+ * - `thinkingLevel` is ignored for Anthropic
479
+ *
480
+ * **Google Gemini 3 (gemini-3-pro-preview, gemini-3-flash-preview):**
481
+ * - Use `thinkingConfig.thinkingLevel` or `thinkingLevel`
482
+ * - Levels: minimal, low, medium, high
483
+ * - `budgetTokens` is ignored for Gemini (uses level-based allocation)
484
+ *
485
+ * ### Option Compatibility Matrix
486
+ *
487
+ * | Option | Anthropic | Gemini 3 | Other Providers |
488
+ * |----------------|-----------|----------|-----------------|
489
+ * | thinking | Yes | Yes | Ignored |
490
+ * | thinkingBudget | Yes | Ignored | Ignored |
491
+ * | thinkingLevel | Ignored | Yes | Ignored |
492
+ * | thinkingConfig | Yes | Yes | Ignored |
493
+ *
494
+ * ### Examples
495
+ *
496
+ * ```typescript
497
+ * // Simplified (CLI-friendly) - Anthropic
498
+ * { thinking: true, thinkingBudget: 10000 }
499
+ *
500
+ * // Simplified (CLI-friendly) - Gemini 3
501
+ * { thinking: true, thinkingLevel: "high" }
502
+ *
503
+ * // Full config (recommended for SDK)
504
+ * { thinkingConfig: { enabled: true, budgetTokens: 10000 } } // Anthropic
505
+ * { thinkingConfig: { thinkingLevel: "high" } } // Gemini 3
506
+ * ```
507
+ */
508
+ /**
509
+ * Enable extended thinking capability (simplified option).
510
+ * Equivalent to `thinkingConfig.enabled = true`.
511
+ * Works with both Anthropic and Gemini 3 models.
512
+ */
513
+ thinking?: boolean;
514
+ /**
515
+ * Token budget for thinking (Anthropic models only).
516
+ * Equivalent to `thinkingConfig.budgetTokens`.
517
+ * Range: 5000-100000 tokens. Ignored for Gemini models.
518
+ */
519
+ thinkingBudget?: number;
520
+ /**
521
+ * Thinking level for Gemini 3 models only.
522
+ * Equivalent to `thinkingConfig.thinkingLevel`.
523
+ * - `minimal` - Near-zero thinking (Flash only)
524
+ * - `low` - Light reasoning
525
+ * - `medium` - Balanced reasoning/latency
526
+ * - `high` - Deep reasoning (Pro default)
527
+ * Ignored for Anthropic models.
528
+ */
529
+ thinkingLevel?: "minimal" | "low" | "medium" | "high";
530
+ /**
531
+ * Full thinking/reasoning configuration (recommended for SDK usage).
532
+ * Takes precedence over simplified options (thinking, thinkingBudget, thinkingLevel).
533
+ *
534
+ * @see Above documentation for provider-specific behavior and option compatibility.
535
+ */
536
+ thinkingConfig?: {
537
+ /** Enable extended thinking. Default: false */
538
+ enabled?: boolean;
539
+ /** Explicit enable/disable type. Alternative to `enabled` boolean. */
540
+ type?: "enabled" | "disabled";
541
+ /** Token budget for thinking (Anthropic: 5000-100000). Ignored for Gemini. */
542
+ budgetTokens?: number;
543
+ /** Thinking level (Gemini 3: minimal|low|medium|high). Ignored for Anthropic. */
544
+ thinkingLevel?: "minimal" | "low" | "medium" | "high";
545
+ };
411
546
  };
412
547
  /**
413
548
  * Text generation result (consolidated from core types)
@@ -0,0 +1,231 @@
1
+ /**
2
+ * Enhanced grounding metadata types for web search and source attribution.
3
+ *
4
+ * This module provides type definitions for grounding AI responses with
5
+ * web search results and source attribution. Grounding helps ensure AI
6
+ * responses are backed by verifiable sources and provides transparency
7
+ * about where information originates.
8
+ *
9
+ * @module groundingTypes
10
+ */
11
+ /**
12
+ * Represents a grounding source with enhanced metadata for search results.
13
+ * Used when grounding responses with web search or retrieval results to
14
+ * provide detailed information about each source that supports the AI response.
15
+ *
16
+ * @example
17
+ * const source: EnhancedGroundingSource = {
18
+ * uri: "https://docs.example.com/api-reference",
19
+ * title: "API Reference Documentation",
20
+ * domain: "docs.example.com",
21
+ * confidenceScore: 0.95,
22
+ * isPrimary: true,
23
+ * chunkIndex: 0
24
+ * };
25
+ */
26
+ export type EnhancedGroundingSource = {
27
+ /** The full URI/URL of the source document */
28
+ uri: string;
29
+ /** The title of the source document or web page */
30
+ title: string;
31
+ /** The domain name extracted from the URI (e.g., "example.com") */
32
+ domain: string;
33
+ /** Confidence score (0-1) indicating how well this source supports the response */
34
+ confidenceScore?: number;
35
+ /** Whether this is a primary source for the grounded response */
36
+ isPrimary?: boolean;
37
+ /** Index of the chunk within the source document that was used */
38
+ chunkIndex?: number;
39
+ };
40
+ /**
41
+ * Represents the support relationship between a text segment and a source.
42
+ * Links a specific source (by index) to the segment it supports with a
43
+ * confidence score indicating the strength of the attribution.
44
+ *
45
+ * @example
46
+ * const support: SegmentSupport = {
47
+ * sourceIndex: 0, // References first source in the sources array
48
+ * confidence: 0.92
49
+ * };
50
+ */
51
+ export type SegmentSupport = {
52
+ /** Index into the sources array identifying which source supports this segment */
53
+ sourceIndex: number;
54
+ /** Confidence score (0-1) for how strongly this source supports the segment */
55
+ confidence: number;
56
+ };
57
+ /**
58
+ * Represents attribution information for a specific segment of the AI response.
59
+ * Maps portions of the generated text to their supporting sources, enabling
60
+ * fine-grained source attribution throughout the response.
61
+ *
62
+ * @example
63
+ * const attribution: SegmentAttribution = {
64
+ * text: "The API supports RESTful operations",
65
+ * startIndex: 0,
66
+ * endIndex: 35,
67
+ * partIndex: 0,
68
+ * supportingSources: [
69
+ * { sourceIndex: 0, confidence: 0.95 },
70
+ * { sourceIndex: 2, confidence: 0.78 }
71
+ * ]
72
+ * };
73
+ */
74
+ export type SegmentAttribution = {
75
+ /** The actual text content of this segment from the response */
76
+ text: string;
77
+ /** Starting character index of this segment in the full response text */
78
+ startIndex: number;
79
+ /** Ending character index of this segment in the full response text */
80
+ endIndex: number;
81
+ /** Index of the response part this segment belongs to (for multi-part responses) */
82
+ partIndex: number;
83
+ /** Array of sources that support this segment with their confidence scores */
84
+ supportingSources: SegmentSupport[];
85
+ };
86
+ /**
87
+ * Represents a search result returned from web search grounding.
88
+ * Contains the essential information from a web search result that
89
+ * can be used to ground and verify AI responses.
90
+ *
91
+ * @example
92
+ * const result: EnhancedSearchResult = {
93
+ * uri: "https://blog.example.com/best-practices",
94
+ * title: "Best Practices Guide",
95
+ * snippet: "This guide covers the essential best practices for..."
96
+ * };
97
+ */
98
+ export type EnhancedSearchResult = {
99
+ /** The full URI/URL of the search result */
100
+ uri: string;
101
+ /** The title of the search result page */
102
+ title: string;
103
+ /** Optional text snippet from the search result showing relevant content */
104
+ snippet?: string;
105
+ };
106
+ /**
107
+ * Comprehensive grounding metadata containing all information about how
108
+ * an AI response is grounded in external sources. This is the primary
109
+ * type used to represent the complete grounding context for a response.
110
+ *
111
+ * @example
112
+ * const metadata: EnhancedGroundingMetadata = {
113
+ * query: "What are the system requirements?",
114
+ * webSearchQueries: ["system requirements documentation"],
115
+ * searchResults: [
116
+ * { uri: "https://docs.example.com/requirements", title: "Requirements" }
117
+ * ],
118
+ * sources: [
119
+ * { uri: "https://docs.example.com/requirements", title: "Requirements", domain: "docs.example.com" }
120
+ * ],
121
+ * averageConfidence: 0.89,
122
+ * grounded: true
123
+ * };
124
+ */
125
+ export type EnhancedGroundingMetadata = {
126
+ /** The original user query that triggered the grounded response */
127
+ query: string;
128
+ /** Array of search queries used to find grounding sources */
129
+ webSearchQueries?: string[];
130
+ /** Array of search results returned from web search */
131
+ searchResults: EnhancedSearchResult[];
132
+ /** Fine-grained attributions mapping response segments to sources */
133
+ segmentAttributions?: SegmentAttribution[];
134
+ /** Array of all sources used to ground the response */
135
+ sources: EnhancedGroundingSource[];
136
+ /** Average confidence score across all grounding attributions (0-1) */
137
+ averageConfidence?: number;
138
+ /** Whether the response is successfully grounded in sources */
139
+ grounded: boolean;
140
+ };
141
+ /**
142
+ * Represents a grounding chunk from raw provider responses.
143
+ * This is the low-level representation of a grounding source chunk
144
+ * as returned directly from AI providers like Google Vertex AI.
145
+ *
146
+ * @example
147
+ * const chunk: GroundingChunk = {
148
+ * web: {
149
+ * uri: "https://example.com/article",
150
+ * title: "Relevant Article"
151
+ * },
152
+ * confidenceScore: 0.87
153
+ * };
154
+ */
155
+ export type GroundingChunk = {
156
+ /** Web source information for this grounding chunk */
157
+ web?: {
158
+ /** The URI of the web source */
159
+ uri?: string;
160
+ /** The title of the web source */
161
+ title?: string;
162
+ };
163
+ /** Confidence score for this grounding chunk (0-1) */
164
+ confidenceScore?: number;
165
+ };
166
+ /**
167
+ * Represents grounding support information from raw provider responses.
168
+ * Contains segment information and links to the grounding chunks that
169
+ * support that segment, as returned directly from AI providers.
170
+ *
171
+ * @example
172
+ * const support: GroundingSupport = {
173
+ * segment: {
174
+ * text: "The feature was released in 2024",
175
+ * startIndex: 0,
176
+ * endIndex: 32,
177
+ * partIndex: 0
178
+ * },
179
+ * groundingChunkIndices: [0, 1],
180
+ * confidenceScores: [0.92, 0.85]
181
+ * };
182
+ */
183
+ export type GroundingSupport = {
184
+ /** The text segment that is being grounded */
185
+ segment?: {
186
+ /** The text content of the segment */
187
+ text?: string;
188
+ /** Starting character index in the response */
189
+ startIndex?: number;
190
+ /** Ending character index in the response */
191
+ endIndex?: number;
192
+ /** Index of the response part this segment belongs to */
193
+ partIndex?: number;
194
+ };
195
+ /** Indices into the groundingChunks array that support this segment */
196
+ groundingChunkIndices?: number[];
197
+ /** Confidence scores corresponding to each grounding chunk index */
198
+ confidenceScores?: number[];
199
+ };
200
+ /**
201
+ * Raw grounding metadata as returned directly from AI providers.
202
+ * This is the unprocessed format that gets transformed into
203
+ * EnhancedGroundingMetadata for consistent consumption across the SDK.
204
+ *
205
+ * @example
206
+ * const rawMetadata: RawGroundingMetadata = {
207
+ * webSearchQueries: ["neurolink documentation"],
208
+ * searchEntryPoint: {
209
+ * renderedContent: "<div>Search results widget HTML</div>"
210
+ * },
211
+ * groundingChunks: [
212
+ * { web: { uri: "https://docs.neurolink.dev", title: "NeuroLink Docs" } }
213
+ * ],
214
+ * groundingSupports: [
215
+ * { segment: { text: "NeuroLink is..." }, groundingChunkIndices: [0] }
216
+ * ]
217
+ * };
218
+ */
219
+ export type RawGroundingMetadata = {
220
+ /** Array of search queries used by the provider for web grounding */
221
+ webSearchQueries?: string[];
222
+ /** Search entry point with rendered HTML content for display */
223
+ searchEntryPoint?: {
224
+ /** HTML content that can be rendered to show search results */
225
+ renderedContent?: string;
226
+ };
227
+ /** Array of grounding chunks from the provider */
228
+ groundingChunks?: GroundingChunk[];
229
+ /** Array of grounding support information linking segments to chunks */
230
+ groundingSupports?: GroundingSupport[];
231
+ };
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Enhanced grounding metadata types for web search and source attribution.
3
+ *
4
+ * This module provides type definitions for grounding AI responses with
5
+ * web search results and source attribution. Grounding helps ensure AI
6
+ * responses are backed by verifiable sources and provides transparency
7
+ * about where information originates.
8
+ *
9
+ * @module groundingTypes
10
+ */
11
+ export {};
12
+ //# sourceMappingURL=groundingTypes.js.map
@@ -432,6 +432,29 @@ export type GenAILiveSession = {
432
432
  }) => Promise<void> | void;
433
433
  close?: (code?: number, reason?: string) => Promise<void> | void;
434
434
  };
435
+ /**
436
+ * Google AI generateContentStream response chunk
437
+ */
438
+ export type GenAIStreamChunk = {
439
+ text?: string;
440
+ functionCalls?: Array<{
441
+ name: string;
442
+ args: Record<string, unknown>;
443
+ }>;
444
+ };
445
+ /**
446
+ * Google AI models API interface
447
+ */
448
+ export type GenAIModelsAPI = {
449
+ generateContentStream: (params: {
450
+ model: string;
451
+ contents: Array<{
452
+ role: string;
453
+ parts: unknown[];
454
+ }>;
455
+ config?: Record<string, unknown>;
456
+ }) => Promise<AsyncIterable<GenAIStreamChunk>>;
457
+ };
435
458
  /**
436
459
  * Google AI client interface
437
460
  */
@@ -439,12 +462,18 @@ export type GenAIClient = {
439
462
  live: {
440
463
  connect: (config: LiveConnectConfig) => Promise<GenAILiveSession>;
441
464
  };
465
+ models: GenAIModelsAPI;
442
466
  };
443
467
  /**
444
468
  * Google GenAI constructor type
469
+ * Supports both API key (Google AI Studio) and Vertex AI configurations
445
470
  */
446
471
  export type GoogleGenAIClass = new (cfg: {
447
472
  apiKey: string;
473
+ } | {
474
+ vertexai: boolean;
475
+ project: string;
476
+ location: string;
448
477
  }) => GenAIClient;
449
478
  /**
450
479
  * OpenAI-compatible models endpoint response structure