@providerkit/core 0.30.0 → 0.32.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.
Files changed (137) hide show
  1. package/README.md +101 -5
  2. package/THIRD_PARTY_NOTICES +144 -0
  3. package/dist/auth/chatgpt-models.js.map +1 -1
  4. package/dist/auth/oauth.d.ts.map +1 -1
  5. package/dist/auth/oauth.js.map +1 -1
  6. package/dist/capability.js.map +1 -1
  7. package/dist/context.d.ts +4 -3
  8. package/dist/context.d.ts.map +1 -1
  9. package/dist/context.js +19 -5
  10. package/dist/context.js.map +1 -1
  11. package/dist/decisions.js.map +1 -1
  12. package/dist/errors.d.ts.map +1 -1
  13. package/dist/errors.js.map +1 -1
  14. package/dist/fallback.d.ts +3 -0
  15. package/dist/fallback.d.ts.map +1 -1
  16. package/dist/fallback.js +9 -5
  17. package/dist/fallback.js.map +1 -1
  18. package/dist/gate.js.map +1 -1
  19. package/dist/hosted/anthropic.d.ts +30 -0
  20. package/dist/hosted/anthropic.d.ts.map +1 -0
  21. package/dist/hosted/anthropic.js +465 -0
  22. package/dist/hosted/anthropic.js.map +1 -0
  23. package/dist/hosted/gemini.d.ts +22 -0
  24. package/dist/hosted/gemini.d.ts.map +1 -0
  25. package/dist/hosted/gemini.js +440 -0
  26. package/dist/hosted/gemini.js.map +1 -0
  27. package/dist/hosted/openai.d.ts +33 -0
  28. package/dist/hosted/openai.d.ts.map +1 -0
  29. package/dist/hosted/openai.js +107 -0
  30. package/dist/hosted/openai.js.map +1 -0
  31. package/dist/hosted/responses.d.ts +28 -0
  32. package/dist/hosted/responses.d.ts.map +1 -0
  33. package/dist/hosted/responses.js +358 -0
  34. package/dist/hosted/responses.js.map +1 -0
  35. package/dist/hosted/shared.d.ts +107 -0
  36. package/dist/hosted/shared.d.ts.map +1 -0
  37. package/dist/hosted/shared.js +264 -0
  38. package/dist/hosted/shared.js.map +1 -0
  39. package/dist/hosted/types.d.ts +191 -0
  40. package/dist/hosted/types.d.ts.map +1 -0
  41. package/dist/hosted/types.js +10 -0
  42. package/dist/hosted/types.js.map +1 -0
  43. package/dist/hosted.d.ts +33 -0
  44. package/dist/hosted.d.ts.map +1 -0
  45. package/dist/hosted.js +61 -0
  46. package/dist/hosted.js.map +1 -0
  47. package/dist/index.d.ts +8 -7
  48. package/dist/index.d.ts.map +1 -1
  49. package/dist/index.js +8 -7
  50. package/dist/index.js.map +1 -1
  51. package/dist/key-pool.d.ts.map +1 -1
  52. package/dist/key-pool.js.map +1 -1
  53. package/dist/otel.d.ts +26 -0
  54. package/dist/otel.d.ts.map +1 -0
  55. package/dist/otel.js +263 -0
  56. package/dist/otel.js.map +1 -0
  57. package/dist/presets.d.ts +2 -2
  58. package/dist/presets.d.ts.map +1 -1
  59. package/dist/providers/anthropic.d.ts +75 -1
  60. package/dist/providers/anthropic.d.ts.map +1 -1
  61. package/dist/providers/anthropic.js +207 -135
  62. package/dist/providers/anthropic.js.map +1 -1
  63. package/dist/providers/factory.d.ts +10 -0
  64. package/dist/providers/factory.d.ts.map +1 -1
  65. package/dist/providers/factory.js +31 -23
  66. package/dist/providers/factory.js.map +1 -1
  67. package/dist/providers/gemini.d.ts +123 -1
  68. package/dist/providers/gemini.d.ts.map +1 -1
  69. package/dist/providers/gemini.js +114 -54
  70. package/dist/providers/gemini.js.map +1 -1
  71. package/dist/providers/hosted-codecs.d.ts +10 -0
  72. package/dist/providers/hosted-codecs.d.ts.map +1 -0
  73. package/dist/providers/hosted-codecs.js +8 -0
  74. package/dist/providers/hosted-codecs.js.map +1 -0
  75. package/dist/providers/openai.d.ts +69 -0
  76. package/dist/providers/openai.d.ts.map +1 -1
  77. package/dist/providers/openai.js +38 -14
  78. package/dist/providers/openai.js.map +1 -1
  79. package/dist/providers/responses.d.ts +123 -0
  80. package/dist/providers/responses.d.ts.map +1 -1
  81. package/dist/providers/responses.js +57 -22
  82. package/dist/providers/responses.js.map +1 -1
  83. package/dist/providers/speech-factory.js.map +1 -1
  84. package/dist/registry.d.ts +3 -0
  85. package/dist/registry.d.ts.map +1 -1
  86. package/dist/registry.js +8 -4
  87. package/dist/registry.js.map +1 -1
  88. package/dist/retry.js.map +1 -1
  89. package/dist/speech-core.d.ts.map +1 -1
  90. package/dist/speech-core.js.map +1 -1
  91. package/dist/tools.d.ts.map +1 -1
  92. package/dist/tools.js.map +1 -1
  93. package/dist/transcription-core.d.ts.map +1 -1
  94. package/dist/transcription-core.js.map +1 -1
  95. package/dist/transport.js.map +1 -1
  96. package/dist/turn.d.ts +10 -1
  97. package/dist/turn.d.ts.map +1 -1
  98. package/dist/turn.js +53 -1
  99. package/dist/turn.js.map +1 -1
  100. package/dist/types.d.ts +51 -0
  101. package/dist/types.d.ts.map +1 -1
  102. package/dist/types.js.map +1 -1
  103. package/dist/usage.d.ts +10 -1
  104. package/dist/usage.d.ts.map +1 -1
  105. package/dist/usage.js +40 -2
  106. package/dist/usage.js.map +1 -1
  107. package/dist/watchdog.d.ts +6 -0
  108. package/dist/watchdog.d.ts.map +1 -1
  109. package/dist/watchdog.js +10 -2
  110. package/dist/watchdog.js.map +1 -1
  111. package/package.json +19 -5
  112. package/src/context.ts +21 -5
  113. package/src/fallback.ts +21 -6
  114. package/src/hosted/anthropic.ts +512 -0
  115. package/src/hosted/gemini.ts +510 -0
  116. package/src/hosted/openai.ts +137 -0
  117. package/src/hosted/responses.ts +420 -0
  118. package/src/hosted/shared.ts +341 -0
  119. package/src/hosted/types.ts +214 -0
  120. package/src/hosted.ts +101 -0
  121. package/src/index.ts +64 -7
  122. package/src/otel.ts +306 -0
  123. package/src/providers/anthropic.ts +252 -143
  124. package/src/providers/factory.ts +127 -82
  125. package/src/providers/gemini.ts +184 -60
  126. package/src/providers/hosted-codecs.ts +29 -0
  127. package/src/providers/openai.ts +52 -15
  128. package/src/providers/responses.ts +93 -24
  129. package/src/registry.ts +14 -4
  130. package/src/turn.ts +55 -1
  131. package/src/types.ts +62 -1
  132. package/src/usage.ts +32 -2
  133. package/src/watchdog.ts +12 -2
  134. package/dist/jev.d.ts +0 -123
  135. package/dist/jev.d.ts.map +0 -1
  136. package/dist/jev.js +0 -278
  137. package/dist/jev.js.map +0 -1
