@nextsparkjs/plugin-langchain 0.1.0-beta.68 → 0.1.0-beta.73

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/.env.example CHANGED
@@ -1,41 +1,73 @@
1
- # ===========================================
2
- # LangChain Plugin Configuration
3
- # ===========================================
1
+ # ============================================
2
+ # LANGCHAIN PLUGIN CONFIGURATION
3
+ # ============================================
4
+ #
5
+ # Copy this file to .env and configure your LangChain settings
6
+ # This file is loaded automatically by the LangChain plugin
7
+ #
8
+ # Priority: Plugin .env > Root .env > Defaults
9
+ #
10
+ # ============================================
4
11
 
12
+ # ===========================
5
13
  # Plugin Settings
14
+ # ===========================
15
+
16
+ # Enable/disable the LangChain plugin
6
17
  LANGCHAIN_PLUGIN_ENABLED=true
18
+
19
+ # Enable debug logging for development
7
20
  LANGCHAIN_PLUGIN_DEBUG=false
8
21
 
9
- # File Logging (core environment variable)
10
- # Logs to logger/ai/ when enabled
22
+ # Enable file logging (logs to logger/ai/)
11
23
  LOG_ENABLED=false
12
24
 
13
- # ===========================================
25
+ # ===========================
14
26
  # Ollama Configuration (Local)
15
- # ===========================================
16
- # Used by: single-agent
27
+ # ===========================
17
28
  # No API key required - runs locally
29
+ # Install Ollama: https://ollama.ai/download
30
+ # Pull a model: ollama pull llama3.2:3b
18
31
 
19
32
  # Ollama server URL
20
33
  LANGCHAIN_OLLAMA_BASE_URL=http://localhost:11434
21
34
 
22
- # Model to use (run `ollama list` to see available models)
35
+ # Default model (run `ollama list` to see available models)
23
36
  LANGCHAIN_OLLAMA_MODEL=llama3.2:3b
24
37
 
25
- # ===========================================
26
- # OpenAI-compatible Configuration (LM Studio)
27
- # ===========================================
28
- # Used by: orchestrator, task-assistant, customer-assistant, page-assistant
29
- #
30
- # LM Studio provides an OpenAI-compatible API on localhost.
31
- # 1. Start LM Studio and load a model
32
- # 2. Start the local server (default: http://localhost:1234/v1)
38
+ # ===========================
39
+ # OpenAI Configuration
40
+ # ===========================
41
+ # Get your key from: https://platform.openai.com/api-keys
42
+
43
+ # OpenAI API Key
44
+ OPENAI_API_KEY=your-openai-key-here
45
+
46
+ # Default model for OpenAI provider
47
+ LANGCHAIN_OPENAI_MODEL=gpt-4o-mini
48
+
49
+ # OpenAI-compatible base URL (for LM Studio, local servers)
50
+ # LM Studio: http://localhost:1234/v1
51
+ # Leave empty for official OpenAI API
52
+ # LANGCHAIN_OPENAI_BASE_URL=http://localhost:1234/v1
53
+
54
+ # ===========================
55
+ # Anthropic Configuration
56
+ # ===========================
57
+ # Get your key from: https://console.anthropic.com/
58
+
59
+ # Anthropic API Key
60
+ ANTHROPIC_API_KEY=your-anthropic-key-here
61
+
62
+ # Default model for Anthropic provider
63
+ LANGCHAIN_ANTHROPIC_MODEL=claude-3-5-sonnet-20241022
33
64
 
34
- # LM Studio server URL
35
- LANGCHAIN_OPENAI_BASE_URL=http://localhost:1234/v1
65
+ # ===========================
66
+ # Feature Flags
67
+ # ===========================
36
68
 
37
- # Model name as loaded in LM Studio
38
- LANGCHAIN_OPENAI_MODEL=your-loaded-model-name
69
+ # Enable graph-based orchestrator (recommended for multi-agent)
70
+ LANGCHAIN_USE_GRAPH_ORCHESTRATOR=true
39
71
 
40
- # API Key (LM Studio doesn't require a real key, use any string)
41
- OPENAI_API_KEY=lm-studio
72
+ # Enable verbose debug output
73
+ LANGCHAIN_DEBUG=false
@@ -687,6 +687,53 @@ Configure how structured output works for multi-provider compatibility:
687
687
 
688
688
  ## Environment Variables
689
689
 
