glitool 2.0.0 → 2.0.1
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/agent.js +2 -1
- package/dist/llm/factory.js +16 -8
- package/package.json +1 -1
package/dist/agent.js
CHANGED
|
@@ -20,7 +20,7 @@ import { runDebugger } from "./agents/debugger.js";
|
|
|
20
20
|
import { runRefactorer } from "./agents/refactorer.js";
|
|
21
21
|
import { runGitAgent } from "./agents/git-agent.js";
|
|
22
22
|
import { ToolMessage } from "@langchain/core/messages";
|
|
23
|
-
import { makeLlm } from './llm/factory.js';
|
|
23
|
+
import { makeLlm, startNewRequest } from './llm/factory.js';
|
|
24
24
|
const __filename = fileURLToPath(import.meta.url);
|
|
25
25
|
const __dirname = dirname(__filename);
|
|
26
26
|
loadEnv({ path: join(os.homedir(), '.glitool', '.env') });
|
|
@@ -172,6 +172,7 @@ function extractTarget(args) {
|
|
|
172
172
|
return String(first ?? '');
|
|
173
173
|
}
|
|
174
174
|
export async function chat(userInput, onToolCall, onStatus, onToken, onEscalation, onUsage, onStageEvent) {
|
|
175
|
+
startNewRequest();
|
|
175
176
|
const decision = await route(userInput, sessionMessages.slice(-6));
|
|
176
177
|
logRouting(userInput, decision);
|
|
177
178
|
const cleanedInput = decision.source === 'explicit' ? stripExplicitPrefix(userInput) : userInput;
|
package/dist/llm/factory.js
CHANGED
|
@@ -1,9 +1,16 @@
|
|
|
1
1
|
import { ChatOpenAI } from '@langchain/openai';
|
|
2
|
+
import { randomUUID } from 'crypto';
|
|
2
3
|
import { getAuthToken, getOrCreateAnonId } from '../auth.js';
|
|
3
|
-
// const BACKEND_URL = process.env.GLITOOL_BACKEND ?? 'http://localhost:3000';
|
|
4
4
|
const BACKEND_URL = process.env.GLITOOL_BACKEND ?? 'https://api.glit.in';
|
|
5
|
+
let currentRequestId = null;
|
|
6
|
+
export function startNewRequest() {
|
|
7
|
+
currentRequestId = randomUUID();
|
|
8
|
+
return currentRequestId;
|
|
9
|
+
}
|
|
10
|
+
function requestIdHeader() {
|
|
11
|
+
return currentRequestId ? { 'X-Glitool-Request-ID': currentRequestId } : {};
|
|
12
|
+
}
|
|
5
13
|
export function makeLlm(model, extras = {}) {
|
|
6
|
-
// BYOK: local key bypasses the Glitool backend entirely
|
|
7
14
|
if (process.env.OPENAI_API_KEY) {
|
|
8
15
|
return new ChatOpenAI({ model, apiKey: process.env.OPENAI_API_KEY, ...extras });
|
|
9
16
|
}
|
|
@@ -12,17 +19,19 @@ export function makeLlm(model, extras = {}) {
|
|
|
12
19
|
return new ChatOpenAI({
|
|
13
20
|
model,
|
|
14
21
|
apiKey: token,
|
|
15
|
-
configuration: {
|
|
22
|
+
configuration: {
|
|
23
|
+
baseURL: `${BACKEND_URL}/v1`,
|
|
24
|
+
defaultHeaders: requestIdHeader(),
|
|
25
|
+
},
|
|
16
26
|
...extras,
|
|
17
27
|
});
|
|
18
28
|
}
|
|
19
|
-
// Anonymous trial — backend validates via X-Anon-ID header
|
|
20
29
|
return new ChatOpenAI({
|
|
21
30
|
model,
|
|
22
31
|
apiKey: 'anon',
|
|
23
32
|
configuration: {
|
|
24
33
|
baseURL: `${BACKEND_URL}/v1`,
|
|
25
|
-
defaultHeaders: { 'X-Anon-ID': getOrCreateAnonId() },
|
|
34
|
+
defaultHeaders: { 'X-Anon-ID': getOrCreateAnonId(), ...requestIdHeader() },
|
|
26
35
|
},
|
|
27
36
|
...extras,
|
|
28
37
|
});
|
|
@@ -32,9 +41,7 @@ export function makeInternalLlm(model, extras = {}) {
|
|
|
32
41
|
return new ChatOpenAI({ model, apiKey: process.env.OPENAI_API_KEY, ...extras });
|
|
33
42
|
}
|
|
34
43
|
const token = getAuthToken();
|
|
35
|
-
const anonHeaders = token
|
|
36
|
-
? {}
|
|
37
|
-
: { 'X-Anon-ID': getOrCreateAnonId() };
|
|
44
|
+
const anonHeaders = token ? {} : { 'X-Anon-ID': getOrCreateAnonId() };
|
|
38
45
|
return new ChatOpenAI({
|
|
39
46
|
model,
|
|
40
47
|
apiKey: token ?? 'anon',
|
|
@@ -43,6 +50,7 @@ export function makeInternalLlm(model, extras = {}) {
|
|
|
43
50
|
defaultHeaders: {
|
|
44
51
|
...anonHeaders,
|
|
45
52
|
'X-Glitool-Internal': 'true',
|
|
53
|
+
...requestIdHeader(),
|
|
46
54
|
},
|
|
47
55
|
},
|
|
48
56
|
...extras,
|