package/dist/jev.d.ts DELETED
@@ -1,123 +0,0 @@
1
- import { type Attribution } from "./attribution.ts";
2
- import { type RetryOptions } from "./retry.ts";
3
- import type { TokenUsage } from "./types.ts";
4
- export type JevHost = "typesafe" | "openrouter" | "cloudflare" | "vercel";
5
- /** What a question asks, beyond its options: a sentence, or any JSON the
6
- * model should read alongside it (a goal, a list of rules). */
7
- export type JevInstructions = string | Record<string, unknown> | readonly unknown[];
8
- /** Pick one option. */
9
- export interface ChoiceQuestion<Option extends string = string> {
10
- type: "choice";
11
- instructions?: JevInstructions;
12
- /** Each option, mapped to what it means. Use `null` when its name says it all.
13
- * TypeSafe takes up to 255. */
14
- criteria: Record<Option, unknown>;
15
- }
16
- /** Is this statement true? */
17
- export interface NoulQuestion {
18
- type: "noul";
19
- instructions: JevInstructions;
20
- /** What yes and what no mean, when the statement alone leaves it open. */
21
- criteria?: {
22
- true?: string;
23
- false?: string;
24
- };
25
- }
26
- /** Where on this ordered scale? */
27
- export interface ScoreQuestion {
28
- type: "score";
29
- instructions?: JevInstructions;
30
- /** The levels, lowest first. TypeSafe takes 2 to 10. */
31
- criteria: readonly unknown[];
32
- }
33
- export type JevQuestion = ChoiceQuestion | NoulQuestion | ScoreQuestion;
34
- export interface ChoiceAnswer<Option extends string = string> {
35
- type: "choice";
36
- choice: Option;
37
- /** Every offered option's probability. The whole distribution is kept
38
- * because a caller acting on it needs more than the pick: the runner-up,
39
- * P(yes) when the pick was no, a joint probability across two questions. */
40
- probabilities: Record<Option, number>;
41
- /** How peaked `probabilities` is, from 0 to 1. Not the probability of the pick.
42
- * TypeSafe's own example spreads 0.57 / 0.43 and reports 0.35, so reading
43
- * it as P(pick) would put the pick below the option it beat. Null when the
44
- * host sent none. */
45
- confidence: number | null;
46
- }
47
- export interface NoulAnswer {
48
- type: "noul";
49
- /** The probability that the statement is true. */
50
- noul: number;
51
- }
52
- export interface ScoreAnswer {
53
- type: "score";
54
- /** The probability-weighted level, fractional: 1.43 sits between level 1
55
- * and level 2, nearer 1. */
56
- score: number;
57
- /** Each level's probability, keyed by its index as the wire sends it:
58
- * "0", "1", … */
59
- probabilities: Record<string, number>;
60
- confidence: number | null;
61
- }
62
- export type JevAnswer = ChoiceAnswer | NoulAnswer | ScoreAnswer;
63
- /** The answer type a question gets back. A choice's options carry through. */
64
- export type AnswerTo<Q> = Q extends ChoiceQuestion<infer Option extends string> ? ChoiceAnswer<Option> : Q extends NoulQuestion ? NoulAnswer : Q extends ScoreQuestion ? ScoreAnswer : never;
65
- export interface JevReply<Q extends Record<string, JevQuestion>> {
66
- /** One per question. `null` when that answer did not pass the checks in
67
- * `readAnswer`. Each fails alone: in a fan-out, a malformed answer to a
68
- * question the caller never acts on must not cost the one it does. */
69
- answers: {
70
- [Id in keyof Q]: AnswerTo<Q[Id]> | null;
71
- };
72
- usage: TokenUsage;
73
- /** The model that answered, as the host names it: `jev-1.13.0` on
74
- * TypeSafe, `typesafe/jev-1.13-20260917` on OpenRouter. */
75
- model: string;
76
- }
77
- export interface JevConfig {
78
- host: JevHost;
79
- apiKey: string;
80
- /** Cloudflare only: the account the Workers AI call runs on. */
81
- accountId?: string;
82
- /** Defaults to each host's always-current alias. */
83
- model?: string;
84
- /** OpenRouter only: names your app on its rankings. */
85
- attribution?: Attribution;
86
- /** One attempt's deadline, in ms. Default 15 s: Jev answers in under a
87
- * second, so a call still open after this is not coming back. */
88
- timeoutMs?: number;
89
- /** Default: three attempts, transient failures only, Retry-After honoured. */
90
- retry?: Omit<RetryOptions, "signal">;
91
- /** Swapped in tests, or to route through a proxy. */
92
- fetchImpl?: typeof fetch;
93
- }
94
- export interface JevClient {
95
- readonly host: JevHost;
96
- readonly model: string;
97
- ask<Q extends Record<string, JevQuestion>>(state: unknown, questions: Q, opts?: {
98
- signal?: AbortSignal;
99
- }): Promise<JevReply<Q>>;
100
- /** Proves the key, the account and the model work, with one real question:
101
- * about 40 input tokens, a few millionths of a dollar. A free read (a
102
- * model list, a balance) proves only the key, not that this account can
103
- * run this model. Vercel has no such free read. Throws the classified failure. */
104
- checkKey(opts?: {
105
- signal?: AbortSignal;
106
- }): Promise<void>;
107
- }
108
- /**
109
- * One answer, checked against the question that asked it, or null.
110
- *
111
- * A Jev answer usually becomes an action (a click, a label, a route), so it is
112
- * read fail-closed: the right type; for a choice, a pick among the offered
113
- * options that is also the most likely one in its own full distribution. A
114
- * distribution is never rebuilt from `confidence`, which measures spread, not
115
- * the pick.
116
- *
117
- * `ask` runs this on every answer. It is exported for the app that has to
118
- * keep its own request (its own error copy, its own auth refresh) and can
119
- * still take the checks.
120
- */
121
- export declare function readAnswer<Q extends JevQuestion>(question: Q, raw: unknown): AnswerTo<Q> | null;
122
- export declare function createJevClient(config: JevConfig): JevClient;
123
- //# sourceMappingURL=jev.d.ts.map
package/dist/jev.d.ts.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"jev.d.ts","sourceRoot":"","sources":["../src/jev.ts"],"names":[],"mappings":"AAmBA,OAAO,EAAsB,KAAK,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAGxE,OAAO,EAAa,KAAK,YAAY,EAAE,MAAM,YAAY,CAAC;AAE1D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAE7C,MAAM,MAAM,OAAO,GAAG,UAAU,GAAG,YAAY,GAAG,YAAY,GAAG,QAAQ,CAAC;AAE1E;gEACgE;AAChE,MAAM,MAAM,eAAe,GAAG,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS,OAAO,EAAE,CAAC;AAEpF,uBAAuB;AACvB,MAAM,WAAW,cAAc,CAAC,MAAM,SAAS,MAAM,GAAG,MAAM;IAC5D,IAAI,EAAE,QAAQ,CAAC;IACf,YAAY,CAAC,EAAE,eAAe,CAAC;IAC/B;oCACgC;IAChC,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,CAAC,CAAC,CAAC;IACxB;;;uFAGmF;IACnF,QAAQ,CAAC,IAAI,CAAC,EAAE;QAAE,MAAM,CAAC,EAAE,WAAW,CAAA;KAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CAC1D;AA2ID;;;;;;;;;;;;GAYG;AACH,wBAAgB,UAAU,CAAC,CAAC,SAAS,WAAW,EAAE,QAAQ,EAAE,CAAC,EAAE,GAAG,EAAE,OAAO,GAAG,QAAQ,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC;AAgEjG,wBAAgB,eAAe,CAAC,MAAM,EAAE,SAAS,GAAG,SAAS,CAmF5D"}
package/dist/jev.js DELETED
@@ -1,278 +0,0 @@
1
- // Jev — TypeSafe's decision model, on any of the four hosts that serve it.
2
- // `@providerkit/core/jev`.
3
- //
4
- // Jev does not write text. It reads a `state` and answers typed questions —
5
- // pick one option (choice), is this true (noul), where on this scale (score) —
6
- // each with the probabilities behind the answer, in well under a second, for
7
- // $0.042 per million input tokens with output free (TypeSafe's list price,
8
- // 2026-09-27). That is why it is not a `Provider`: there is no stream and no
9
- // message, nothing the chat seam could carry without lying about it. It gets
10
- // its own entry point and borrows the rest of the package — the error
11
- // envelope, the classifier, retry — so a throttled Jev call behaves exactly
12
- // like a throttled chat call.
13
- //
14
- // The four hosts serve one model and read the same questions. They differ
15
- // only in the envelope: the URL, the auth headers, how the body is wrapped,
16
- // and where the answers and the usage sit in the reply. One row per host.
17
- //
18
- // Prices stay with the caller, for the reason in usage.ts. OpenRouter reports
19
- // what each call cost; the caller's `ModelRate` prices the other three.
20
- import { attributionHeaders } from "./attribution.js";
21
- import { ProviderError, streamError } from "./errors.js";
22
- import { openRouterCostUsd } from "./providers/openai.js";
23
- import { withRetry } from "./retry.js";
24
- import { postJson } from "./transport.js";
25
- const DEFAULT_TIMEOUT_MS = 15_000;
26
- const record = (value) => typeof value === "object" && value !== null && !Array.isArray(value)
27
- ? value
28
- : undefined;
29
- const HOSTS = {
30
- typesafe: {
31
- model: "jev-latest",
32
- url: () => "https://api.typesafe.ai/v1/systemone",
33
- headers: () => ({}),
34
- body: (model, state, questions) => ({ model, state, questions }),
35
- unwrap: record,
36
- },
37
- openrouter: {
38
- // Both this alias and the pinned `typesafe/jev-1.13` answered, live,
39
- // 2026-09-27. OpenRouter also serves `/api/alpha/decisions`; this is the
40
- // path its Jev guide documents next to it, and the one that answered.
41
- model: "~typesafe/jev-latest",
42
- url: () => "https://openrouter.ai/api/v1/systemone",
43
- headers: (config) => attributionHeaders(config.attribution ?? {}),
44
- body: (model, state, questions) => ({ model, state, questions }),
45
- unwrap: record,
46
- },
47
- cloudflare: {
48
- model: "typesafe/jev",
49
- url: (config) => `https://api.cloudflare.com/client/v4/accounts/${encodeURIComponent(config.accountId ?? "")}/ai/run`,
50
- headers: () => ({}),
51
- body: (model, state, questions) => ({ model, input: { state, questions } }),
52
- // The v4 envelope puts the model's reply under `result`, and a task
53
- // record can wrap it once more. A task that has not finished carries no
54
- // answers, so it fails as an unreadable reply without a status check —
55
- // which is as well, since two sources disagree on that field's name.
56
- unwrap: (json) => {
57
- const result = record(record(json)?.result);
58
- return record(result?.result) ?? result;
59
- },
60
- },
61
- vercel: {
62
- model: "typesafe-ai/jev",
63
- url: () => "https://ai-gateway.vercel.sh/v4/ai/evaluation-model",
64
- // Without these the gateway answers 400 "Unsupported gateway protocol
65
- // version" (checked, 2026-09-27). The model rides in a header, not the body.
66
- headers: (_config, model) => ({
67
- "ai-gateway-protocol-version": "0.0.1",
68
- "ai-gateway-auth-method": "api-key",
69
- "ai-evaluation-model-specification-version": "4",
70
- "ai-model-id": model,
71
- }),
72
- // The gateway's own spelling of noul is `boolean`: its validator lists
73
- // exactly `choice | score | boolean` (checked, 2026-09-27).
74
- body: (_model, state, questions) => ({
75
- state,
76
- questions: Object.fromEntries(Object.entries(questions).map(([id, q]) => [
77
- id,
78
- q.type === "noul" ? { ...q, type: "boolean" } : q,
79
- ])),
80
- }),
81
- unwrap: fromVercel,
82
- },
83
- };
84
- /**
85
- * Vercel's reply, back in TypeSafe's shape: a `boolean` answer carries its
86
- * probability as `probability`, confidence moves out of the answer into
87
- * `providerMetadata.typesafe.confidence`, and usage is camelCase.
88
- *
89
- * ponytail: read from @jkudish/jev-agent-tools' adapter, not from a recorded
90
- * reply. No Vercel key has run it here. If a real reply disagrees, this
91
- * function is the whole fix.
92
- */
93
- function fromVercel(json) {
94
- const reply = record(json);
95
- const answers = record(reply?.answers);
96
- if (!reply || !answers)
97
- return reply;
98
- const confidence = record(record(record(reply.providerMetadata)?.typesafe)?.confidence) ?? {};
99
- const usage = record(reply.usage);
100
- return {
101
- model: reply.model,
102
- answers: Object.fromEntries(Object.entries(answers).map(([id, raw]) => {
103
- const answer = record(raw);
104
- if (answer?.type === "boolean")
105
- return [id, { type: "noul", noul: answer.probability }];
106
- if (!answer || answer.confidence !== undefined)
107
- return [id, raw];
108
- return [id, { ...answer, confidence: confidence[id] }];
109
- })),
110
- usage: usage && { input_tokens: usage.inputTokens, output_tokens: usage.outputTokens },
111
- };
112
- }
113
- // ── reading an answer ─────────────────────────────────────────────────────
114
- const unit = (value) => typeof value === "number" && Number.isFinite(value) && value >= 0 && value <= 1;
115
- /**
116
- * Exactly the offered keys, each a probability, summing to one.
117
- *
118
- * Jev rounds every probability to two decimals, so each option carrying
119
- * weight can drift the sum by 0.005: eight live options can honestly sum to
120
- * 0.98. The tolerance grows with that count, floored at 1% and capped at 5%
121
- * so garbage still fails.
122
- */
123
- function distribution(value, keys) {
124
- const given = record(value);
125
- if (!given || keys.length === 0 || Object.keys(given).length !== keys.length)
126
- return null;
127
- const out = {};
128
- let sum = 0;
129
- let live = 0;
130
- for (const key of keys) {
131
- const p = given[key];
132
- if (!Object.hasOwn(given, key) || !unit(p))
133
- return null;
134
- out[key] = p;
135
- sum += p;
136
- if (p > 0)
137
- live++;
138
- }
139
- const tolerance = Math.min(0.05, Math.max(0.01, 0.005 * live)) + 1e-9;
140
- return Math.abs(sum - 1) <= tolerance ? out : null;
141
- }
142
- export function readAnswer(question, raw) {
143
- const answer = record(raw);
144
- if (!answer || answer.type !== question.type)
145
- return null;
146
- if (question.type === "noul") {
147
- return unit(answer.noul) ? { type: "noul", noul: answer.noul } : null;
148
- }
149
- const confidence = answer.confidence ?? null;
150
- if (confidence !== null && !unit(confidence))
151
- return null;
152
- if (question.type === "choice") {
153
- const options = Object.keys(question.criteria);
154
- const probabilities = distribution(answer.probabilities, options);
155
- const choice = answer.choice;
156
- if (!probabilities || typeof choice !== "string" || !options.includes(choice))
157
- return null;
158
- // 0.001 admits a tie at two decimals; a different winner never passes.
159
- if ((probabilities[choice] ?? 0) + 0.001 < Math.max(...Object.values(probabilities))) {
160
- return null;
161
- }
162
- return { type: "choice", choice, probabilities, confidence };
163
- }
164
- const levels = question.criteria.map((_, index) => String(index));
165
- const probabilities = distribution(answer.probabilities, levels);
166
- const score = answer.score;
167
- if (!probabilities || typeof score !== "number" || !(score >= 0 && score <= levels.length - 1)) {
168
- return null;
169
- }
170
- return { type: "score", score, probabilities, confidence };
171
- }
172
- const count = (value) => typeof value === "number" && Number.isFinite(value) && value >= 0 ? value : 0;
173
- function usageOf(host, raw) {
174
- const usage = record(raw) ?? {};
175
- // Keyed on the host, as in the OpenAI adapter: OpenRouter is who sends the
176
- // bill, and `cost` is its field in its unit. Another host's `cost` has not
177
- // said what it means.
178
- const reportedCostUsd = host === "openrouter"
179
- ? openRouterCostUsd({
180
- cost: usage.cost,
181
- is_byok: usage.is_byok === true,
182
- cost_details: record(usage.cost_details) ?? null,
183
- })
184
- : undefined;
185
- return {
186
- inputTokens: count(usage.input_tokens),
187
- cachedInputTokens: 0,
188
- outputTokens: count(usage.output_tokens),
189
- ...(reportedCostUsd !== undefined ? { reportedCostUsd } : {}),
190
- };
191
- }
192
- // ── the client ────────────────────────────────────────────────────────────
193
- /** The question `checkKey` asks: the cheapest one whose answer can be checked. */
194
- const KEY_CHECK = {
195
- ok: {
196
- type: "choice",
197
- instructions: "Does the text say hello?",
198
- criteria: { YES: null, NO: null },
199
- },
200
- };
201
- export function createJevClient(config) {
202
- const row = HOSTS[config.host];
203
- if (config.host === "cloudflare" && !config.accountId) {
204
- // Sent anyway, the URL has an empty account and Cloudflare answers 404,
205
- // which reads as a missing model — the wrong thing to go and fix.
206
- throw new Error("providerkit: Jev on Cloudflare needs the accountId of the Workers AI account");
207
- }
208
- const model = config.model ?? row.model;
209
- const provider = `jev:${config.host}`;
210
- const timeoutMs = config.timeoutMs ?? DEFAULT_TIMEOUT_MS;
211
- async function post(body, signal) {
212
- const deadline = AbortSignal.timeout(timeoutMs);
213
- try {
214
- return await postJson({
215
- url: row.url(config),
216
- headers: { Authorization: `Bearer ${config.apiKey}`, ...row.headers(config, model) },
217
- body,
218
- provider,
219
- signal: signal ? AbortSignal.any([signal, deadline]) : deadline,
220
- fetchImpl: config.fetchImpl,
221
- });
222
- }
223
- catch (err) {
224
- // Our deadline is a timeout, and retried; the caller's Stop leaves
225
- // exactly as it arrived and never is (invariant 2).
226
- if (deadline.aborted && !signal?.aborted) {
227
- throw new ProviderError(provider, "timeout", `${provider}: no answer in ${timeoutMs} ms`, {
228
- cause: err,
229
- });
230
- }
231
- throw err;
232
- }
233
- }
234
- const client = {
235
- host: config.host,
236
- model,
237
- ask(state, questions, opts = {}) {
238
- const { signal } = opts;
239
- return withRetry(async () => {
240
- const json = await post(row.body(model, state, questions), signal);
241
- const reply = row.unwrap(json);
242
- const raw = record(reply?.answers);
243
- if (!reply || !raw) {
244
- // A failure inside a 200 is still a failure (invariant 11): a
245
- // body that names one is classified like any other; a body that
246
- // names nothing is a contract we do not understand, and is not
247
- // retried into hiding it.
248
- const payload = record(json);
249
- const error = payload?.error ?? payload?.errors;
250
- if (error !== undefined)
251
- throw streamError(provider, error);
252
- throw new ProviderError(provider, "unknown", `${provider}: the reply has no answers`, {
253
- body: (JSON.stringify(json) ?? "").slice(0, 2_000),
254
- });
255
- }
256
- const answers = {};
257
- for (const [id, question] of Object.entries(questions)) {
258
- answers[id] = readAnswer(question, raw[id]);
259
- }
260
- return {
261
- // Sound: `readAnswer` returns each answer in its own question's
262
- // type, with a choice limited to that question's options.
263
- answers: answers,
264
- usage: usageOf(config.host, reply.usage),
265
- model: typeof reply.model === "string" && reply.model ? reply.model : model,
266
- };
267
- }, { ...config.retry, signal });
268
- },
269
- async checkKey(opts) {
270
- const reply = await client.ask("hello", KEY_CHECK, opts);
271
- if (!reply.answers.ok) {
272
- throw new ProviderError(provider, "unknown", `${provider}: the key works, but the answer failed its checks`);
273
- }
274
- },
275
- };
276
- return client;
277
- }
278
- //# sourceMappingURL=jev.js.map
package/dist/jev.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"jev.js","sourceRoot":"","sources":["../src/jev.ts"],"names":[],"mappings":"AAAA,2EAA2E;AAC3E,2BAA2B;AAC3B,EAAE;AACF,4EAA4E;AAC5E,+EAA+E;AAC/E,6EAA6E;AAC7E,2EAA2E;AAC3E,6EAA6E;AAC7E,6EAA6E;AAC7E,sEAAsE;AACtE,4EAA4E;AAC5E,8BAA8B;AAC9B,EAAE;AACF,0EAA0E;AAC1E,4EAA4E;AAC5E,0EAA0E;AAC1E,EAAE;AACF,8EAA8E;AAC9E,wEAAwE;AACxE,OAAO,EAAE,kBAAkB,EAAoB,MAAM,kBAAkB,CAAC;AACxE,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AACzD,OAAO,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAC1D,OAAO,EAAE,SAAS,EAAqB,MAAM,YAAY,CAAC;AAC1D,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AA2H1C,MAAM,kBAAkB,GAAG,MAAM,CAAC;AAElC,MAAM,MAAM,GAAG,CAAC,KAAc,EAAuC,EAAE,CACrE,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC;IAClE,CA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