@corbits/system-one 0.2.0 → 0.3.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/README.md +46 -9
- package/dist/adapter.d.ts +6 -7
- package/dist/adapter.js +63 -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,42 @@ 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
|
+
`questions` and `state` are per-call defaults; `providerOptions.systemOne` on a call wins field by field. A top-level `model` applies when `endpoint` sets none. Unknown keys throw. The adapter sends the bearer sentinel and the harness injects the offering's credential.
|
|
202
|
+
|
|
203
|
+
| Gateway | `endpoint` | `model` |
|
|
204
|
+
| ------------------ | ---------------------------------------------------------------- | ----------------------------- |
|
|
205
|
+
| Official (default) | omit, or `{"kind":"official"}` | `jev-latest` |
|
|
206
|
+
| Vercel AI Gateway | `{"kind":"gateway"}` | `typesafe-ai/jev` |
|
|
207
|
+
| OpenCode Zen | `{"kind":"custom","url":"https://opencode.ai/zen/v1/systemone"}` | `jev-1.13` or `jev-1.13-free` |
|
|
208
|
+
|
|
172
209
|
## Upgrading from 0.1
|
|
173
210
|
|
|
174
211
|
- `HttpError`, `NetworkError` and `TimeoutError` are removed. Transport failures return a `FallbackResult`.
|
package/dist/adapter.d.ts
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
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
|
-
* a custom URL) and the per-call model default; the inference call's own
|
|
10
|
-
* `model` argument wins for the request body.
|
|
7
|
+
* Interchange `AdapterFactory` for `SIDECAR_ADAPTER_MANIFEST`: validates the
|
|
8
|
+
* offering's `quirks` and reuses `createSystemOneAdapter`. A top-level
|
|
9
|
+
* `model` fills the endpoint's model when the endpoint sets none.
|
|
11
10
|
*/
|
|
12
|
-
export declare
|
|
11
|
+
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,57 @@ 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
|
+
/**
|
|
213
|
+
* Interchange `AdapterFactory` for `SIDECAR_ADAPTER_MANIFEST`: validates the
|
|
214
|
+
* offering's `quirks` and reuses `createSystemOneAdapter`. A top-level
|
|
215
|
+
* `model` fills the endpoint's model when the endpoint sets none.
|
|
216
|
+
*/
|
|
217
|
+
export const createSystemOneAdapterFactory = (source, quirks) => {
|
|
218
|
+
const parsed = SystemOneFactoryQuirks(quirks ?? {});
|
|
219
|
+
if (parsed instanceof type.errors) {
|
|
220
|
+
throw new Error(`${SYSTEM_ONE_PROVIDER} adapter: invalid quirks: ${parsed.summary}`);
|
|
221
|
+
}
|
|
222
|
+
const endpoint = {
|
|
223
|
+
kind: "official",
|
|
224
|
+
...parsed.endpoint,
|
|
225
|
+
};
|
|
226
|
+
if (parsed.model !== undefined && endpoint.model === undefined) {
|
|
227
|
+
endpoint.model = parsed.model;
|
|
228
|
+
}
|
|
229
|
+
const adapter = createSystemOneProviderAdapter({ endpoint }, source);
|
|
230
|
+
const defaults = {
|
|
231
|
+
...(parsed.state !== undefined && { state: parsed.state }),
|
|
232
|
+
...(parsed.questions !== undefined && { questions: parsed.questions }),
|
|
233
|
+
};
|
|
234
|
+
if (Object.keys(defaults).length === 0)
|
|
235
|
+
return adapter;
|
|
236
|
+
return {
|
|
237
|
+
...adapter,
|
|
238
|
+
buildRequest: (messages, model, options) => {
|
|
239
|
+
const raw = options.providerOptions?.["systemOne"];
|
|
240
|
+
const call = raw === undefined ? {} : raw;
|
|
241
|
+
return adapter.buildRequest(messages, model, {
|
|
242
|
+
...options,
|
|
243
|
+
providerOptions: {
|
|
244
|
+
...options.providerOptions,
|
|
245
|
+
systemOne: typeof call === "object" && call !== null
|
|
246
|
+
? { ...defaults, ...call }
|
|
247
|
+
: call,
|
|
248
|
+
},
|
|
249
|
+
});
|
|
250
|
+
},
|
|
251
|
+
};
|
|
252
|
+
};
|
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.0",
|
|
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",
|