pi-harness-runtime 1.1.153 → 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/index.ts +83 -3
- 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/package.json +1 -1
- 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/package.json +1 -1
- 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,335 @@
|
|
|
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
|
+
import type {
|
|
12
|
+
JevQuestion,
|
|
13
|
+
JevQuestions,
|
|
14
|
+
JevResponse,
|
|
15
|
+
JevDecision,
|
|
16
|
+
JevEvaluationResult,
|
|
17
|
+
JevNoulResponse,
|
|
18
|
+
JevChoiceResponse,
|
|
19
|
+
JevScoreResponse,
|
|
20
|
+
} from "./types.js";
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* TypeSafe API request format
|
|
24
|
+
*/
|
|
25
|
+
interface TypeSafeRequest {
|
|
26
|
+
questions: TypeSafeQuestion[];
|
|
27
|
+
state: string;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* TypeSafe question format
|
|
32
|
+
*/
|
|
33
|
+
interface TypeSafeQuestion {
|
|
34
|
+
id: string;
|
|
35
|
+
type: "noul" | "choice" | "score";
|
|
36
|
+
instructions: string;
|
|
37
|
+
options?: string[]; // For choice type
|
|
38
|
+
criteria?: string[]; // For choice type - ordered criteria
|
|
39
|
+
min?: number; // For score type
|
|
40
|
+
max?: number; // For score type
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* TypeSafe API response format
|
|
45
|
+
*/
|
|
46
|
+
interface TypeSafeResponse {
|
|
47
|
+
answers: Record<string, TypeSafeAnswer>;
|
|
48
|
+
model?: string;
|
|
49
|
+
latency_ms?: number;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* TypeSafe answer format
|
|
54
|
+
*/
|
|
55
|
+
interface TypeSafeAnswer {
|
|
56
|
+
type: "noul" | "choice" | "score";
|
|
57
|
+
probability?: number; // For noul type (0-1)
|
|
58
|
+
choice?: string; // For choice type
|
|
59
|
+
score?: number; // For score type
|
|
60
|
+
confidence?: number; // 0-1 for all types
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* TypeSafe provider configuration
|
|
65
|
+
*/
|
|
66
|
+
export interface TypeSafeConfig {
|
|
67
|
+
apiKey: string;
|
|
68
|
+
baseUrl?: string; // Defaults to https://api.typesafe.ai
|
|
69
|
+
timeoutMs?: number; // Defaults to 30000
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Default configuration
|
|
74
|
+
*/
|
|
75
|
+
const DEFAULT_CONFIG = {
|
|
76
|
+
baseUrl: "https://api.typesafe.ai",
|
|
77
|
+
timeoutMs: 30000,
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* TypeSafe Jev Judge - Direct TypeSafe API integration
|
|
82
|
+
*
|
|
83
|
+
* Uses TypeSafe's systemone API for structured decisions.
|
|
84
|
+
* More reliable than OpenRouter proxy and supports full feature set.
|
|
85
|
+
*/
|
|
86
|
+
export class TypeSafeJudge {
|
|
87
|
+
private config: Required<TypeSafeConfig>;
|
|
88
|
+
|
|
89
|
+
constructor(config: TypeSafeConfig) {
|
|
90
|
+
this.config = {
|
|
91
|
+
...DEFAULT_CONFIG,
|
|
92
|
+
...config,
|
|
93
|
+
} as Required<TypeSafeConfig>;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Evaluate state against questions using TypeSafe API
|
|
98
|
+
*/
|
|
99
|
+
async evaluate<T extends string>(
|
|
100
|
+
state: string | object,
|
|
101
|
+
questions: JevQuestions<T>
|
|
102
|
+
): Promise<JevEvaluationResult<T>> {
|
|
103
|
+
const startTime = Date.now();
|
|
104
|
+
|
|
105
|
+
// Convert state to string if object
|
|
106
|
+
const stateStr = typeof state === "string" ? state : JSON.stringify(state);
|
|
107
|
+
|
|
108
|
+
// Build TypeSafe question format
|
|
109
|
+
const questionsArray = Object.entries(questions).map(([id, q]) => {
|
|
110
|
+
const questionObj = q as JevQuestion;
|
|
111
|
+
const question: TypeSafeQuestion = {
|
|
112
|
+
id,
|
|
113
|
+
type: questionObj.type,
|
|
114
|
+
instructions: questionObj.instructions,
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
if (questionObj.type === "choice") {
|
|
118
|
+
question.options = questionObj.options;
|
|
119
|
+
// For choice questions, criteria defines ordered preference levels
|
|
120
|
+
question.criteria = questionObj.options;
|
|
121
|
+
} else if (questionObj.type === "score") {
|
|
122
|
+
question.min = questionObj.min ?? 0;
|
|
123
|
+
question.max = questionObj.max ?? 100;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
return question;
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
// Call TypeSafe API directly
|
|
130
|
+
const response = await fetch(`${this.config.baseUrl}/v1/systemone`, {
|
|
131
|
+
method: "POST",
|
|
132
|
+
headers: {
|
|
133
|
+
"Content-Type": "application/json",
|
|
134
|
+
Authorization: `Bearer ${this.config.apiKey}`,
|
|
135
|
+
},
|
|
136
|
+
body: JSON.stringify({
|
|
137
|
+
questions: questionsArray,
|
|
138
|
+
state: stateStr,
|
|
139
|
+
} satisfies TypeSafeRequest),
|
|
140
|
+
signal: AbortSignal.timeout(this.config.timeoutMs),
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
const latencyMs = Date.now() - startTime;
|
|
144
|
+
|
|
145
|
+
if (!response.ok) {
|
|
146
|
+
const errorText = await response.text().catch(() => "Unknown error");
|
|
147
|
+
throw new Error(`TypeSafe API error ${response.status}: ${errorText}`);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
const data = await response.json() as TypeSafeResponse;
|
|
151
|
+
|
|
152
|
+
// Build decisions map
|
|
153
|
+
const decisions = {} as Record<T, JevDecision<T>>;
|
|
154
|
+
|
|
155
|
+
for (const [questionId, question] of Object.entries(questions)) {
|
|
156
|
+
const questionData = question as JevQuestion;
|
|
157
|
+
const answer = data.answers?.[questionId] as TypeSafeAnswer | undefined;
|
|
158
|
+
|
|
159
|
+
if (!answer) {
|
|
160
|
+
// Skip missing answers
|
|
161
|
+
continue;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
const decision = this.buildDecision(
|
|
165
|
+
questionId,
|
|
166
|
+
questionData,
|
|
167
|
+
answer
|
|
168
|
+
);
|
|
169
|
+
(decisions as Record<string, JevDecision>)[questionId] = decision;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
return {
|
|
173
|
+
decisions,
|
|
174
|
+
state: stateStr,
|
|
175
|
+
latencyMs,
|
|
176
|
+
model: data.model ?? "typesafe/systemone",
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* Quick noul (yes/no) evaluation
|
|
182
|
+
*/
|
|
183
|
+
async noul(
|
|
184
|
+
state: string | object,
|
|
185
|
+
question: string
|
|
186
|
+
): Promise<{ noul: number; confidence: "high" | "medium" | "low" }> {
|
|
187
|
+
const result = await this.evaluate(state, {
|
|
188
|
+
answer: { type: "noul", instructions: question },
|
|
189
|
+
});
|
|
190
|
+
|
|
191
|
+
const decision = result.decisions.answer as JevDecision<"answer">;
|
|
192
|
+
const noulResponse = decision.response as JevNoulResponse;
|
|
193
|
+
return {
|
|
194
|
+
noul: noulResponse.noul,
|
|
195
|
+
confidence: decision.confidence,
|
|
196
|
+
};
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
/**
|
|
200
|
+
* Quick choice evaluation
|
|
201
|
+
*/
|
|
202
|
+
async choice<T extends string>(
|
|
203
|
+
state: string | object,
|
|
204
|
+
question: string,
|
|
205
|
+
options: T[]
|
|
206
|
+
): Promise<{ choice: T; confidence: number }> {
|
|
207
|
+
const result = await this.evaluate(state, {
|
|
208
|
+
answer: { type: "choice", instructions: question, options },
|
|
209
|
+
});
|
|
210
|
+
|
|
211
|
+
const decision = result.decisions.answer as JevDecision<"answer">;
|
|
212
|
+
const choiceResponse = decision.response as JevChoiceResponse<T>;
|
|
213
|
+
return {
|
|
214
|
+
choice: choiceResponse.choice,
|
|
215
|
+
confidence: choiceResponse.confidence,
|
|
216
|
+
};
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
/**
|
|
220
|
+
* Quick score evaluation
|
|
221
|
+
*/
|
|
222
|
+
async score(
|
|
223
|
+
state: string | object,
|
|
224
|
+
question: string,
|
|
225
|
+
min = 0,
|
|
226
|
+
max = 100
|
|
227
|
+
): Promise<{ score: number; confidence: number }> {
|
|
228
|
+
const result = await this.evaluate(state, {
|
|
229
|
+
answer: { type: "score", instructions: question, min, max },
|
|
230
|
+
});
|
|
231
|
+
|
|
232
|
+
const decision = result.decisions.answer as JevDecision<"answer">;
|
|
233
|
+
const scoreResponse = decision.response as JevScoreResponse;
|
|
234
|
+
return {
|
|
235
|
+
score: scoreResponse.score,
|
|
236
|
+
confidence: scoreResponse.confidence,
|
|
237
|
+
};
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
/**
|
|
241
|
+
* Build JevDecision from TypeSafe answer
|
|
242
|
+
*/
|
|
243
|
+
private buildDecision<T extends string>(
|
|
244
|
+
questionId: T,
|
|
245
|
+
question: JevQuestion,
|
|
246
|
+
answer: TypeSafeAnswer
|
|
247
|
+
): JevDecision<T> {
|
|
248
|
+
let response: JevResponse;
|
|
249
|
+
let probability: number;
|
|
250
|
+
|
|
251
|
+
switch (answer.type) {
|
|
252
|
+
case "noul":
|
|
253
|
+
response = {
|
|
254
|
+
type: "noul",
|
|
255
|
+
noul: answer.probability ?? 0.5,
|
|
256
|
+
};
|
|
257
|
+
probability = answer.probability ?? 0.5;
|
|
258
|
+
break;
|
|
259
|
+
|
|
260
|
+
case "choice":
|
|
261
|
+
response = {
|
|
262
|
+
type: "choice",
|
|
263
|
+
choice: answer.choice ?? question.type === "choice" ? (question as { options: string[] }).options[0] : "",
|
|
264
|
+
confidence: answer.confidence ?? 0.5,
|
|
265
|
+
};
|
|
266
|
+
probability = answer.confidence ?? 0.5;
|
|
267
|
+
break;
|
|
268
|
+
|
|
269
|
+
case "score":
|
|
270
|
+
const min = question.type === "score" ? (question as { min?: number }).min ?? 0 : 0;
|
|
271
|
+
const max = question.type === "score" ? (question as { max?: number }).max ?? 100 : 100;
|
|
272
|
+
response = {
|
|
273
|
+
type: "score",
|
|
274
|
+
score: answer.score ?? (min + max) / 2,
|
|
275
|
+
confidence: answer.confidence ?? 0.5,
|
|
276
|
+
};
|
|
277
|
+
// Normalize score to 0-1
|
|
278
|
+
probability = ((answer.score ?? (min + max) / 2) - min) / (max - min);
|
|
279
|
+
break;
|
|
280
|
+
|
|
281
|
+
default:
|
|
282
|
+
// Fallback for unknown types
|
|
283
|
+
response = {
|
|
284
|
+
type: "noul",
|
|
285
|
+
noul: 0.5,
|
|
286
|
+
};
|
|
287
|
+
probability = 0.5;
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
const confidence = this.getConfidence(answer.confidence ?? probability);
|
|
291
|
+
|
|
292
|
+
return {
|
|
293
|
+
questionId,
|
|
294
|
+
question,
|
|
295
|
+
response,
|
|
296
|
+
probability,
|
|
297
|
+
confidence,
|
|
298
|
+
};
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
/**
|
|
302
|
+
* Determine confidence level from probability
|
|
303
|
+
*/
|
|
304
|
+
private getConfidence(probability: number): "high" | "medium" | "low" {
|
|
305
|
+
// Confidence is based on distance from 0.5 (uncertain)
|
|
306
|
+
const distance = Math.abs(probability - 0.5);
|
|
307
|
+
if (distance > 0.35) return "high";
|
|
308
|
+
if (distance > 0.2) return "medium";
|
|
309
|
+
return "low";
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
/**
|
|
314
|
+
* Detect which provider to use based on API key or config
|
|
315
|
+
*/
|
|
316
|
+
export function detectProvider(
|
|
317
|
+
apiKey: string,
|
|
318
|
+
baseUrl?: string
|
|
319
|
+
): "typesafe" | "openrouter" {
|
|
320
|
+
// If baseUrl is explicitly set to TypeSafe, use TypeSafe
|
|
321
|
+
if (baseUrl?.includes("typesafe.ai")) {
|
|
322
|
+
return "typesafe";
|
|
323
|
+
}
|
|
324
|
+
// If using OpenRouter URL, use OpenRouter
|
|
325
|
+
if (baseUrl?.includes("openrouter")) {
|
|
326
|
+
return "openrouter";
|
|
327
|
+
}
|
|
328
|
+
// If key looks like TypeSafe (no specific pattern known), prefer TypeSafe
|
|
329
|
+
// TypeSafe keys are typically longer than OpenAI-compatible keys
|
|
330
|
+
if (apiKey.length > 50) {
|
|
331
|
+
return "typesafe";
|
|
332
|
+
}
|
|
333
|
+
// Default to OpenRouter for short keys (OpenAI-compatible)
|
|
334
|
+
return "openrouter";
|
|
335
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pi-harness/provider-router",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.154",
|
|
4
4
|
"description": "Enhanced Provider Router for pi-harness-runtime — intelligent routing with capabilities, costs, and quotas",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/provider-router.js",
|