jevascript 0.1.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.
- package/LICENSE +21 -0
- package/README.md +447 -0
- package/dist/cache.d.ts +18 -0
- package/dist/cache.d.ts.map +1 -0
- package/dist/cache.js +58 -0
- package/dist/cache.js.map +1 -0
- package/dist/collections.d.ts +52 -0
- package/dist/collections.d.ts.map +1 -0
- package/dist/collections.js +206 -0
- package/dist/collections.js.map +1 -0
- package/dist/config.d.ts +57 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +75 -0
- package/dist/config.js.map +1 -0
- package/dist/context.d.ts +73 -0
- package/dist/context.d.ts.map +1 -0
- package/dist/context.js +251 -0
- package/dist/context.js.map +1 -0
- package/dist/define.d.ts +52 -0
- package/dist/define.d.ts.map +1 -0
- package/dist/define.js +59 -0
- package/dist/define.js.map +1 -0
- package/dist/errors.d.ts +28 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +56 -0
- package/dist/errors.js.map +1 -0
- package/dist/evaluate.d.ts +31 -0
- package/dist/evaluate.d.ts.map +1 -0
- package/dist/evaluate.js +142 -0
- package/dist/evaluate.js.map +1 -0
- package/dist/factory.d.ts +6 -0
- package/dist/factory.d.ts.map +1 -0
- package/dist/factory.js +7 -0
- package/dist/factory.js.map +1 -0
- package/dist/index.d.ts +68 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +53 -0
- package/dist/index.js.map +1 -0
- package/dist/internal.d.ts +3 -0
- package/dist/internal.d.ts.map +1 -0
- package/dist/internal.js +6 -0
- package/dist/internal.js.map +1 -0
- package/dist/outputs.d.ts +40 -0
- package/dist/outputs.d.ts.map +1 -0
- package/dist/outputs.js +20 -0
- package/dist/outputs.js.map +1 -0
- package/dist/providers/jev.d.ts +21 -0
- package/dist/providers/jev.d.ts.map +1 -0
- package/dist/providers/jev.js +175 -0
- package/dist/providers/jev.js.map +1 -0
- package/dist/questions.d.ts +98 -0
- package/dist/questions.d.ts.map +1 -0
- package/dist/questions.js +57 -0
- package/dist/questions.js.map +1 -0
- package/dist/runner.d.ts +52 -0
- package/dist/runner.d.ts.map +1 -0
- package/dist/runner.js +208 -0
- package/dist/runner.js.map +1 -0
- package/dist/schema.d.ts +49 -0
- package/dist/schema.d.ts.map +1 -0
- package/dist/schema.js +30 -0
- package/dist/schema.js.map +1 -0
- package/dist/testing.d.ts +34 -0
- package/dist/testing.d.ts.map +1 -0
- package/dist/testing.js +68 -0
- package/dist/testing.js.map +1 -0
- package/dist/types.d.ts +152 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +8 -0
- package/dist/types.js.map +1 -0
- package/package.json +29 -0
package/dist/evaluate.js
ADDED
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
import { BUILTIN_DEFAULTS, globalRuntime } from "./config.js";
|
|
2
|
+
import { emit, runPlan } from "./runner.js";
|
|
3
|
+
import { parseTtlOrUndefined } from "./internal.js";
|
|
4
|
+
import { DEFAULT_SCORE_FRAME } from "./questions.js";
|
|
5
|
+
/**
|
|
6
|
+
* Each question's instructions must be a proposition, on its own.
|
|
7
|
+
*
|
|
8
|
+
* Folding the task, the field name and a description into one JSON blob reads
|
|
9
|
+
* as a label rather than a claim, and the model scores it near 0.5 because
|
|
10
|
+
* there is nothing definite to affirm or deny. Measured on a ticket that is
|
|
11
|
+
* plainly not urgent: the blob form returns 0.54, a bare proposition 0.06.
|
|
12
|
+
*
|
|
13
|
+
* So the task moves into the state, where it is sent once and frames every
|
|
14
|
+
* question, and each field asks something answerable.
|
|
15
|
+
*/
|
|
16
|
+
function instructionsFor(path, describe, kind) {
|
|
17
|
+
if (describe !== undefined)
|
|
18
|
+
return describe;
|
|
19
|
+
const name = path.length > 0 ? path.join(" ") : "this";
|
|
20
|
+
// No description given: build the least-bad proposition from the field name.
|
|
21
|
+
return kind === "number" ? DEFAULT_SCORE_FRAME(name) : name;
|
|
22
|
+
}
|
|
23
|
+
function collect(output, path, into) {
|
|
24
|
+
if (output.kind === "object") {
|
|
25
|
+
for (const [name, field] of Object.entries(output.fields))
|
|
26
|
+
collect(field, [...path, name], into);
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
const key = path.length === 0 ? "value" : path.join("__");
|
|
30
|
+
const instructions = instructionsFor(path, output.describe, output.kind);
|
|
31
|
+
if (output.kind === "boolean") {
|
|
32
|
+
into.push({
|
|
33
|
+
key,
|
|
34
|
+
path,
|
|
35
|
+
output,
|
|
36
|
+
question: {
|
|
37
|
+
kind: "truth",
|
|
38
|
+
instructions,
|
|
39
|
+
...(output.trueWhen !== undefined ? { trueWhen: output.trueWhen } : {}),
|
|
40
|
+
...(output.falseWhen !== undefined ? { falseWhen: output.falseWhen } : {}),
|
|
41
|
+
},
|
|
42
|
+
});
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
if (output.kind === "enum") {
|
|
46
|
+
into.push({ key, path, output, question: { kind: "choice", instructions, options: output.options } });
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
into.push({
|
|
50
|
+
key,
|
|
51
|
+
path,
|
|
52
|
+
output,
|
|
53
|
+
question: output.levels
|
|
54
|
+
? { kind: "level", instructions, levels: output.levels }
|
|
55
|
+
: { kind: "truth", instructions },
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
function assign(target, path, value) {
|
|
59
|
+
if (path.length === 0)
|
|
60
|
+
return;
|
|
61
|
+
let cursor = target;
|
|
62
|
+
for (const segment of path.slice(0, -1)) {
|
|
63
|
+
cursor[segment] ??= {};
|
|
64
|
+
cursor = cursor[segment];
|
|
65
|
+
}
|
|
66
|
+
cursor[path[path.length - 1]] = value;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* The low-level entry point. One request regardless of how many fields the
|
|
70
|
+
* output describes.
|
|
71
|
+
*/
|
|
72
|
+
export async function evaluate(request) {
|
|
73
|
+
return evaluateWith(globalRuntime, request);
|
|
74
|
+
}
|
|
75
|
+
/** `evaluate` against a specific runtime. `createSemantic()` binds this. */
|
|
76
|
+
export async function evaluateWith(runtime, request) {
|
|
77
|
+
const provider = runtime.provider(request.provider);
|
|
78
|
+
const leaves = [];
|
|
79
|
+
collect(request.output, [], leaves);
|
|
80
|
+
if (leaves.length === 0)
|
|
81
|
+
throw new Error("`output` describes no fields to evaluate.");
|
|
82
|
+
// The task and any background travel in the state: sent once, not per question.
|
|
83
|
+
const state = request.question || request.context
|
|
84
|
+
? {
|
|
85
|
+
...(request.question ? { task: request.question } : {}),
|
|
86
|
+
...(request.context ? { context: request.context } : {}),
|
|
87
|
+
input: request.data,
|
|
88
|
+
}
|
|
89
|
+
: request.data;
|
|
90
|
+
const ttl = parseTtlOrUndefined(request.cache ?? runtime.config.defaults?.cache);
|
|
91
|
+
const planned = leaves.map((leaf) => ({
|
|
92
|
+
key: leaf.key,
|
|
93
|
+
question: leaf.question,
|
|
94
|
+
samples: request.samples ?? 1,
|
|
95
|
+
...(ttl !== undefined ? { cacheTtlMs: ttl } : {}),
|
|
96
|
+
}));
|
|
97
|
+
const result = await runPlan(provider, state, planned, { store: runtime.store, ...(request.timeoutMs !== undefined ? { timeoutMs: request.timeoutMs } : {}) });
|
|
98
|
+
emit({
|
|
99
|
+
operation: "evaluate",
|
|
100
|
+
keys: leaves.map((l) => l.key),
|
|
101
|
+
provider: provider.name,
|
|
102
|
+
model: provider.model,
|
|
103
|
+
latencyMs: result.latencyMs,
|
|
104
|
+
cached: result.cachedKeys.size === leaves.length,
|
|
105
|
+
batched: leaves.length > 1,
|
|
106
|
+
questionCount: leaves.length,
|
|
107
|
+
requestCount: result.requestCount,
|
|
108
|
+
samples: request.samples ?? 1,
|
|
109
|
+
usage: result.usage,
|
|
110
|
+
...(request.metric ? { metric: request.metric } : {}),
|
|
111
|
+
}, runtime.config);
|
|
112
|
+
const threshold = runtime.config.defaults?.threshold ?? BUILTIN_DEFAULTS.threshold;
|
|
113
|
+
const root = {};
|
|
114
|
+
let scalar;
|
|
115
|
+
for (const leaf of leaves) {
|
|
116
|
+
const answer = result.answers[leaf.key];
|
|
117
|
+
let value;
|
|
118
|
+
if (leaf.output.kind === "boolean") {
|
|
119
|
+
value = answer.probability > threshold;
|
|
120
|
+
}
|
|
121
|
+
else if (leaf.output.kind === "enum") {
|
|
122
|
+
value = answer.choice;
|
|
123
|
+
}
|
|
124
|
+
else {
|
|
125
|
+
const { min, max } = leaf.output;
|
|
126
|
+
if (answer.kind === "level") {
|
|
127
|
+
const width = answer.probabilities.length;
|
|
128
|
+
const position = width > 1 ? answer.level / (width - 1) : 0;
|
|
129
|
+
value = min + position * (max - min);
|
|
130
|
+
}
|
|
131
|
+
else {
|
|
132
|
+
value = min + answer.probability * (max - min);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
if (leaf.path.length === 0)
|
|
136
|
+
scalar = value;
|
|
137
|
+
else
|
|
138
|
+
assign(root, leaf.path, value);
|
|
139
|
+
}
|
|
140
|
+
return (request.output.kind === "object" ? root : scalar);
|
|
141
|
+
}
|
|
142
|
+
//# sourceMappingURL=evaluate.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"evaluate.js","sourceRoot":"","sources":["../src/evaluate.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,aAAa,EAAgB,MAAM,aAAa,CAAA;AAC3E,OAAO,EAAE,IAAI,EAAE,OAAO,EAAwB,MAAM,aAAa,CAAA;AACjE,OAAO,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAA;AACnD,OAAO,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAA;AA6BpD;;;;;;;;;;GAUG;AACH,SAAS,eAAe,CAAC,IAAc,EAAE,QAA4B,EAAE,IAAuB;IAC5F,IAAI,QAAQ,KAAK,SAAS;QAAE,OAAO,QAAQ,CAAA;IAC3C,MAAM,IAAI,GAAG,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,G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State } from "./types.ts";
|
|
4
|
+
/** Separate module so `define.ts` can build contexts without importing `index.ts`. */
|
|
5
|
+
export declare function semanticContext(state: State, runtime?: Runtime): SemanticContext;
|
|
6
|
+
//# sourceMappingURL=factory.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"factory.d.ts","sourceRoot":"","sources":["../src/factory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAA;AAC9C,OAAO,EAAiB,KAAK,OAAO,EAAE,MAAM,aAAa,CAAA;AACzD,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,YAAY,CAAA;AAEvC,sFAAsF;AACtF,wBAAgB,eAAe,CAAC,KAAK,EAAE,KAAK,EAAE,OAAO,GAAE,OAAuB,GAAG,eAAe,CAE/F"}
|
package/dist/factory.js
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { SemanticContext } from "./context.js";
|
|
2
|
+
import { globalRuntime } from "./config.js";
|
|
3
|
+
/** Separate module so `define.ts` can build contexts without importing `index.ts`. */
|
|
4
|
+
export function semanticContext(state, runtime = globalRuntime) {
|
|
5
|
+
return new SemanticContext(state, runtime);
|
|
6
|
+
}
|
|
7
|
+
//# sourceMappingURL=factory.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"factory.js","sourceRoot":"","sources":["../src/factory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAA;AAC9C,OAAO,EAAE,aAAa,EAAgB,MAAM,aAAa,CAAA;AAGzD,sFAAsF;AACtF,MAAM,UAAU,eAAe,CAAC,KAAY,EAAE,UAAmB,aAAa;IAC5E,OAAO,IAAI,eAAe,CAAC,KAAK,EAAE,OAAO,CAAC,CAAA;AAC5C,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { SemanticContext } from "./context.ts";
|
|
2
|
+
import { type Collections } from "./collections.ts";
|
|
3
|
+
import { type SemanticConfig } from "./config.ts";
|
|
4
|
+
import { type EvaluateRequest } from "./evaluate.ts";
|
|
5
|
+
import { type Metric, type MetricDefinition, type Rule, type RuleDefinition } from "./define.ts";
|
|
6
|
+
import { type Evaluator, type SchemaDefinition } from "./schema.ts";
|
|
7
|
+
import type { AnyOutput, OutputValue } from "./outputs.ts";
|
|
8
|
+
import { type QuestionSpec, type ScoreOptions } from "./questions.ts";
|
|
9
|
+
import { type NumberOutput } from "./outputs.ts";
|
|
10
|
+
import type { State } from "./types.ts";
|
|
11
|
+
export interface Semantic extends Collections {
|
|
12
|
+
/** Wraps a value so semantic questions can be asked about it. */
|
|
13
|
+
(state: State): SemanticContext;
|
|
14
|
+
evaluate<O extends AnyOutput>(request: EvaluateRequest<O>): Promise<OutputValue<O>>;
|
|
15
|
+
defineMetric(definition: MetricDefinition): Metric;
|
|
16
|
+
defineRule(definition: RuleDefinition): Rule;
|
|
17
|
+
defineSchema<const O extends AnyOutput>(definition: SchemaDefinition<O>): Evaluator<O>;
|
|
18
|
+
/** The configuration this instance runs with. */
|
|
19
|
+
readonly config: SemanticConfig;
|
|
20
|
+
/** Merge more configuration in — swap the provider in a test, add a hook at boot. */
|
|
21
|
+
configure(config: SemanticConfig): void;
|
|
22
|
+
}
|
|
23
|
+
/** @deprecated Use `Semantic`. */
|
|
24
|
+
export type SemanticFn = Semantic;
|
|
25
|
+
/**
|
|
26
|
+
* A private, fully configured instance. Create it once in a shared module and
|
|
27
|
+
* import it everywhere; naming it `semantic` keeps call sites identical:
|
|
28
|
+
*
|
|
29
|
+
* export const semantic = createSemantic({ provider: jev(), defaults: { timeoutMs: 5_000 } })
|
|
30
|
+
*
|
|
31
|
+
* Nothing it does touches the global `semantic` or `configureSemantic`.
|
|
32
|
+
*/
|
|
33
|
+
export declare function createSemantic(config?: SemanticConfig): Semantic;
|
|
34
|
+
/** The module-level instance, configured with `configureSemantic()` or from the environment. */
|
|
35
|
+
export declare const semantic: Semantic;
|
|
36
|
+
/**
|
|
37
|
+
* `score` is two things, disambiguated by its first argument.
|
|
38
|
+
*
|
|
39
|
+
* As a question — `score("urgency")` — it composes into `batch()`.
|
|
40
|
+
* As an output shape — `score(0, 100)` — it describes a field for `evaluate()`.
|
|
41
|
+
*/
|
|
42
|
+
export declare function score(criterion: string, options?: ScoreOptions): QuestionSpec<number>;
|
|
43
|
+
export declare function score(min?: number, max?: number, describe?: string): NumberOutput;
|
|
44
|
+
export { SemanticContext } from "./context.ts";
|
|
45
|
+
export type { DetailedChoice, DetailedScore, DetailedTruth } from "./context.ts";
|
|
46
|
+
export { configureSemantic, resetSemantic, getConfig, createRuntime, BUILTIN_DEFAULTS } from "./config.ts";
|
|
47
|
+
export type { SemanticConfig, SemanticDefaults, Runtime } from "./config.ts";
|
|
48
|
+
export { choose, is, DEFAULT_SCORE_FRAME } from "./questions.ts";
|
|
49
|
+
export type { ChoiceInput, ChooseOptions, IsOptions, QuestionSpec, ScoreOptions, SharedOptions, TruthCriteria, } from "./questions.ts";
|
|
50
|
+
export { evaluate, evaluateWith } from "./evaluate.ts";
|
|
51
|
+
export type { EvaluateRequest } from "./evaluate.ts";
|
|
52
|
+
export { boolean, enumOf, number, numberRange, object } from "./outputs.ts";
|
|
53
|
+
export type { AnyOutput, BooleanOutput, EnumOutput, NumberOutput, ObjectOutput, OutputValue, } from "./outputs.ts";
|
|
54
|
+
export { defineMetric, defineRule, defineMetricWith, defineRuleWith } from "./define.ts";
|
|
55
|
+
export type { Metric, MetricDefinition, Rule, RuleDefinition } from "./define.ts";
|
|
56
|
+
export { compare, every, filter, find, some, rank, bindCollections } from "./collections.ts";
|
|
57
|
+
export type { Collections, CollectionOptions, Comparison, Ranked, RankOptions } from "./collections.ts";
|
|
58
|
+
export { MemoryCache, parseTtl, hashKey } from "./cache.ts";
|
|
59
|
+
export type { SemanticCache } from "./cache.ts";
|
|
60
|
+
export { confidenceFromSpread, assertSupported, cacheKeyFor, runPlan } from "./runner.ts";
|
|
61
|
+
export type { PlannedQuestion, RunResult } from "./runner.ts";
|
|
62
|
+
export { LowConfidenceError, NotConfiguredError, ProviderError, SemanticError, SemanticValidationError, UnsupportedByProviderError, } from "./errors.ts";
|
|
63
|
+
export type { ChoiceAnswer, ChoiceOptionSpec, ChoiceQuestion, EvaluationEvent, JsonValue, LevelAnswer, LevelQuestion, LevelSpec, Observability, ProviderCapabilities, SemanticAnswer, SemanticProvider, SemanticProviderResponse, SemanticQuestion, SemanticRequest, State, TruthAnswer, TruthQuestion, Usage, } from "./types.ts";
|
|
64
|
+
export { defineSchema, defineSchemaWith } from "./schema.ts";
|
|
65
|
+
export type { Evaluator, SchemaDefinition, SchemaOptions } from "./schema.ts";
|
|
66
|
+
export { jev, DEFAULT_MODEL, DEFAULT_BASE_URL, JEV_CAPABILITIES } from "./providers/jev.ts";
|
|
67
|
+
export type { JevOptions } from "./providers/jev.ts";
|
|
68
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAA;AAE9C,OAAO,EAAmB,KAAK,WAAW,EAAE,MAAM,kBAAkB,CAAA;AACpE,OAAO,EAA8C,KAAK,cAAc,EAAE,MAAM,aAAa,CAAA;AAC7F,OAAO,EAAgB,KAAK,eAAe,EAAE,MAAM,eAAe,CAAA;AAClE,OAAO,EAAoC,KAAK,MAAM,EAAE,KAAK,gBAAgB,EAAE,KAAK,IAAI,EAAE,KAAK,cAAc,EAAE,MAAM,aAAa,CAAA;AAClI,OAAO,EAAoB,KAAK,SAAS,EAAE,KAAK,gBAAgB,EAAE,MAAM,aAAa,CAAA;AACrF,OAAO,KAAK,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,cAAc,CAAA;AAC1D,OAAO,EAA0B,KAAK,YAAY,EAAE,KAAK,YAAY,EAAE,MAAM,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AAY,CAAA;AAC3D,YAAY,EAAE,aAAa,EAAE,MAAM,YAAY,CAAA;AAE/C,OAAO,EAAE,oBAAoB,EAAE,eAAe,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,aAAa,CAAA;AACzF,YAAY,EAAE,eAAe,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AAE7D,OAAO,EACL,kBAAkB,EAClB,kBAAkB,EAClB,aAAa,EACb,aAAa,EACb,uBAAuB,EACvB,0BAA0B,GAC3B,MAAM,aAAa,CAAA;AAEpB,YAAY,EACV,YAAY,EACZ,gBAAgB,EAChB,cAAc,EACd,eAAe,EACf,SAAS,EACT,WAAW,EACX,aAAa,EACb,SAAS,EACT,aAAa,EACb,oBAAoB,EACpB,cAAc,EACd,gBAAgB,EAChB,wBAAwB,EACxB,gBAAgB,EAChB,eAAe,EACf,KAAK,EACL,WAAW,EACX,aAAa,EACb,KAAK,GACN,MAAM,YAAY,CAAA;AAEnB,OAAO,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAA;AAC5D,YAAY,EAAE,SAAS,EAAE,gBAAgB,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AAE7E,OAAO,EAAE,GAAG,EAAE,aAAa,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAA;AAC3F,YAAY,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAA"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { SemanticContext } from "./context.js";
|
|
2
|
+
import { semanticContext } from "./factory.js";
|
|
3
|
+
import { bindCollections } from "./collections.js";
|
|
4
|
+
import { createRuntime, globalRuntime } from "./config.js";
|
|
5
|
+
import { evaluateWith } from "./evaluate.js";
|
|
6
|
+
import { defineMetricWith, defineRuleWith } from "./define.js";
|
|
7
|
+
import { defineSchemaWith } from "./schema.js";
|
|
8
|
+
import { score as questionScore } from "./questions.js";
|
|
9
|
+
import { numberRange } from "./outputs.js";
|
|
10
|
+
function bind(runtime) {
|
|
11
|
+
const fn = (state) => semanticContext(state, runtime);
|
|
12
|
+
return Object.assign(fn, bindCollections(runtime), {
|
|
13
|
+
evaluate: (request) => evaluateWith(runtime, request),
|
|
14
|
+
defineMetric: (definition) => defineMetricWith(runtime, definition),
|
|
15
|
+
defineRule: (definition) => defineRuleWith(runtime, definition),
|
|
16
|
+
defineSchema: (definition) => defineSchemaWith(runtime, definition),
|
|
17
|
+
configure: (config) => runtime.configure(config),
|
|
18
|
+
get config() {
|
|
19
|
+
return runtime.config;
|
|
20
|
+
},
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* A private, fully configured instance. Create it once in a shared module and
|
|
25
|
+
* import it everywhere; naming it `semantic` keeps call sites identical:
|
|
26
|
+
*
|
|
27
|
+
* export const semantic = createSemantic({ provider: jev(), defaults: { timeoutMs: 5_000 } })
|
|
28
|
+
*
|
|
29
|
+
* Nothing it does touches the global `semantic` or `configureSemantic`.
|
|
30
|
+
*/
|
|
31
|
+
export function createSemantic(config = {}) {
|
|
32
|
+
return bind(createRuntime(config));
|
|
33
|
+
}
|
|
34
|
+
/** The module-level instance, configured with `configureSemantic()` or from the environment. */
|
|
35
|
+
export const semantic = bind(globalRuntime);
|
|
36
|
+
export function score(a, b, c) {
|
|
37
|
+
if (typeof a === "string")
|
|
38
|
+
return questionScore(a, b ?? {});
|
|
39
|
+
return numberRange(a ?? 0, b ?? 100, c);
|
|
40
|
+
}
|
|
41
|
+
export { SemanticContext } from "./context.js";
|
|
42
|
+
export { configureSemantic, resetSemantic, getConfig, createRuntime, BUILTIN_DEFAULTS } from "./config.js";
|
|
43
|
+
export { choose, is, DEFAULT_SCORE_FRAME } from "./questions.js";
|
|
44
|
+
export { evaluate, evaluateWith } from "./evaluate.js";
|
|
45
|
+
export { boolean, enumOf, number, numberRange, object } from "./outputs.js";
|
|
46
|
+
export { defineMetric, defineRule, defineMetricWith, defineRuleWith } from "./define.js";
|
|
47
|
+
export { compare, every, filter, find, some, rank, bindCollections } from "./collections.js";
|
|
48
|
+
export { MemoryCache, parseTtl, hashKey } from "./cache.js";
|
|
49
|
+
export { confidenceFromSpread, assertSupported, cacheKeyFor, runPlan } from "./runner.js";
|
|
50
|
+
export { LowConfidenceError, NotConfiguredError, ProviderError, SemanticError, SemanticValidationError, UnsupportedByProviderError, } from "./errors.js";
|
|
51
|
+
export { defineSchema, defineSchemaWith } from "./schema.js";
|
|
52
|
+
export { jev, DEFAULT_MODEL, DEFAULT_BASE_URL, JEV_CAPABILITIES } from "./providers/jev.js";
|
|
53
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAA;AAC9C,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAA;AAC9C,OAAO,EAAE,eAAe,EAAoB,MAAM,kBAAkB,CAAA;AACpE,OAAO,EAAE,aAAa,EAAE,aAAa,EAAqC,MAAM,aAAa,CAAA;AAC7F,OAAO,EAAE,YAAY,EAAwB,MAAM,eAAe,CAAA;AAClE,OAAO,EAAE,gBAAgB,EAAE,cAAc,EAAsE,MAAM,aAAa,CAAA;AAClI,OAAO,EAAE,gBAAgB,EAAyC,MAAM,aAAa,CAAA;AAErF,OAAO,EAAE,KAAK,IAAI,aAAa,EAAwC,MAAM,gBAAgB,CAAA;AAC7F,OAAO,EAAE,WAAW,EAAqB,MAAM,cAAc,CAAA;AAmB7D,SAAS,IAAI,CAAC,OAAgB;IAC5B,MAAM,EAAE,GAAG,CAAC,KAAY,EAAE,EAAE,CAAC,eAAe,CAAC,KAAK,EAAE,OAAO,CAAC,CAAA;IAC5D,OAAO,MAAM,CAAC,MAAM,CAAC,EAAE,EAAE,eAAe,CAAC,OAAO,CAAC,EAAE;QACjD,QAAQ,EAAE,CAAsB,OAA2B,EAA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,EAAE,YAAY,EAAE,MAAM,eAAe,CAAA;AAGtD,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,cAAc,CAAA;AAU3E,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,gBAAgB,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;AAGxF,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAA;AAG5F,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,YAAY,CAAA;AAG3D,OAAO,EAAE,oBAAoB,EAAE,eAAe,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,aAAa,CAAA;AAGzF,OAAO,EACL,kBAAkB,EAClB,kBAAkB,EAClB,aAAa,EACb,aAAa,EACb,uBAAuB,EACvB,0BAA0B,GAC3B,MAAM,aAAa,CAAA;AAwBpB,OAAO,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAA;AAG5D,OAAO,EAAE,GAAG,EAAE,aAAa,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"internal.d.ts","sourceRoot":"","sources":["../src/internal.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AAEtD,wBAAgB,mBAAmB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,GAAG,MAAM,GAAG,SAAS,CAExF"}
|
package/dist/internal.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"internal.js","sourceRoot":"","sources":["../src/internal.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAA;AAErC,OAAO,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AAEtD,MAAM,UAAU,mBAAmB,CAAC,GAAgC;IAClE,OAAO,GAAG,KAAK,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAA;AACtD,CAAC"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { ChoiceOptionSpec, JsonValue } from "./types.ts";
|
|
2
|
+
export interface BooleanOutput {
|
|
3
|
+
readonly kind: "boolean";
|
|
4
|
+
readonly describe?: string;
|
|
5
|
+
readonly trueWhen?: string | JsonValue;
|
|
6
|
+
readonly falseWhen?: string | JsonValue;
|
|
7
|
+
}
|
|
8
|
+
export interface NumberOutput {
|
|
9
|
+
readonly kind: "number";
|
|
10
|
+
readonly min: number;
|
|
11
|
+
readonly max: number;
|
|
12
|
+
readonly describe?: string;
|
|
13
|
+
readonly levels?: readonly string[];
|
|
14
|
+
}
|
|
15
|
+
export interface EnumOutput<T extends string = string> {
|
|
16
|
+
readonly kind: "enum";
|
|
17
|
+
readonly options: Readonly<Record<T, string | ChoiceOptionSpec>>;
|
|
18
|
+
readonly describe?: string;
|
|
19
|
+
}
|
|
20
|
+
export interface ObjectOutput<F extends Record<string, AnyOutput> = Record<string, AnyOutput>> {
|
|
21
|
+
readonly kind: "object";
|
|
22
|
+
readonly fields: F;
|
|
23
|
+
}
|
|
24
|
+
export type AnyOutput = BooleanOutput | NumberOutput | EnumOutput | ObjectOutput;
|
|
25
|
+
export type OutputValue<O> = O extends BooleanOutput ? boolean : O extends NumberOutput ? number : O extends EnumOutput<infer T> ? T : O extends ObjectOutput<infer F> ? {
|
|
26
|
+
[K in keyof F]: OutputValue<F[K]>;
|
|
27
|
+
} : never;
|
|
28
|
+
export declare function boolean(options?: Omit<BooleanOutput, "kind">): BooleanOutput;
|
|
29
|
+
export declare function number(options?: {
|
|
30
|
+
min?: number;
|
|
31
|
+
max?: number;
|
|
32
|
+
describe?: string;
|
|
33
|
+
levels?: readonly string[];
|
|
34
|
+
}): NumberOutput;
|
|
35
|
+
export declare function enumOf<const T extends readonly string[]>(options: T, describe?: string): EnumOutput<T[number]>;
|
|
36
|
+
export declare function enumOf<const T extends Readonly<Record<string, string | ChoiceOptionSpec>>>(options: T, describe?: string): EnumOutput<keyof T & string>;
|
|
37
|
+
export declare function object<const F extends Record<string, AnyOutput>>(fields: F): ObjectOutput<F>;
|
|
38
|
+
/** Output-shaped score, as distinct from the question-shaped `score(criterion)`. */
|
|
39
|
+
export declare function numberRange(min?: number, max?: number, describe?: string): NumberOutput;
|
|
40
|
+
//# sourceMappingURL=outputs.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"outputs.d.ts","sourceRoot":"","sources":["../src/outputs.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,SAAS,EAAE,MAAM,YAAY,CAAA;AAE7D,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAA;IACxB,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAA;IAC1B,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;IACtC,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;CACxC;AAED,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAA;IACvB,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAA;IACpB,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAA;IACpB,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAA;IAC1B,QAAQ,CAAC,MAAM,CAAC,EAAE,SAAS,MAAM,EAAE,CAAA;CACpC;AAED,MAAM,WAAW,UAAU,CAAC,CAAC,SAAS,MAAM,GAAG,MAAM;IACnD,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IACrB,QAAQ,CAAC,OAAO,EA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CAAC,CAAA;AAC/G,wBAAgB,MAAM,CAAC,KAAK,CAAC,CAAC,SAAS,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,gBAAgB,CAAC,CAAC,EACxF,OAAO,EAAE,CAAC,EACV,QAAQ,CAAC,EAAE,MAAM,GAChB,UAAU,CAAC,MAAM,CAAC,GAAG,MAAM,CAAC,CAAA;AAQ/B,wBAAgB,MAAM,CAAC,KAAK,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,EAAE,MAAM,EAAE,CAAC,GAAG,YAAY,CAAC,CAAC,CAAC,CAE5F;AAED,oFAAoF;AACpF,wBAAgB,WAAW,CAAC,GAAG,SAAI,EAAE,GAAG,SAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,YAAY,CAE/E"}
|
package/dist/outputs.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export function boolean(options = {}) {
|
|
2
|
+
return { kind: "boolean", ...options };
|
|
3
|
+
}
|
|
4
|
+
export function number(options = {}) {
|
|
5
|
+
return { kind: "number", min: options.min ?? 0, max: options.max ?? 100, ...options };
|
|
6
|
+
}
|
|
7
|
+
export function enumOf(options, describe) {
|
|
8
|
+
const map = Array.isArray(options)
|
|
9
|
+
? Object.fromEntries(options.map((key) => [key, key]))
|
|
10
|
+
: { ...options };
|
|
11
|
+
return { kind: "enum", options: map, ...(describe !== undefined ? { describe } : {}) };
|
|
12
|
+
}
|
|
13
|
+
export function object(fields) {
|
|
14
|
+
return { kind: "object", fields };
|
|
15
|
+
}
|
|
16
|
+
/** Output-shaped score, as distinct from the question-shaped `score(criterion)`. */
|
|
17
|
+
export function numberRange(min = 0, max = 100, describe) {
|
|
18
|
+
return { kind: "number", min, max, ...(describe !== undefined ? { describe } : {}) };
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=outputs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"outputs.js","sourceRoot":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AAE,CAAC,EAAE,CAAA;AACtF,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { ProviderCapabilities, SemanticProvider } from "../types.ts";
|
|
2
|
+
/**
|
|
3
|
+
* Pinned on purpose.
|
|
4
|
+
*
|
|
5
|
+
* `jev-latest` is an alias that moves. A silent move would invalidate cached
|
|
6
|
+
* answers, shift production behaviour, and quietly detach dataset evaluations
|
|
7
|
+
* from the model they were measured against.
|
|
8
|
+
*/
|
|
9
|
+
export declare const DEFAULT_MODEL = "jev-1.13.0";
|
|
10
|
+
export declare const DEFAULT_BASE_URL = "https://api.typesafe.ai/v1";
|
|
11
|
+
export declare const JEV_CAPABILITIES: ProviderCapabilities;
|
|
12
|
+
export interface JevOptions {
|
|
13
|
+
apiKey?: string;
|
|
14
|
+
model?: string;
|
|
15
|
+
baseUrl?: string;
|
|
16
|
+
fetch?: typeof globalThis.fetch;
|
|
17
|
+
/** Attempts on 429 and 5xx, including the first. Defaults to 3. */
|
|
18
|
+
maxRetries?: number;
|
|
19
|
+
}
|
|
20
|
+
export declare function jev(options?: JevOptions): SemanticProvider;
|
|
21
|
+
//# sourceMappingURL=jev.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"jev.d.ts","sourceRoot":"","sources":["../../src/providers/jev.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAGV,oBAAoB,EAEpB,gBAAgB,EAKjB,MAAM,aAAa,CAAA;AAEpB;;;;;;GAMG;AACH,eAAO,MAAM,aAAa,eAAe,CAAA;AACzC,eAAO,MAAM,gBAAgB,+BAA+B,CAAA;AAE5D,eAAO,MAAM,gBAAgB,EAAE,oBAQ9B,CAAA;AAED,MAAM,WAAW,UAAU;IACzB,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,KAAK,CAAC,EAAE,OAAO,UAAU,CAAC,KAAK,CAAA;IAC/B,mEAAmE;IACnE,UAAU,CAAC,EAAE,MAAM,CAAA;CACpB;AAwED,wBAAgB,GAAG,CAAC,OAAO,GAAE,UAAe,GAAG,gBAAgB,CA2F9D"}
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
import { ProviderError } from "../errors.js";
|
|
2
|
+
/**
|
|
3
|
+
* Pinned on purpose.
|
|
4
|
+
*
|
|
5
|
+
* `jev-latest` is an alias that moves. A silent move would invalidate cached
|
|
6
|
+
* answers, shift production behaviour, and quietly detach dataset evaluations
|
|
7
|
+
* from the model they were measured against.
|
|
8
|
+
*/
|
|
9
|
+
export const DEFAULT_MODEL = "jev-1.13.0";
|
|
10
|
+
export const DEFAULT_BASE_URL = "https://api.typesafe.ai/v1";
|
|
11
|
+
export const JEV_CAPABILITIES = {
|
|
12
|
+
maxChoiceOptions: 255,
|
|
13
|
+
levelRange: [2, 10],
|
|
14
|
+
maxStateTokens: 32_000,
|
|
15
|
+
maxTotalTokens: 64_000,
|
|
16
|
+
/** Decision-only: there is no generated text, so no generated rationale. */
|
|
17
|
+
generatesText: false,
|
|
18
|
+
batching: true,
|
|
19
|
+
};
|
|
20
|
+
function toPayload(question) {
|
|
21
|
+
if (question.kind === "truth") {
|
|
22
|
+
const truth = question;
|
|
23
|
+
const criteria = {};
|
|
24
|
+
if (truth.trueWhen !== undefined)
|
|
25
|
+
criteria["true"] = truth.trueWhen;
|
|
26
|
+
if (truth.falseWhen !== undefined)
|
|
27
|
+
criteria["false"] = truth.falseWhen;
|
|
28
|
+
return {
|
|
29
|
+
type: "noul",
|
|
30
|
+
instructions: truth.instructions,
|
|
31
|
+
...(Object.keys(criteria).length > 0 ? { criteria } : {}),
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
if (question.kind === "choice") {
|
|
35
|
+
const choice = question;
|
|
36
|
+
return { type: "choice", instructions: choice.instructions, criteria: choice.options };
|
|
37
|
+
}
|
|
38
|
+
const level = question;
|
|
39
|
+
return {
|
|
40
|
+
type: "score",
|
|
41
|
+
instructions: level.instructions,
|
|
42
|
+
criteria: level.levels.map((entry) => (typeof entry === "string" ? entry : entry)),
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
function parseAnswer(key, raw, question) {
|
|
46
|
+
if (raw === null || typeof raw !== "object") {
|
|
47
|
+
throw new ProviderError(`Malformed answer for "${key}": expected an object, got ${typeof raw}.`);
|
|
48
|
+
}
|
|
49
|
+
const value = raw;
|
|
50
|
+
if (question.kind === "truth") {
|
|
51
|
+
const noul = value["noul"];
|
|
52
|
+
if (typeof noul !== "number")
|
|
53
|
+
throw new ProviderError(`Answer "${key}" is missing a numeric \`noul\`.`);
|
|
54
|
+
return { kind: "truth", probability: noul };
|
|
55
|
+
}
|
|
56
|
+
if (question.kind === "choice") {
|
|
57
|
+
const choice = value["choice"];
|
|
58
|
+
if (typeof choice !== "string")
|
|
59
|
+
throw new ProviderError(`Answer "${key}" is missing a \`choice\`.`);
|
|
60
|
+
const probabilities = value["probabilities"] ?? { [choice]: 1 };
|
|
61
|
+
const confidence = typeof value["confidence"] === "number" ? value["confidence"] : deriveConfidence(Object.values(probabilities));
|
|
62
|
+
return { kind: "choice", choice, probabilities, confidence };
|
|
63
|
+
}
|
|
64
|
+
const level = value["score"];
|
|
65
|
+
if (typeof level !== "number")
|
|
66
|
+
throw new ProviderError(`Answer "${key}" is missing a numeric \`score\`.`);
|
|
67
|
+
const raws = value["probabilities"];
|
|
68
|
+
const probabilities = Array.isArray(raws)
|
|
69
|
+
? raws
|
|
70
|
+
: Object.entries(raws ?? {})
|
|
71
|
+
.sort(([a], [b]) => Number(a) - Number(b))
|
|
72
|
+
.map(([, probability]) => probability);
|
|
73
|
+
const confidence = typeof value["confidence"] === "number" ? value["confidence"] : deriveConfidence(probabilities);
|
|
74
|
+
return { kind: "level", level, probabilities, confidence };
|
|
75
|
+
}
|
|
76
|
+
/** Fallback only: used when the API omits an explicit confidence. */
|
|
77
|
+
function deriveConfidence(probabilities) {
|
|
78
|
+
if (probabilities.length === 0)
|
|
79
|
+
return 0;
|
|
80
|
+
return Math.max(...probabilities);
|
|
81
|
+
}
|
|
82
|
+
const RETRYABLE = new Set([408, 409, 429, 500, 502, 503, 504, 529]);
|
|
83
|
+
export function jev(options = {}) {
|
|
84
|
+
// Resolved per request, not at construction: a module that creates the
|
|
85
|
+
// provider must be importable in tests and builds that have no key.
|
|
86
|
+
const resolveKey = () => {
|
|
87
|
+
const apiKey = options.apiKey ?? process.env["JEV_API_KEY"];
|
|
88
|
+
if (!apiKey) {
|
|
89
|
+
throw new ProviderError("No API key. Pass jev({ apiKey }) or set JEV_API_KEY. Keys: https://console.typesafe.ai/keys");
|
|
90
|
+
}
|
|
91
|
+
return apiKey;
|
|
92
|
+
};
|
|
93
|
+
const model = options.model ?? process.env["JEV_MODEL"] ?? DEFAULT_MODEL;
|
|
94
|
+
const baseUrl = (options.baseUrl ?? process.env["JEV_BASE_URL"] ?? DEFAULT_BASE_URL).replace(/\/+$/, "");
|
|
95
|
+
const doFetch = options.fetch ?? globalThis.fetch;
|
|
96
|
+
const maxRetries = options.maxRetries ?? 3;
|
|
97
|
+
return {
|
|
98
|
+
name: "jev",
|
|
99
|
+
model,
|
|
100
|
+
capabilities: JEV_CAPABILITIES,
|
|
101
|
+
async evaluate(request) {
|
|
102
|
+
const apiKey = resolveKey();
|
|
103
|
+
const questions = {};
|
|
104
|
+
for (const [key, question] of Object.entries(request.questions))
|
|
105
|
+
questions[key] = toPayload(question);
|
|
106
|
+
const body = JSON.stringify({ state: request.state, model, questions });
|
|
107
|
+
let lastError;
|
|
108
|
+
for (let attempt = 0; attempt < maxRetries; attempt++) {
|
|
109
|
+
const signals = [];
|
|
110
|
+
if (request.signal)
|
|
111
|
+
signals.push(request.signal);
|
|
112
|
+
if (request.timeoutMs)
|
|
113
|
+
signals.push(AbortSignal.timeout(request.timeoutMs));
|
|
114
|
+
let response;
|
|
115
|
+
try {
|
|
116
|
+
response = await doFetch(`${baseUrl}/systemone`, {
|
|
117
|
+
method: "POST",
|
|
118
|
+
headers: {
|
|
119
|
+
authorization: `Bearer ${apiKey}`,
|
|
120
|
+
"content-type": "application/json",
|
|
121
|
+
},
|
|
122
|
+
body,
|
|
123
|
+
...(signals.length > 0 ? { signal: AbortSignal.any(signals) } : {}),
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
catch (error) {
|
|
127
|
+
lastError = error;
|
|
128
|
+
if (attempt === maxRetries - 1)
|
|
129
|
+
throw new ProviderError(`Request to Jev failed: ${String(error)}`);
|
|
130
|
+
await backoff(attempt);
|
|
131
|
+
continue;
|
|
132
|
+
}
|
|
133
|
+
if (!response.ok) {
|
|
134
|
+
const detail = await response.text().catch(() => "");
|
|
135
|
+
if (RETRYABLE.has(response.status) && attempt < maxRetries - 1) {
|
|
136
|
+
lastError = detail;
|
|
137
|
+
await backoff(attempt, response.headers.get("retry-after"));
|
|
138
|
+
continue;
|
|
139
|
+
}
|
|
140
|
+
throw new ProviderError(`Jev returned ${response.status}: ${detail.slice(0, 500)}`, response.status);
|
|
141
|
+
}
|
|
142
|
+
const payload = (await response.json());
|
|
143
|
+
// The envelope has varied between SDK surfaces; accept either shape.
|
|
144
|
+
const container = payload["answers"] ?? payload;
|
|
145
|
+
const answers = {};
|
|
146
|
+
for (const [key, question] of Object.entries(request.questions)) {
|
|
147
|
+
const raw = container[key];
|
|
148
|
+
if (raw === undefined)
|
|
149
|
+
throw new ProviderError(`Jev returned no answer for "${key}".`);
|
|
150
|
+
answers[key] = parseAnswer(key, raw, question);
|
|
151
|
+
}
|
|
152
|
+
const usage = payload["usage"];
|
|
153
|
+
return {
|
|
154
|
+
answers,
|
|
155
|
+
model: payload["model"] ?? model,
|
|
156
|
+
...(usage
|
|
157
|
+
? {
|
|
158
|
+
usage: {
|
|
159
|
+
inputTokens: usage.input_tokens ?? usage.inputTokens ?? 0,
|
|
160
|
+
outputTokens: usage.output_tokens ?? usage.outputTokens ?? 0,
|
|
161
|
+
},
|
|
162
|
+
}
|
|
163
|
+
: {}),
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
throw new ProviderError(`Jev request exhausted ${maxRetries} attempts: ${String(lastError)}`);
|
|
167
|
+
},
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
async function backoff(attempt, retryAfter) {
|
|
171
|
+
const hinted = retryAfter ? Number(retryAfter) * 1000 : NaN;
|
|
172
|
+
const delay = Number.isFinite(hinted) ? hinted : 2 ** attempt * 250 + Math.random() * 100;
|
|
173
|
+
await new Promise((resolve) => setTimeout(resolve, delay));
|
|
174
|
+
}
|
|
175
|
+
//# sourceMappingURL=jev.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"jev.js","sourceRoot":"","sources":["../../src/providers/jev.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAA;AAa5C;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,YAAY,CAAA;AACzC,MAAM,CAAC,MAAM,gBAAgB,GAAG,4BAA4B,CAAA;AAE5D,MAAM,CAAC,MAAM,gBAAgB,GAAyB;IACpD,gBAAgB,EAAE,GAAG;IACrB,UAAU,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC;IACnB,cAAc,EAAE,MAAM;IACtB,cAAc,EAAE,MAAM;IACtB,4EAA4E;IAC5E,aAAa,EAAE,KAAK;IACpB,QAAQ,EAAE,IAAI;CACf,CAAA;AAiBD,SAAS,SAAS,CAAC,QAA0B;IAC3C,IAAI,QAAQ,CAAC,IAAI,KAAK,OAAO,EAAE,CAAC;QAC9B,MAAM,KAAK,GAAG,QAAyB,CAAA;QACvC,MAAM,QAAQ,GAA4B,EAAE,CAAA;QAC5C,IAAI,KAAK,CAAC,QAAQ,KAAK,SAAS;YAAE,QAAQ,CAAC,MAAM,CAAC,GAAG,KAAK,CAAC,QAAQ,CAAA;QACnE,IAAI,KAAK,CAAC,SAAS,KAAK,SAAS;YAAE,QAAQ,C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