cerno-sdk 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.
@@ -0,0 +1,117 @@
1
+ /**
2
+ * Wire types for the cerno API.
3
+ *
4
+ * These mirror `spec/openapi.json` exactly. A change here without a change there is a bug.
5
+ */
6
+ /** Temperature scaling applied to label logits before the softmax. */
7
+ export interface Calibration {
8
+ /** 1 leaves the model's own distribution alone; above 1 flattens, below 1 sharpens. */
9
+ temperature: number;
10
+ }
11
+ export interface ChoiceSpec {
12
+ question?: string;
13
+ options: string[];
14
+ }
15
+ /** A rubric given either as a plain count or as the text of each level, lowest first. */
16
+ export type LevelSpec = number | string[];
17
+ export interface ScoreSpec {
18
+ question?: string;
19
+ levels: LevelSpec;
20
+ }
21
+ export type Question = {
22
+ id: string;
23
+ noul: string;
24
+ } | {
25
+ id: string;
26
+ choice: ChoiceSpec;
27
+ } | {
28
+ id: string;
29
+ score: ScoreSpec;
30
+ };
31
+ export interface SystemOneRequest {
32
+ state: string;
33
+ model?: string;
34
+ calibration?: Calibration;
35
+ questions: Question[];
36
+ }
37
+ export interface OptionProbability {
38
+ option: string;
39
+ probability: number;
40
+ }
41
+ export interface LevelProbability {
42
+ level: number;
43
+ legend: string;
44
+ probability: number;
45
+ }
46
+ interface AnswerBase {
47
+ /**
48
+ * The logprob fed into the softmax, per label. A floor substitution appears here like any
49
+ * other value; `truncated` is what says one happened.
50
+ */
51
+ raw_logprobs: Record<string, number>;
52
+ /**
53
+ * Whether some label fell outside the host's reporting window, which makes its probability
54
+ * an upper bound rather than an observation.
55
+ */
56
+ truncated: boolean;
57
+ /**
58
+ * The labels whose `raw_logprobs` entry is an upper bound rather than an observation. Empty
59
+ * unless `truncated`. A server predating this field omits it; `Answers.truncatedLabels` reads
60
+ * that as empty.
61
+ */
62
+ truncated_labels?: string[];
63
+ }
64
+ export interface NoulAnswer extends AnswerBase {
65
+ type: "noul";
66
+ /** Probability that the answer is yes. */
67
+ noul: number;
68
+ }
69
+ export interface ChoiceAnswer extends AnswerBase {
70
+ type: "choice";
71
+ choice: string;
72
+ /** How peaked the distribution was, in 0..=1. */
73
+ confidence: number;
74
+ /** The winning option's position in the request. */
75
+ index: number;
76
+ probabilities: OptionProbability[];
77
+ }
78
+ export interface ScoreAnswer extends AnswerBase {
79
+ type: "score";
80
+ /** The most likely level, 1-based. */
81
+ score: number;
82
+ /** The probability-weighted mean level — often more useful than the argmax. */
83
+ expected_score: number;
84
+ legend: string;
85
+ /** How peaked the distribution was, in 0..=1. */
86
+ confidence: number;
87
+ probabilities: LevelProbability[];
88
+ }
89
+ export type Answer = NoulAnswer | ChoiceAnswer | ScoreAnswer;
90
+ export interface Usage {
91
+ input_tokens: number;
92
+ questions: number;
93
+ }
94
+ export interface SystemOneResponse {
95
+ answers: Record<string, Answer>;
96
+ model: string;
97
+ usage: Usage;
98
+ timing_ms: {
99
+ total: number;
100
+ };
101
+ }
102
+ export type ErrorCode = "too_many_options" | "too_many_questions" | "invalid_request" | "too_few_options" | "invalid_levels" | "empty_state" | "empty_question" | "duplicate_question_id" | "no_questions" | "unknown_model" | "invalid_calibration" | "no_label_matched" | "host_unavailable" | "host_timeout" | "internal";
103
+ export interface ErrorResponse {
104
+ code: ErrorCode;
105
+ message: string;
106
+ question_id?: string;
107
+ }
108
+ export interface ModelInfo {
109
+ alias: string;
110
+ model: string;
111
+ calibration: Calibration;
112
+ }
113
+ export interface ModelsResponse {
114
+ models: ModelInfo[];
115
+ default: string;
116
+ }
117
+ export {};
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Wire types for the cerno API.
3
+ *
4
+ * These mirror `spec/openapi.json` exactly. A change here without a change there is a bug.
5
+ */
6
+ export {};
package/package.json ADDED
@@ -0,0 +1,37 @@
1
+ {
2
+ "name": "cerno-sdk",
3
+ "version": "0.1.0",
4
+ "description": "TypeScript client for cerno — noul, choice and score against a locally hosted model",
5
+ "license": "MIT",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/cebor/cerno.git",
9
+ "directory": "sdks/typescript"
10
+ },
11
+ "type": "module",
12
+ "main": "./dist/cjs/index.js",
13
+ "module": "./dist/esm/index.js",
14
+ "types": "./dist/esm/index.d.ts",
15
+ "exports": {
16
+ ".": {
17
+ "types": "./dist/esm/index.d.ts",
18
+ "import": "./dist/esm/index.js",
19
+ "require": "./dist/cjs/index.js"
20
+ }
21
+ },
22
+ "files": ["dist", "README.md"],
23
+ "sideEffects": false,
24
+ "scripts": {
25
+ "build": "npm run build:esm && npm run build:cjs",
26
+ "build:esm": "tsc -p tsconfig.esm.json",
27
+ "build:cjs": "tsc -p tsconfig.cjs.json && node -e \"require('fs').writeFileSync('dist/cjs/package.json', JSON.stringify({type:'commonjs'}))\"",
28
+ "typecheck": "tsc -p tsconfig.json --noEmit",
29
+ "test": "node --test test/*.test.ts",
30
+ "prepublishOnly": "npm run build"
31
+ },
32
+ "devDependencies": {
33
+ "typescript": "^5.7.0",
34
+ "@types/node": "^22.0.0"
35
+ },
36
+ "engines": { "node": ">=18" }
37
+ }