690
+ ### ⭐ Plugin-Level Environment Configuration (Recommended)
691
+
692
+ The LangChain plugin supports **plugin-level `.env` files** that take priority over root environment variables. This provides isolation and modularity for your AI configuration.
693
+
694
+ #### Setup
695
+
696
+ 1. **Copy the example file:**
697
+ ```bash
698
+ cp contents/plugins/langchain/.env.example contents/plugins/langchain/.env
699
+ ```
700
+
701
+ 2. **Configure your settings:**
702
+ ```env
703
+ # Plugin Settings
704
+ LANGCHAIN_PLUGIN_ENABLED=true
705
+ LANGCHAIN_PLUGIN_DEBUG=false
706
+
707
+ # Ollama Configuration (Local)
708
+ LANGCHAIN_OLLAMA_BASE_URL=http://localhost:11434
709
+ LANGCHAIN_OLLAMA_MODEL=llama3.2:3b
710
+
711
+ # OpenAI Configuration (LM Studio or OpenAI API)
712
+ LANGCHAIN_OPENAI_BASE_URL=http://localhost:1234/v1
713
+ LANGCHAIN_OPENAI_MODEL=gpt-4o-mini
714
+ OPENAI_API_KEY=your-api-key
715
+ ```
716
+
717
+ #### Priority System
718
+
719
+ The plugin environment loader uses this priority:
720
+
721
+ 1. **Plugin `.env`** (`contents/plugins/langchain/.env`) - Highest priority
722
+ 2. **Root `.env`** (`/.env`) - Fallback for variables not in plugin .env
723
+ 3. **Built-in defaults** - Lowest priority
724
+
725
+ This means you can:
726
+ - Keep API keys in the root `.env` (shared across plugins)
727
+ - Override specific settings in the plugin `.env` (isolated configuration)
728
+
729
+ #### Benefits
730
+
731
+ - ✅ **Isolation**: LangChain config doesn't pollute root `.env`
732
+ - ✅ **Modularity**: Each plugin manages its own environment
733
+ - ✅ **Security**: API keys can be scoped to specific plugins
734
+ - ✅ **Flexibility**: Different configurations for different plugins
735
+ - ✅ **Fallback**: Automatically uses root `.env` when plugin `.env` doesn't define a variable
736
+
690
737
  ### Provider Configuration
691
738
 
