@corbits/system-one 0.2.0 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +53 -9
- package/dist/adapter.d.ts +9 -7
- package/dist/adapter.js +64 -5
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -57,15 +57,16 @@ Boolean questions answer as `noul`, a probability from 0 to 1 that the answer is
|
|
|
57
57
|
|
|
58
58
|
## Reference
|
|
59
59
|
|
|
60
|
-
| Export | Description
|
|
61
|
-
| --------------------------------- |
|
|
62
|
-
| `evaluate(input, options?)` | Runs one evaluation. Returns `EvaluateResult`: decisions or a `FallbackResult`.
|
|
63
|
-
| `createSystemOneAdapter(config?)` | Returns a `ProviderAdapter` for `runInference`. `config` is an `EvaluateConfig`.
|
|
64
|
-
| `
|
|
65
|
-
| `
|
|
66
|
-
| `
|
|
67
|
-
| `
|
|
68
|
-
| `
|
|
60
|
+
| Export | Description |
|
|
61
|
+
| --------------------------------- | ----------------------------------------------------------------------------------- |
|
|
62
|
+
| `evaluate(input, options?)` | Runs one evaluation. Returns `EvaluateResult`: decisions or a `FallbackResult`. |
|
|
63
|
+
| `createSystemOneAdapter(config?)` | Returns a `ProviderAdapter` for `runInference`. `config` is an `EvaluateConfig`. |
|
|
64
|
+
| `createSystemOneAdapterFactory` | Interchange `AdapterFactory` for `SIDECAR_ADAPTER_MANIFEST`; takes offering quirks. |
|
|
65
|
+
| `SYSTEM_ONE_PROVIDER` | The `"corbits-system-one"` provider id. |
|
|
66
|
+
| `DEFAULT_TIMEOUT_MS` | `1500`, the default `timeoutMs`. |
|
|
67
|
+
| `SystemOneError` | Thrown for invalid input or a `custom` endpoint without a `url`. |
|
|
68
|
+
| `SystemOneTelemetryEvent` | Schema and type for events passed to `onTelemetry`. |
|
|
69
|
+
| `EvaluateOptions`, `EvaluateDeps` | Types for `options`: `onTelemetry`, and `deps: { fetch, scheduler }`. |
|
|
69
70
|
|
|
70
71
|
`Question`, `QuestionList`, `Decision`, `EvaluateInput`, `EvaluateConfig`, `EndpointConfig`, `EvaluateResult` and `FallbackResult` are exported as arktype schemas and types.
|
|
71
72
|
|
|
@@ -169,6 +170,49 @@ for await (const event of runInference({
|
|
|
169
170
|
|
|
170
171
|
The adapter emits one `inference.text.delta` per decision, whose `token` is the decision as JSON, then an `inference.usage` event. The harness supplies the credential through `readMaterial` and owns retries. A malformed response body is a `ProtocolMismatchError`, not a fallback.
|
|
171
172
|
|
|
173
|
+
### Manifest factory
|
|
174
|
+
|
|
175
|
+
`createSystemOneAdapterFactory(source, quirks?)` is an Interchange `AdapterFactory`, so a stock sidecar loads it from `SIDECAR_ADAPTER_MANIFEST` with no custom code:
|
|
176
|
+
|
|
177
|
+
```json
|
|
178
|
+
[
|
|
179
|
+
{
|
|
180
|
+
"provider": "corbits-system-one",
|
|
181
|
+
"specifier": "@corbits/system-one",
|
|
182
|
+
"export": "createSystemOneAdapterFactory"
|
|
183
|
+
}
|
|
184
|
+
]
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
The hub offering's `quirks` are validated and all optional:
|
|
188
|
+
|
|
189
|
+
```json
|
|
190
|
+
{
|
|
191
|
+
"endpoint": {
|
|
192
|
+
"kind": "custom",
|
|
193
|
+
"url": "https://opencode.ai/zen/v1/systemone"
|
|
194
|
+
},
|
|
195
|
+
"model": "jev-1.13",
|
|
196
|
+
"questions": [{ "type": "boolean", "id": "gate", "instructions": "Allow?" }],
|
|
197
|
+
"state": {}
|
|
198
|
+
}
|
|
199
|
+
```
|
|
200
|
+
|
|
201
|
+
Without `endpoint`, the adapter posts to the catalog provider's `baseURL` + `/systemone`, the host the offering's credential was issued for. A `model` quirk (top level or on `endpoint`) is the model sent on the wire, so one catalog model can be served by providers that name it differently. `questions` and `state` are per-call defaults; `providerOptions.systemOne` on a call wins field by field. Unknown keys throw. The adapter sends the bearer sentinel and the harness injects the offering's credential.
|
|
202
|
+
|
|
203
|
+
| Provider | Provider `baseURL` | `model` quirk |
|
|
204
|
+
| ----------------- | ------------------------------------------ | ----------------------------- |
|
|
205
|
+
| TypeSafe | `https://api.typesafe.ai/v1` | `jev-latest` |
|
|
206
|
+
| Vercel AI Gateway | `https://ai-gateway.vercel.sh/typesafe/v1` | `typesafe-ai/jev` |
|
|
207
|
+
| OpenRouter | `https://openrouter.ai/api/v1` | `typesafe/jev-1.13` |
|
|
208
|
+
| OpenCode Zen | `https://opencode.ai/zen/v1` | `jev-1.13` or `jev-1.13-free` |
|
|
209
|
+
|
|
210
|
+
## Upgrading to 0.3.1
|
|
211
|
+
|
|
212
|
+
- `createSystemOneAdapterFactory` without an `endpoint` quirk now posts to the catalog provider's `baseURL` + `/systemone` instead of the official TypeSafe URL. Set the provider `baseURL` to the API root (for example `https://api.typesafe.ai/v1`), or keep the old behavior with `{"endpoint":{"kind":"official"}}`. The harness sends the offering's credential to whatever URL the adapter returns, so only set an explicit `endpoint` on a host that credential belongs to.
|
|
213
|
+
- A `model` quirk now overrides the model the harness passes (the catalog canonical name).
|
|
214
|
+
- `createSystemOneAdapter` and `evaluate` are unchanged.
|
|
215
|
+
|
|
172
216
|
## Upgrading from 0.1
|
|
173
217
|
|
|
174
218
|
- `HttpError`, `NetworkError` and `TimeoutError` are removed. Transport failures return a `FallbackResult`.
|
package/dist/adapter.d.ts
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
|
-
import { type ProviderAdapter } from "@intx/inference";
|
|
1
|
+
import { type AdapterFactory, type ProviderAdapter } from "@intx/inference";
|
|
2
2
|
import { type EvaluateConfig } from "./schemas.js";
|
|
3
3
|
/** Provider id this package serves. */
|
|
4
4
|
export declare const SYSTEM_ONE_PROVIDER = "corbits-system-one";
|
|
5
|
+
export declare function createSystemOneAdapter(config?: EvaluateConfig): ProviderAdapter;
|
|
5
6
|
/**
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
* `model`
|
|
7
|
+
* Interchange `AdapterFactory` for `SIDECAR_ADAPTER_MANIFEST`: validates the
|
|
8
|
+
* offering's `quirks` and builds the same adapter `createSystemOneAdapter`
|
|
9
|
+
* does. Without an
|
|
10
|
+
* `endpoint` quirk, requests go to the catalog provider's `baseURL` +
|
|
11
|
+
* `/systemone`. A quirk `model` (on `endpoint` or top level) is the model
|
|
12
|
+
* sent on the wire, overriding the catalog's canonical name.
|
|
11
13
|
*/
|
|
12
|
-
export declare
|
|
14
|
+
export declare const createSystemOneAdapterFactory: AdapterFactory;
|
package/dist/adapter.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { type } from "arktype";
|
|
2
2
|
import { BEARER_CREDENTIAL_SENTINEL, ProtocolMismatchError, } from "@intx/inference";
|
|
3
3
|
import { resolveEndpoint } from "./config.js";
|
|
4
|
-
import { Decision, toDecision, toWireQuestions, WireResponseBody, QuestionList, State, } from "./schemas.js";
|
|
4
|
+
import { Decision, toDecision, toWireQuestions, WireResponseBody, EndpointConfig, QuestionList, State, } from "./schemas.js";
|
|
5
5
|
// ---------------------------------------------------------------------------
|
|
6
6
|
// Adapter
|
|
7
7
|
// ---------------------------------------------------------------------------
|
|
@@ -109,8 +109,13 @@ function parseDecisions(body, provider) {
|
|
|
109
109
|
* a custom URL) and the per-call model default; the inference call's own
|
|
110
110
|
* `model` argument wins for the request body.
|
|
111
111
|
*/
|
|
112
|
-
|
|
112
|
+
function createSystemOneProviderAdapter(config, source) {
|
|
113
113
|
const endpoint = resolveEndpoint(config?.endpoint);
|
|
114
|
+
const usageSource = source ?? {
|
|
115
|
+
sourceId: SYSTEM_ONE_PROVIDER,
|
|
116
|
+
provider: SYSTEM_ONE_PROVIDER,
|
|
117
|
+
model: endpoint.model,
|
|
118
|
+
};
|
|
114
119
|
const buildRequest = (messages, model, options) => {
|
|
115
120
|
let state = { transcript: transcriptText(messages) };
|
|
116
121
|
let questions = DEFAULT_QUESTIONS;
|
|
@@ -160,9 +165,8 @@ export function createSystemOneAdapter(config) {
|
|
|
160
165
|
data: {
|
|
161
166
|
usage: toTokenUsage(usage),
|
|
162
167
|
source: {
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
model: model ?? endpoint.model,
|
|
168
|
+
...usageSource,
|
|
169
|
+
model: model ?? usageSource.model,
|
|
166
170
|
},
|
|
167
171
|
},
|
|
168
172
|
});
|
|
@@ -192,3 +196,58 @@ export function createSystemOneAdapter(config) {
|
|
|
192
196
|
extractRetryAfterMs,
|
|
193
197
|
};
|
|
194
198
|
}
|
|
199
|
+
export function createSystemOneAdapter(config) {
|
|
200
|
+
return createSystemOneProviderAdapter(config);
|
|
201
|
+
}
|
|
202
|
+
// Deployment quirks a hub offering carries for this provider. `questions`
|
|
203
|
+
// and `state` are per-call defaults: a call's own `providerOptions.systemOne`
|
|
204
|
+
// wins field by field.
|
|
205
|
+
const SystemOneFactoryQuirks = type({
|
|
206
|
+
"endpoint?": EndpointConfig,
|
|
207
|
+
"model?": "string",
|
|
208
|
+
"questions?": QuestionList,
|
|
209
|
+
"state?": State,
|
|
210
|
+
"+": "reject",
|
|
211
|
+
});
|
|
212
|
+
// Interchange joins a relative request path to the catalog provider's
|
|
213
|
+
// `baseURL`, the host the offering's credential was issued for.
|
|
214
|
+
const PROVIDER_ENDPOINT = { kind: "custom", url: "/systemone" };
|
|
215
|
+
/**
|
|
216
|
+
* Interchange `AdapterFactory` for `SIDECAR_ADAPTER_MANIFEST`: validates the
|
|
217
|
+
* offering's `quirks` and builds the same adapter `createSystemOneAdapter`
|
|
218
|
+
* does. Without an
|
|
219
|
+
* `endpoint` quirk, requests go to the catalog provider's `baseURL` +
|
|
220
|
+
* `/systemone`. A quirk `model` (on `endpoint` or top level) is the model
|
|
221
|
+
* sent on the wire, overriding the catalog's canonical name.
|
|
222
|
+
*/
|
|
223
|
+
export const createSystemOneAdapterFactory = (source, quirks) => {
|
|
224
|
+
const parsed = SystemOneFactoryQuirks(quirks ?? {});
|
|
225
|
+
if (parsed instanceof type.errors) {
|
|
226
|
+
throw new Error(`${SYSTEM_ONE_PROVIDER} adapter: invalid quirks: ${parsed.summary}`);
|
|
227
|
+
}
|
|
228
|
+
const wireModel = parsed.endpoint?.model ?? parsed.model;
|
|
229
|
+
if (wireModel === "") {
|
|
230
|
+
throw new Error(`${SYSTEM_ONE_PROVIDER} adapter: invalid quirks: model must not be empty`);
|
|
231
|
+
}
|
|
232
|
+
const adapter = createSystemOneProviderAdapter({ endpoint: parsed.endpoint ?? PROVIDER_ENDPOINT }, source);
|
|
233
|
+
const defaults = {
|
|
234
|
+
...(parsed.state !== undefined && { state: parsed.state }),
|
|
235
|
+
...(parsed.questions !== undefined && { questions: parsed.questions }),
|
|
236
|
+
};
|
|
237
|
+
return {
|
|
238
|
+
...adapter,
|
|
239
|
+
buildRequest: (messages, model, options) => {
|
|
240
|
+
const raw = options.providerOptions?.["systemOne"];
|
|
241
|
+
const call = raw === undefined ? {} : raw;
|
|
242
|
+
return adapter.buildRequest(messages, wireModel ?? model, {
|
|
243
|
+
...options,
|
|
244
|
+
providerOptions: {
|
|
245
|
+
...options.providerOptions,
|
|
246
|
+
systemOne: typeof call === "object" && call !== null
|
|
247
|
+
? { ...defaults, ...call }
|
|
248
|
+
: call,
|
|
249
|
+
},
|
|
250
|
+
});
|
|
251
|
+
},
|
|
252
|
+
};
|
|
253
|
+
};
|
package/dist/index.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ export { DEFAULT_TIMEOUT_MS } from "./config.js";
|
|
|
2
2
|
export type { EvaluateDeps } from "./client.js";
|
|
3
3
|
export { evaluate } from "./evaluate.js";
|
|
4
4
|
export type { EvaluateOptions } from "./evaluate.js";
|
|
5
|
-
export { createSystemOneAdapter, SYSTEM_ONE_PROVIDER } from "./adapter.js";
|
|
5
|
+
export { createSystemOneAdapter, createSystemOneAdapterFactory, SYSTEM_ONE_PROVIDER, } from "./adapter.js";
|
|
6
6
|
export { SystemOneError } from "./errors.js";
|
|
7
7
|
export type { SystemOneErrorCode } from "./errors.js";
|
|
8
8
|
export { SystemOneTelemetryEvent } from "./telemetry.js";
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export { DEFAULT_TIMEOUT_MS } from "./config.js";
|
|
2
2
|
export { evaluate } from "./evaluate.js";
|
|
3
|
-
export { createSystemOneAdapter, SYSTEM_ONE_PROVIDER } from "./adapter.js";
|
|
3
|
+
export { createSystemOneAdapter, createSystemOneAdapterFactory, SYSTEM_ONE_PROVIDER, } from "./adapter.js";
|
|
4
4
|
export { SystemOneError } from "./errors.js";
|
|
5
5
|
export { SystemOneTelemetryEvent } from "./telemetry.js";
|
|
6
6
|
export { BooleanQuestion, ChoiceQuestion, Decision, Description, EndpointConfig, EvaluateConfig, EvaluateInput, EvaluateResult, FallbackReason, FallbackResult, NoulQuestion, ProbabilityMap, Question, QuestionList, ScoreQuestion, State, Usage, } from "./schemas.js";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@corbits/system-one",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.1",
|
|
4
4
|
"description": "Typed-decision evaluation client for System One (Jev-class) models: arktype question/decision schemas, endpoint configuration with gateway override, and timeout/fallback semantics.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"corbits",
|