pi-harness-runtime 1.1.152 → 1.1.154
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/harness/langchain/graph.ts +9 -9
- package/harness/langchain/{jev-logger.ts → planner-logger.ts} +25 -24
- package/harness/service-diagnostics.ts +217 -0
- package/index.ts +113 -9
- package/package.json +1 -1
- package/packages/a2a-adapter/package.json +1 -1
- package/packages/agent-policy/package.json +1 -1
- package/packages/architecture-generator/package.json +1 -1
- package/packages/auth/package.json +1 -1
- package/packages/autonomous-refactor/package.json +1 -1
- package/packages/autonomous-runtime/package.json +1 -1
- package/packages/cache-strategy/package.json +1 -1
- package/packages/capability-registry/package.json +1 -1
- package/packages/checkpoint/package.json +1 -1
- package/packages/cli-plugin-sdk/package.json +1 -1
- package/packages/clipboard/package.json +1 -1
- package/packages/clipboard-plugin/package.json +1 -1
- package/packages/code-generation/package.json +1 -1
- package/packages/code-review/package.json +1 -1
- package/packages/codex-adapter/package.json +1 -1
- package/packages/codex-watcher/package.json +1 -1
- package/packages/config-capture/package.json +1 -1
- package/packages/context-compiler/package.json +1 -1
- package/packages/context-discovery/package.json +1 -1
- package/packages/context-manager/package.json +1 -1
- package/packages/cookie-sanitizer/package.json +1 -1
- package/packages/cost-optimizer/package.json +1 -1
- package/packages/dependency-analyzer/package.json +1 -1
- package/packages/django-plugin/package.json +1 -1
- package/packages/doc-generator/package.json +1 -1
- package/packages/evaluation-engine/package.json +1 -1
- package/packages/evaluation-runner/package.json +1 -1
- package/packages/event-bus/package.json +1 -1
- package/packages/event-store/package.json +1 -1
- package/packages/experience-replay/package.json +1 -1
- package/packages/feedback-collector/package.json +1 -1
- package/packages/file-copy-helper/package.json +1 -1
- package/packages/framework-detector/package.json +1 -1
- package/packages/framework-plugin-sdk/package.json +1 -1
- package/packages/frappe-plugin/package.json +1 -1
- package/packages/generic-web-plugin/package.json +1 -1
- package/packages/health-monitor/package.json +1 -1
- package/packages/intent-analyzer/package.json +1 -1
- package/packages/jev-judge/dist/index.d.ts +14 -3
- package/packages/jev-judge/dist/index.d.ts.map +1 -1
- package/packages/jev-judge/dist/index.js +54 -12
- package/packages/jev-judge/dist/index.js.map +1 -1
- package/packages/jev-judge/dist/typesafe-provider.d.ts +66 -0
- package/packages/jev-judge/dist/typesafe-provider.d.ts.map +1 -0
- package/packages/jev-judge/dist/typesafe-provider.js +220 -0
- package/packages/jev-judge/dist/typesafe-provider.js.map +1 -0
- package/packages/jev-judge/package.json +1 -1
- package/packages/jev-judge/src/index.ts +58 -12
- package/packages/jev-judge/src/typesafe-provider.ts +335 -0
- package/packages/knowledge-graph/package.json +1 -1
- package/packages/knowledge-retrieval/package.json +1 -1
- package/packages/laravel-plugin/package.json +1 -1
- package/packages/learning-engine/package.json +1 -1
- package/packages/mcp-adapter/package.json +1 -1
- package/packages/memory-engine/package.json +1 -1
- package/packages/milestone-manager/package.json +1 -1
- package/packages/model-registry/package.json +1 -1
- package/packages/nextjs-plugin/package.json +1 -1
- package/packages/notification/package.json +1 -1
- package/packages/observability/package.json +1 -1
- package/packages/okf-indexer/package.json +1 -1
- package/packages/paperclip-integration/package.json +1 -1
- package/packages/performance-optimizer/package.json +1 -1
- package/packages/privilege-broker/package.json +1 -1
- package/packages/project-analyzer/package.json +1 -1
- package/packages/project-bootstrap/package.json +1 -1
- package/packages/projection-engine/package.json +1 -1
- package/packages/prompt-compiler/package.json +1 -1
- package/packages/prompt-versioning/package.json +1 -1
- package/packages/provider-adapter-sdk/package.json +1 -1
- package/packages/provider-router/package.json +1 -1
- package/packages/provider-selector/package.json +1 -1
- package/packages/providers/package.json +1 -1
- package/packages/qdrant-skills/dist/client.d.ts.map +1 -1
- package/packages/qdrant-skills/dist/client.js +4 -3
- package/packages/qdrant-skills/dist/client.js.map +1 -1
- package/packages/qdrant-skills/package.json +1 -1
- package/packages/qdrant-skills/src/client.ts +14 -17
- package/packages/quota-manager/package.json +1 -1
- package/packages/rate-limiter/package.json +1 -1
- package/packages/react-vite-plugin/package.json +1 -1
- package/packages/release-manager/package.json +1 -1
- package/packages/requirement-compiler/package.json +1 -1
- package/packages/runtime/package.json +1 -1
- package/packages/scheduler/package.json +1 -1
- package/packages/scheduler-adapter/package.json +1 -1
- package/packages/session/package.json +1 -1
- package/packages/session-api/package.json +1 -1
- package/packages/session-export/package.json +1 -1
- package/packages/shared-context/package.json +1 -1
- package/packages/skill-mcp-client/package.json +1 -1
- package/packages/skill-registry/package.json +1 -1
- package/packages/skills/dist/loader.d.ts +9 -2
- package/packages/skills/dist/loader.d.ts.map +1 -1
- package/packages/skills/dist/loader.js +24 -7
- package/packages/skills/dist/loader.js.map +1 -1
- package/packages/skills/package.json +1 -1
- package/packages/skills/src/loader.ts +27 -7
- package/packages/sprint-planner/package.json +1 -1
- package/packages/subscription-engine/package.json +1 -1
- package/packages/task-compiler/package.json +1 -1
- package/packages/tencentdb-memory/package.json +1 -1
- package/packages/tencentdb-sync/package.json +1 -1
- package/packages/test-data-generator/package.json +1 -1
- package/packages/test-generator/package.json +1 -1
- package/packages/todo-bd-sync/package.json +1 -1
- package/packages/token-estimation/package.json +1 -1
- package/packages/token-optimizer/package.json +1 -1
- package/packages/trajectory/package.json +1 -1
- package/packages/tui/package.json +1 -1
- package/packages/types/package.json +1 -1
- package/packages/workflow-events/package.json +1 -1
- package/packages/workspace-scanner/package.json +1 -1
- package/packages/worktree/package.json +1 -1
- package/packages/write-review/package.json +1 -1
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TypeSafe Jev Provider - Direct API integration
|
|
3
|
+
*
|
|
4
|
+
* Uses TypeSafe's /v1/systemone endpoint directly.
|
|
5
|
+
* This is the recommended provider for Jev decisions.
|
|
6
|
+
*
|
|
7
|
+
* API: POST https://api.typesafe.ai/v1/systemone
|
|
8
|
+
* Auth: Bearer token (TYPESAFE_API_KEY)
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* Default configuration
|
|
12
|
+
*/
|
|
13
|
+
const DEFAULT_CONFIG = {
|
|
14
|
+
baseUrl: "https://api.typesafe.ai",
|
|
15
|
+
timeoutMs: 30000,
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* TypeSafe Jev Judge - Direct TypeSafe API integration
|
|
19
|
+
*
|
|
20
|
+
* Uses TypeSafe's systemone API for structured decisions.
|
|
21
|
+
* More reliable than OpenRouter proxy and supports full feature set.
|
|
22
|
+
*/
|
|
23
|
+
export class TypeSafeJudge {
|
|
24
|
+
config;
|
|
25
|
+
constructor(config) {
|
|
26
|
+
this.config = {
|
|
27
|
+
...DEFAULT_CONFIG,
|
|
28
|
+
...config,
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Evaluate state against questions using TypeSafe API
|
|
33
|
+
*/
|
|
34
|
+
async evaluate(state, questions) {
|
|
35
|
+
const startTime = Date.now();
|
|
36
|
+
// Convert state to string if object
|
|
37
|
+
const stateStr = typeof state === "string" ? state : JSON.stringify(state);
|
|
38
|
+
// Build TypeSafe question format
|
|
39
|
+
const questionsArray = Object.entries(questions).map(([id, q]) => {
|
|
40
|
+
const questionObj = q;
|
|
41
|
+
const question = {
|
|
42
|
+
id,
|
|
43
|
+
type: questionObj.type,
|
|
44
|
+
instructions: questionObj.instructions,
|
|
45
|
+
};
|
|
46
|
+
if (questionObj.type === "choice") {
|
|
47
|
+
question.options = questionObj.options;
|
|
48
|
+
// For choice questions, criteria defines ordered preference levels
|
|
49
|
+
question.criteria = questionObj.options;
|
|
50
|
+
}
|
|
51
|
+
else if (questionObj.type === "score") {
|
|
52
|
+
question.min = questionObj.min ?? 0;
|
|
53
|
+
question.max = questionObj.max ?? 100;
|
|
54
|
+
}
|
|
55
|
+
return question;
|
|
56
|
+
});
|
|
57
|
+
// Call TypeSafe API directly
|
|
58
|
+
const response = await fetch(`${this.config.baseUrl}/v1/systemone`, {
|
|
59
|
+
method: "POST",
|
|
60
|
+
headers: {
|
|
61
|
+
"Content-Type": "application/json",
|
|
62
|
+
Authorization: `Bearer ${this.config.apiKey}`,
|
|
63
|
+
},
|
|
64
|
+
body: JSON.stringify({
|
|
65
|
+
questions: questionsArray,
|
|
66
|
+
state: stateStr,
|
|
67
|
+
}),
|
|
68
|
+
signal: AbortSignal.timeout(this.config.timeoutMs),
|
|
69
|
+
});
|
|
70
|
+
const latencyMs = Date.now() - startTime;
|
|
71
|
+
if (!response.ok) {
|
|
72
|
+
const errorText = await response.text().catch(() => "Unknown error");
|
|
73
|
+
throw new Error(`TypeSafe API error ${response.status}: ${errorText}`);
|
|
74
|
+
}
|
|
75
|
+
const data = await response.json();
|
|
76
|
+
// Build decisions map
|
|
77
|
+
const decisions = {};
|
|
78
|
+
for (const [questionId, question] of Object.entries(questions)) {
|
|
79
|
+
const questionData = question;
|
|
80
|
+
const answer = data.answers?.[questionId];
|
|
81
|
+
if (!answer) {
|
|
82
|
+
// Skip missing answers
|
|
83
|
+
continue;
|
|
84
|
+
}
|
|
85
|
+
const decision = this.buildDecision(questionId, questionData, answer);
|
|
86
|
+
decisions[questionId] = decision;
|
|
87
|
+
}
|
|
88
|
+
return {
|
|
89
|
+
decisions,
|
|
90
|
+
state: stateStr,
|
|
91
|
+
latencyMs,
|
|
92
|
+
model: data.model ?? "typesafe/systemone",
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Quick noul (yes/no) evaluation
|
|
97
|
+
*/
|
|
98
|
+
async noul(state, question) {
|
|
99
|
+
const result = await this.evaluate(state, {
|
|
100
|
+
answer: { type: "noul", instructions: question },
|
|
101
|
+
});
|
|
102
|
+
const decision = result.decisions.answer;
|
|
103
|
+
const noulResponse = decision.response;
|
|
104
|
+
return {
|
|
105
|
+
noul: noulResponse.noul,
|
|
106
|
+
confidence: decision.confidence,
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Quick choice evaluation
|
|
111
|
+
*/
|
|
112
|
+
async choice(state, question, options) {
|
|
113
|
+
const result = await this.evaluate(state, {
|
|
114
|
+
answer: { type: "choice", instructions: question, options },
|
|
115
|
+
});
|
|
116
|
+
const decision = result.decisions.answer;
|
|
117
|
+
const choiceResponse = decision.response;
|
|
118
|
+
return {
|
|
119
|
+
choice: choiceResponse.choice,
|
|
120
|
+
confidence: choiceResponse.confidence,
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Quick score evaluation
|
|
125
|
+
*/
|
|
126
|
+
async score(state, question, min = 0, max = 100) {
|
|
127
|
+
const result = await this.evaluate(state, {
|
|
128
|
+
answer: { type: "score", instructions: question, min, max },
|
|
129
|
+
});
|
|
130
|
+
const decision = result.decisions.answer;
|
|
131
|
+
const scoreResponse = decision.response;
|
|
132
|
+
return {
|
|
133
|
+
score: scoreResponse.score,
|
|
134
|
+
confidence: scoreResponse.confidence,
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Build JevDecision from TypeSafe answer
|
|
139
|
+
*/
|
|
140
|
+
buildDecision(questionId, question, answer) {
|
|
141
|
+
let response;
|
|
142
|
+
let probability;
|
|
143
|
+
switch (answer.type) {
|
|
144
|
+
case "noul":
|
|
145
|
+
response = {
|
|
146
|
+
type: "noul",
|
|
147
|
+
noul: answer.probability ?? 0.5,
|
|
148
|
+
};
|
|
149
|
+
probability = answer.probability ?? 0.5;
|
|
150
|
+
break;
|
|
151
|
+
case "choice":
|
|
152
|
+
response = {
|
|
153
|
+
type: "choice",
|
|
154
|
+
choice: answer.choice ?? question.type === "choice" ? question.options[0] : "",
|
|
155
|
+
confidence: answer.confidence ?? 0.5,
|
|
156
|
+
};
|
|
157
|
+
probability = answer.confidence ?? 0.5;
|
|
158
|
+
break;
|
|
159
|
+
case "score":
|
|
160
|
+
const min = question.type === "score" ? question.min ?? 0 : 0;
|
|
161
|
+
const max = question.type === "score" ? question.max ?? 100 : 100;
|
|
162
|
+
response = {
|
|
163
|
+
type: "score",
|
|
164
|
+
score: answer.score ?? (min + max) / 2,
|
|
165
|
+
confidence: answer.confidence ?? 0.5,
|
|
166
|
+
};
|
|
167
|
+
// Normalize score to 0-1
|
|
168
|
+
probability = ((answer.score ?? (min + max) / 2) - min) / (max - min);
|
|
169
|
+
break;
|
|
170
|
+
default:
|
|
171
|
+
// Fallback for unknown types
|
|
172
|
+
response = {
|
|
173
|
+
type: "noul",
|
|
174
|
+
noul: 0.5,
|
|
175
|
+
};
|
|
176
|
+
probability = 0.5;
|
|
177
|
+
}
|
|
178
|
+
const confidence = this.getConfidence(answer.confidence ?? probability);
|
|
179
|
+
return {
|
|
180
|
+
questionId,
|
|
181
|
+
question,
|
|
182
|
+
response,
|
|
183
|
+
probability,
|
|
184
|
+
confidence,
|
|
185
|
+
};
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* Determine confidence level from probability
|
|
189
|
+
*/
|
|
190
|
+
getConfidence(probability) {
|
|
191
|
+
// Confidence is based on distance from 0.5 (uncertain)
|
|
192
|
+
const distance = Math.abs(probability - 0.5);
|
|
193
|
+
if (distance > 0.35)
|
|
194
|
+
return "high";
|
|
195
|
+
if (distance > 0.2)
|
|
196
|
+
return "medium";
|
|
197
|
+
return "low";
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
/**
|
|
201
|
+
* Detect which provider to use based on API key or config
|
|
202
|
+
*/
|
|
203
|
+
export function detectProvider(apiKey, baseUrl) {
|
|
204
|
+
// If baseUrl is explicitly set to TypeSafe, use TypeSafe
|
|
205
|
+
if (baseUrl?.includes("typesafe.ai")) {
|
|
206
|
+
return "typesafe";
|
|
207
|
+
}
|
|
208
|
+
// If using OpenRouter URL, use OpenRouter
|
|
209
|
+
if (baseUrl?.includes("openrouter")) {
|
|
210
|
+
return "openrouter";
|
|
211
|
+
}
|
|
212
|
+
// If key looks like TypeSafe (no specific pattern known), prefer TypeSafe
|
|
213
|
+
// TypeSafe keys are typically longer than OpenAI-compatible keys
|
|
214
|
+
if (apiKey.length > 50) {
|
|
215
|
+
return "typesafe";
|
|
216
|
+
}
|
|
217
|
+
// Default to OpenRouter for short keys (OpenAI-compatible)
|
|
218
|
+
return "openrouter";
|
|
219
|
+
}
|
|
220
|
+
//# sourceMappingURL=typesafe-provider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"typesafe-provider.js","sourceRoot":"","sources":["../src/typesafe-provider.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AA+DH;;GAEG;AACH,MAAM,cAAc,GAAG;IACrB,OAAO,EAAE,yBAAyB;IAClC,SAAS,EAAE,KAAK;CACjB,CAAC;AAEF;;;;;GAKG;AACH,MAAM,OAAO,aAAa;IAChB,MAAM,CAA2B;IAEzC,YAAY,MAAsB;QAChC,IAAI,CAAC,MAAM,GAAG;YACZ,GAAG,cAAc;YACjB,GAAG,MAAM;SACkB,CAAC;IAChC,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,QAAQ,CACZ,KAAsB,EACtB,SAA0B;QAE1B,MAAM,SAAS,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;QAE7B,oCAAoC;QACpC,MAAM,QAAQ,GAAG,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;QAE3E,iCAAiC;QACjC,MAAM,cAAc,GAAG,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,EAAE,EAAE;YAC/D,MAAM,WAAW,GAAG,CAAgB,CAAC;YACrC,MAAM,QAAQ,GAAqB;gBACjC,EAAE;gBACF,IAAI,EAAE,WAAW,CAAC,IAAI;gBACtB,YAAY,EAAE,WAAW,CAAC,YAAY;aACvC,CAAC;YAEF,IAAI,WAAW,CAAC,IAAI,KAAK,QAAQ,EAAE,CAAC;gBAClC,QAAQ,CAAC,OAAO,GAAG,WAAW,CAAC,O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EG;IACK,aAAa,CAAC,WAAmB;QACvC,uDAAuD;QACvD,MAAM,QAAQ,GAAG,IAAI,CAAC,GAAG,CAAC,WAAW,GAAG,GAAG,CAAC,CAAC;QAC7C,IAAI,QAAQ,GAAG,IAAI;YAAE,OAAO,MAAM,CAAC;QACnC,IAAI,QAAQ,GAAG,GAAG;YAAE,OAAO,QAAQ,CAAC;QACpC,OAAO,KAAK,CAAC;IACf,CAAC;CACF;AAED;;GAEG;AACH,MAAM,UAAU,cAAc,CAC5B,MAAc,EACd,OAAgB;IAEhB,yDAAyD;IACzD,IAAI,OAAO,EAAE,QAAQ,CAAC,aAAa,CAAC,EAAE,CAAC;QACrC,OAAO,UAAU,CAAC;IACpB,CAAC;IACD,0CAA0C;IAC1C,IAAI,OAAO,EAAE,QAAQ,CAAC,YAAY,CAAC,EAAE,CAAC;QACpC,OAAO,YAAY,CAAC;IACtB,CAAC;IACD,0EAA0E;IAC1E,iEAAiE;IACjE,IAAI,MAAM,CAAC,MAAM,GAAG,EAAE,EAAE,CAAC;QACvB,OAAO,UAAU,CAAC;IACpB,CAAC;IACD,2DAA2D;IAC3D,OAAO,YAAY,CAAC;AACtB,CAAC"}
|
|
@@ -2,13 +2,16 @@
|
|
|
2
2
|
* Jev Judge - Main API
|
|
3
3
|
*
|
|
4
4
|
* Structured decision model for agent routing, E2E testing, and automated decisions.
|
|
5
|
-
* Uses TypeSafe Jev via
|
|
5
|
+
* Uses TypeSafe Jev via:
|
|
6
|
+
* - Primary: TypeSafe direct API (https://api.typesafe.ai/v1/systemone)
|
|
7
|
+
* - Fallback: OpenRouter API (https://openrouter.ai/api/v1)
|
|
6
8
|
*
|
|
7
9
|
* @example
|
|
8
10
|
* ```typescript
|
|
9
11
|
* import { JevJudge } from "@pi-harness/jev-judge";
|
|
10
12
|
*
|
|
11
|
-
*
|
|
13
|
+
* // Auto-detects TypeSafe vs OpenRouter based on API key and baseUrl
|
|
14
|
+
* const judge = new JevJudge({ apiKey: process.env.TYPESAFE_API_KEY! });
|
|
12
15
|
*
|
|
13
16
|
* // Ask multiple questions at once
|
|
14
17
|
* const result = await judge.evaluate(
|
|
@@ -44,6 +47,8 @@ import type {
|
|
|
44
47
|
// @ts-ignore - openai is installed at workspace root
|
|
45
48
|
import OpenAI from "openai";
|
|
46
49
|
|
|
50
|
+
import { TypeSafeJudge } from "./typesafe-provider.js";
|
|
51
|
+
|
|
47
52
|
/**
|
|
48
53
|
* Environment variable keys for API keys
|
|
49
54
|
*/
|
|
@@ -111,18 +116,33 @@ export function createJevJudge(config?: Partial<JevJudgeConfig>): JevJudge {
|
|
|
111
116
|
* Default configuration
|
|
112
117
|
*/
|
|
113
118
|
const DEFAULT_CONFIG = {
|
|
114
|
-
baseUrl: "https://
|
|
115
|
-
model: "typesafe/
|
|
119
|
+
baseUrl: "https://api.typesafe.ai", // TypeSafe direct API as default
|
|
120
|
+
model: "typesafe/systemone",
|
|
116
121
|
defaultThreshold: 0.7,
|
|
117
122
|
timeoutMs: 30000,
|
|
118
123
|
};
|
|
119
124
|
|
|
125
|
+
/**
|
|
126
|
+
* Detect provider from baseUrl
|
|
127
|
+
*/
|
|
128
|
+
function detectProvider(baseUrl: string): "typesafe" | "openrouter" {
|
|
129
|
+
if (baseUrl.includes("typesafe.ai")) return "typesafe";
|
|
130
|
+
if (baseUrl.includes("openrouter")) return "openrouter";
|
|
131
|
+
return "openrouter"; // Default to OpenRouter for backwards compatibility
|
|
132
|
+
}
|
|
133
|
+
|
|
120
134
|
/**
|
|
121
135
|
* JevJudge - Main class for making structured decisions with Jev
|
|
136
|
+
*
|
|
137
|
+
* Supports two providers:
|
|
138
|
+
* - TypeSafe direct API (primary, recommended)
|
|
139
|
+
* - OpenRouter API (fallback for backwards compatibility)
|
|
122
140
|
*/
|
|
123
141
|
export class JevJudge {
|
|
124
|
-
private
|
|
142
|
+
private typesafeJudge?: TypeSafeJudge;
|
|
143
|
+
private openrouterClient?: OpenAI;
|
|
125
144
|
private config: Required<JevJudgeConfig>;
|
|
145
|
+
private provider: "typesafe" | "openrouter";
|
|
126
146
|
|
|
127
147
|
constructor(config: JevJudgeConfig) {
|
|
128
148
|
this.config = {
|
|
@@ -130,11 +150,23 @@ export class JevJudge {
|
|
|
130
150
|
...config,
|
|
131
151
|
} as Required<JevJudgeConfig>;
|
|
132
152
|
|
|
133
|
-
this.
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
153
|
+
this.provider = detectProvider(this.config.baseUrl);
|
|
154
|
+
|
|
155
|
+
if (this.provider === "typesafe") {
|
|
156
|
+
// Use TypeSafe direct API
|
|
157
|
+
this.typesafeJudge = new TypeSafeJudge({
|
|
158
|
+
apiKey: this.config.apiKey,
|
|
159
|
+
baseUrl: this.config.baseUrl,
|
|
160
|
+
timeoutMs: this.config.timeoutMs,
|
|
161
|
+
});
|
|
162
|
+
} else {
|
|
163
|
+
// Use OpenRouter
|
|
164
|
+
this.openrouterClient = new OpenAI({
|
|
165
|
+
apiKey: this.config.apiKey,
|
|
166
|
+
baseURL: this.config.baseUrl,
|
|
167
|
+
timeout: this.config.timeoutMs,
|
|
168
|
+
});
|
|
169
|
+
}
|
|
138
170
|
}
|
|
139
171
|
|
|
140
172
|
/**
|
|
@@ -148,12 +180,22 @@ export class JevJudge {
|
|
|
148
180
|
state: string | object,
|
|
149
181
|
questions: JevQuestions<T>
|
|
150
182
|
): Promise<JevEvaluationResult<T>> {
|
|
183
|
+
// Use TypeSafe provider if configured
|
|
184
|
+
if (this.provider === "typesafe" && this.typesafeJudge) {
|
|
185
|
+
return this.typesafeJudge.evaluate(state, questions);
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
// Fall back to OpenRouter
|
|
189
|
+
if (!this.openrouterClient) {
|
|
190
|
+
throw new Error("No Jev provider configured");
|
|
191
|
+
}
|
|
192
|
+
|
|
151
193
|
const startTime = Date.now();
|
|
152
194
|
|
|
153
195
|
// Convert state to string if object
|
|
154
196
|
const stateStr = typeof state === "string" ? state : JSON.stringify(state);
|
|
155
197
|
|
|
156
|
-
// Build questions array for API
|
|
198
|
+
// Build questions array for OpenRouter API
|
|
157
199
|
const questionsArray = Object.entries(questions).map(([id, q]) => {
|
|
158
200
|
const questionObj = q as JevQuestion;
|
|
159
201
|
const entry: Record<string, unknown> = { id };
|
|
@@ -174,7 +216,7 @@ export class JevJudge {
|
|
|
174
216
|
});
|
|
175
217
|
|
|
176
218
|
// Call Jev via OpenRouter
|
|
177
|
-
const response = await this.
|
|
219
|
+
const response = await this.openrouterClient.chat.completions.create({
|
|
178
220
|
model: this.config.model,
|
|
179
221
|
messages: [
|
|
180
222
|
{
|
|
@@ -390,3 +432,7 @@ export type { TodoItem, WrapUpResult } from "./wrap-up-judge.js";
|
|
|
390
432
|
// Export EnvironmentJudge
|
|
391
433
|
export { EnvironmentJudge } from "./environment-judge.js";
|
|
392
434
|
export type { EnvironmentContext, EnvironmentDecision, SafetyCheck, EnvironmentConfig } from "./environment-judge.js";
|
|
435
|
+
|
|
436
|
+
// Export TypeSafeJudge
|
|
437
|
+
export { TypeSafeJudge, detectProvider } from "./typesafe-provider.js";
|
|
438
|
+
export type { TypeSafeConfig } from "./typesafe-provider.js";
|