692
739
  ```env
@@ -0,0 +1,180 @@
1
+ /**
2
+ * LangChain Plugin Environment Configuration (Server-Only)
3
+ *
4
+ * Uses centralized plugin environment loader from core
5
+ * Provides type-safe access to LangChain configuration
6
+ */
7
+
8
+ import { getPluginEnv } from '@nextsparkjs/core/lib/plugins/env-loader'
9
+
10
+ interface LangChainPluginEnvConfig {
11
+ // Plugin settings
12
+ LANGCHAIN_PLUGIN_ENABLED?: string
13
+ LANGCHAIN_PLUGIN_DEBUG?: string
14
+ LOG_ENABLED?: string
15
+
16
+ // Ollama Configuration
17
+ LANGCHAIN_OLLAMA_BASE_URL?: string
18
+ LANGCHAIN_OLLAMA_MODEL?: string
19
+
20
+ // OpenAI Configuration
21
+ LANGCHAIN_OPENAI_BASE_URL?: string
22
+ LANGCHAIN_OPENAI_MODEL?: string
23
+ OPENAI_API_KEY?: string
24
+
25
+ // Anthropic Configuration
26
+ LANGCHAIN_ANTHROPIC_MODEL?: string
27
+ ANTHROPIC_API_KEY?: string
28
+
29
+ // Feature Flags
30
+ LANGCHAIN_USE_GRAPH_ORCHESTRATOR?: string
31
+ LANGCHAIN_DEBUG?: string
32
+ }
33
+
34
+ class PluginEnvironment {
35
+ private static instance: PluginEnvironment
36
+ private config: LangChainPluginEnvConfig = {}
37
+ private loaded = false
38
+
39
+ private constructor() {
40
+ this.loadEnvironment()
41
+ }
42
+
43
+ public static getInstance(): PluginEnvironment {
44
+ if (!PluginEnvironment.instance) {
45
+ PluginEnvironment.instance = new PluginEnvironment()
46
+ }
47
+ return PluginEnvironment.instance
48
+ }
49
+
50
+ private loadEnvironment(forceReload: boolean = false): void {
51
+ if (this.loaded && !forceReload) return
52
+
53
+ try {
54
+ // Use centralized plugin env loader
55
+ const env = getPluginEnv('langchain')
56
+
57
+ this.config = {
58
+ // Plugin settings
59
+ LANGCHAIN_PLUGIN_ENABLED: env.LANGCHAIN_PLUGIN_ENABLED || 'true',
60
+ LANGCHAIN_PLUGIN_DEBUG: env.LANGCHAIN_PLUGIN_DEBUG || 'false',
61
+ LOG_ENABLED: env.LOG_ENABLED || 'false',
62
+
63
+ // Ollama Configuration
64
+ LANGCHAIN_OLLAMA_BASE_URL: env.LANGCHAIN_OLLAMA_BASE_URL || 'http://localhost:11434',
65
+ LANGCHAIN_OLLAMA_MODEL: env.LANGCHAIN_OLLAMA_MODEL || 'llama3.2:3b',
66
+
67
+ // OpenAI Configuration
68
+ LANGCHAIN_OPENAI_BASE_URL: env.LANGCHAIN_OPENAI_BASE_URL,
69
+ LANGCHAIN_OPENAI_MODEL: env.LANGCHAIN_OPENAI_MODEL || 'gpt-4o-mini',
70
+ OPENAI_API_KEY: env.OPENAI_API_KEY,
71
+
72
+ // Anthropic Configuration
73
+ LANGCHAIN_ANTHROPIC_MODEL: env.LANGCHAIN_ANTHROPIC_MODEL || 'claude-3-5-sonnet-20241022',
74
+ ANTHROPIC_API_KEY: env.ANTHROPIC_API_KEY,
75
+
76
+ // Feature Flags
77
+ LANGCHAIN_USE_GRAPH_ORCHESTRATOR: env.LANGCHAIN_USE_GRAPH_ORCHESTRATOR || 'true',
78
+ LANGCHAIN_DEBUG: env.LANGCHAIN_DEBUG || 'false',
79
+ }
80
+
81
+ this.logLoadedConfiguration()
82
+ this.loaded = true
83
+ } catch (error) {
84
+ console.error('[LangChain Plugin] Failed to load environment:', error)
85
+ this.loaded = true
86
+ }
87
+ }
88
+
89
+ private logLoadedConfiguration(): void {
90
+ if (process.env.NODE_ENV === 'development' && this.config.LANGCHAIN_PLUGIN_DEBUG === 'true') {
91
+ console.log('[LangChain Plugin] Environment Configuration:')
92
+ console.log(' → Plugin Settings:')
93
+ console.log(` - LANGCHAIN_PLUGIN_ENABLED: ${this.config.LANGCHAIN_PLUGIN_ENABLED}`)
94
+ console.log(` - LANGCHAIN_PLUGIN_DEBUG: ${this.config.LANGCHAIN_PLUGIN_DEBUG}`)
95
+ console.log(' → Ollama Configuration:')
96
+ console.log(` - LANGCHAIN_OLLAMA_BASE_URL: ${this.config.LANGCHAIN_OLLAMA_BASE_URL}`)
97
+ console.log(` - LANGCHAIN_OLLAMA_MODEL: ${this.config.LANGCHAIN_OLLAMA_MODEL}`)
98
+ console.log(' → OpenAI Configuration:')
99
+ console.log(` - LANGCHAIN_OPENAI_BASE_URL: ${this.config.LANGCHAIN_OPENAI_BASE_URL || 'not set'}`)
100
+ console.log(` - LANGCHAIN_OPENAI_MODEL: ${this.config.LANGCHAIN_OPENAI_MODEL}`)
101
+ console.log(` - OPENAI_API_KEY: ${this.config.OPENAI_API_KEY ? '✓ set' : '✗ not set'}`)
102
+ console.log(' → Anthropic Configuration:')
103
+ console.log(` - LANGCHAIN_ANTHROPIC_MODEL: ${this.config.LANGCHAIN_ANTHROPIC_MODEL}`)
104
+ console.log(` - ANTHROPIC_API_KEY: ${this.config.ANTHROPIC_API_KEY ? '✓ set' : '✗ not set'}`)
105
+ console.log()
106
+ }
107
+ }
108
+
109
+ public getConfig(): LangChainPluginEnvConfig {
110
+ if (!this.loaded) {
111
+ this.loadEnvironment()
112
+ }
113
+ return this.config
114
+ }
115
+
116
+ // Helper methods
117
+ public isPluginEnabled(): boolean {
118
+ return this.getConfig().LANGCHAIN_PLUGIN_ENABLED !== 'false'
119
+ }
120
+
121
+ public isDebugEnabled(): boolean {
122
+ return this.getConfig().LANGCHAIN_PLUGIN_DEBUG === 'true' || this.getConfig().LANGCHAIN_DEBUG === 'true'
123
+ }
124
+
125
+ public isLogEnabled(): boolean {
126
+ return this.getConfig().LOG_ENABLED === 'true'
127
+ }
128
+
129
+ public getOllamaBaseUrl(): string {
130
+ return this.getConfig().LANGCHAIN_OLLAMA_BASE_URL || 'http://localhost:11434'
131
+ }
132
+
133
+ public getOllamaModel(): string {
134
+ return this.getConfig().LANGCHAIN_OLLAMA_MODEL || 'llama3.2:3b'
135
+ }
136
+
137
+ public getOpenAIBaseUrl(): string | undefined {
138
+ return this.getConfig().LANGCHAIN_OPENAI_BASE_URL
139
+ }
140
+
141
+ public getOpenAIModel(): string {
142
+ return this.getConfig().LANGCHAIN_OPENAI_MODEL || 'gpt-4o-mini'
143
+ }
144
+
145
+ public getOpenAIApiKey(): string | undefined {
146
+ return this.getConfig().OPENAI_API_KEY
147
+ }
148
+
149
+ public getAnthropicModel(): string {
150
+ return this.getConfig().LANGCHAIN_ANTHROPIC_MODEL || 'claude-3-5-sonnet-20241022'
151
+ }
152
+
153
+ public getAnthropicApiKey(): string | undefined {
154
+ return this.getConfig().ANTHROPIC_API_KEY
155
+ }
156
+
157
+ public isGraphOrchestratorEnabled(): boolean {
158
+ return this.getConfig().LANGCHAIN_USE_GRAPH_ORCHESTRATOR === 'true'
159
+ }
160
+
161
+ public reload(): void {
162
+ this.loaded = false
163
+ this.loadEnvironment(true)
164
+ }
165
+ }
166
+
167
+ export const pluginEnv = PluginEnvironment.getInstance()
168
+
169
+ // Convenience exports
170
+ export const isPluginEnabled = () => pluginEnv.isPluginEnabled()
171
+ export const isDebugEnabled = () => pluginEnv.isDebugEnabled()
172
+ export const isLogEnabled = () => pluginEnv.isLogEnabled()
173
+ export const getOllamaBaseUrl = () => pluginEnv.getOllamaBaseUrl()
174
+ export const getOllamaModel = () => pluginEnv.getOllamaModel()
175
+ export const getOpenAIBaseUrl = () => pluginEnv.getOpenAIBaseUrl()
176
+ export const getOpenAIModel = () => pluginEnv.getOpenAIModel()
177
+ export const getOpenAIApiKey = () => pluginEnv.getOpenAIApiKey()
178
+ export const getAnthropicModel = () => pluginEnv.getAnthropicModel()
179
+ export const getAnthropicApiKey = () => pluginEnv.getAnthropicApiKey()
180
+ export const isGraphOrchestratorEnabled = () => pluginEnv.isGraphOrchestratorEnabled()
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "@nextsparkjs/plugin-langchain",
3
- "version": "0.1.0-beta.68",
3
+ "version": "0.1.0-beta.73",
4
4
  "private": false,
5
5
  "main": "./plugin.config.ts",
6
6
  "requiredPlugins": [],
7
7
  "dependencies": {
8
- "@anthropic-ai/sdk": "^0.36.0",
8
+ "@anthropic-ai/sdk": "^0.71.0",
9
9
  "@langchain/anthropic": "^0.3.0",
10
10
  "@langchain/community": "^0.3.0",
11
11
  "@langchain/core": "^0.3.0",
@@ -16,17 +16,17 @@
16
16
  "langchain": "^0.3.0"
17
17
  },
18
18
  "peerDependencies": {
19
+ "@nextsparkjs/core": "workspace:*",
19
20
  "@tanstack/react-query": "^5.0.0",
20
21
  "lucide-react": "^0.539.0",
21
22
  "next": "^15.0.0",
22
23
  "next-intl": "^4.0.0",
23
24
  "react": "^19.0.0",
24
25
  "react-dom": "^19.0.0",
25
- "zod": "^4.0.0",
26
- "@nextsparkjs/core": "0.1.0-beta.68"
26
+ "zod": "^4.0.0"
27
27
  },
28
28
  "nextspark": {
29
29
  "type": "plugin",
30
30
  "name": "langchain"
31
31
  }
32
- }
32
+ }
package/LICENSE DELETED
@@ -1,21 +0,0 @@
1
- MIT License
2
-
3
- Copyright (c) 2025 NextSpark
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.