@nirmos/sdk 0.3.4 → 0.3.6
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 +8 -3
- package/dist/cjs/client.js +1 -1
- package/dist/cjs/core/version.js +1 -1
- package/dist/esm/client.js +1 -1
- package/dist/esm/core/version.d.ts +1 -1
- package/dist/esm/core/version.js +1 -1
- package/examples/evaluation-offline.mjs +2 -0
- package/examples/evaluation-quickstart.mjs +6 -1
- package/examples/evaluation-quickstart.ts +6 -1
- package/examples/prompt-rollback.mjs +65 -0
- package/examples/prompt-rollback.ts +76 -0
- package/package.json +2 -2
- package/src/client.ts +1 -1
- package/src/core/version.ts +1 -1
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Nirmos TypeScript SDK
|
|
2
2
|
|
|
3
|
-
Documentation and offline checks
|
|
3
|
+
Documentation and offline checks track the version in [package.json](./package.json).
|
|
4
4
|
|
|
5
5
|
One client for Nirmos management and AI execution. Works in modern browsers and Node 18+ with ESM/CommonJS; no runtime dependencies.
|
|
6
6
|
|
|
@@ -12,8 +12,6 @@ pnpm add @nirmos/sdk
|
|
|
12
12
|
import { Nirmos, NirmosError } from "@nirmos/sdk";
|
|
13
13
|
|
|
14
14
|
const nirmos = new Nirmos({
|
|
15
|
-
apiBaseUrl: "http://localhost:4001",
|
|
16
|
-
runtimeBaseUrl: "http://localhost:4000",
|
|
17
15
|
auth: { type: "api-key", key: process.env.NIRMOS_API_KEY! },
|
|
18
16
|
});
|
|
19
17
|
|
|
@@ -28,6 +26,8 @@ const prompt = await nirmos.prompts.create({
|
|
|
28
26
|
await nirmos.prompts.update(prompt.promptId, { name: "Support reply",slug:"support-reply",description: "Customer support" });
|
|
29
27
|
```
|
|
30
28
|
|
|
29
|
+
Omitting `apiBaseUrl` and `runtimeBaseUrl` uses `https://api.nirmos.com` and `https://runtime.nirmos.com`, respectively. Set either option to override its default for local or private deployments.
|
|
30
|
+
|
|
31
31
|
For an API-hosted Better Auth browser session:
|
|
32
32
|
|
|
33
33
|
```ts
|
|
@@ -379,6 +379,11 @@ pnpm docs:sdk:check
|
|
|
379
379
|
node --test apps/web/scripts/sdk/docs-examples.test.mjs
|
|
380
380
|
```
|
|
381
381
|
|
|
382
|
+
`pnpm --filter @nirmos/sdk pack` runs prepack: it builds the SDK, regenerates the
|
|
383
|
+
reference from the current package version and public TypeScript inventory, and
|
|
384
|
+
checks documentation before packing. Commit the generated reference with a release.
|
|
385
|
+
The documentation check also rejects a package/reference version mismatch.
|
|
386
|
+
|
|
382
387
|
These checks use local/injected responses, with no provider quota. See the public
|
|
383
388
|
installation and evaluation guides for complete environment, run and cleanup
|
|
384
389
|
instructions. `evaluations.traceCandidates()` exposes public request IDs and
|
package/dist/cjs/client.js
CHANGED
|
@@ -58,7 +58,7 @@ class Nirmos {
|
|
|
58
58
|
const runtime = new transport_js_1.HttpTransport({
|
|
59
59
|
...common,
|
|
60
60
|
runtime: true,
|
|
61
|
-
baseUrl: normalizeBaseUrl(options.runtimeBaseUrl ?? "https://
|
|
61
|
+
baseUrl: normalizeBaseUrl(options.runtimeBaseUrl ?? "https://runtime.nirmos.com"),
|
|
62
62
|
});
|
|
63
63
|
const resources = (0, resources_js_1.managementResources)(api);
|
|
64
64
|
this.permissions = resources.permissions;
|
package/dist/cjs/core/version.js
CHANGED
package/dist/esm/client.js
CHANGED
|
@@ -55,7 +55,7 @@ export class Nirmos {
|
|
|
55
55
|
const runtime = new HttpTransport({
|
|
56
56
|
...common,
|
|
57
57
|
runtime: true,
|
|
58
|
-
baseUrl: normalizeBaseUrl(options.runtimeBaseUrl ?? "https://
|
|
58
|
+
baseUrl: normalizeBaseUrl(options.runtimeBaseUrl ?? "https://runtime.nirmos.com"),
|
|
59
59
|
});
|
|
60
60
|
const resources = managementResources(api);
|
|
61
61
|
this.permissions = resources.permissions;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const SDK_VERSION = "0.3.
|
|
1
|
+
export declare const SDK_VERSION = "0.3.6";
|
|
2
2
|
//# sourceMappingURL=version.d.ts.map
|
package/dist/esm/core/version.js
CHANGED
|
@@ -94,6 +94,7 @@ const sdk = new Nirmos({
|
|
|
94
94
|
JSON.stringify({
|
|
95
95
|
id: "run",
|
|
96
96
|
status: ++polls === 1 ? "RUNNING" : "COMPLETED",
|
|
97
|
+
summary: polls === 1 ? null : { overallPassRate: 0.5, byEvaluator: { exact_match: { count: 2, passRate: 0.5, average: null } } },
|
|
97
98
|
}),
|
|
98
99
|
);
|
|
99
100
|
if (path === "/v1/evaluations/runs/run/results") {
|
|
@@ -143,6 +144,7 @@ assert.deepEqual(
|
|
|
143
144
|
result.results.data.map((trial) => trial.scores[0].passed),
|
|
144
145
|
[true, false],
|
|
145
146
|
);
|
|
147
|
+
assert.equal(result.summary.overallPassRate, 0.5);
|
|
146
148
|
assert.equal(archived.length, 3);
|
|
147
149
|
console.log(
|
|
148
150
|
"Offline workflow verified: two cases, pinned versions, mappings, polling, true/false scores and archive.",
|
|
@@ -167,7 +167,12 @@ export async function evaluationQuickstart(client, options) {
|
|
|
167
167
|
trial.scores.some((score) => score.status !== "COMPLETED" || score.error))) {
|
|
168
168
|
throw new Error("Run ended with missing or failed trials/scores; inspect results");
|
|
169
169
|
}
|
|
170
|
-
|
|
170
|
+
// Runtime GET returns persisted aggregates after terminal processing.
|
|
171
|
+
const summary = run.summary;
|
|
172
|
+
if (!summary || typeof summary.overallPassRate !== "number")
|
|
173
|
+
throw new Error("Missing aggregate scores; inspect the terminal run");
|
|
174
|
+
console.log({ overallPassRate: summary.overallPassRate, byEvaluator: summary.byEvaluator });
|
|
175
|
+
return { runId, results, summary }; // passed:false is a valid evaluation outcome.
|
|
171
176
|
}
|
|
172
177
|
await new Promise((resolve) => setTimeout(resolve, options.pollMs ?? 2000));
|
|
173
178
|
}
|
|
@@ -202,7 +202,12 @@ export async function evaluationQuickstart(
|
|
|
202
202
|
"Run ended with missing or failed trials/scores; inspect results",
|
|
203
203
|
);
|
|
204
204
|
}
|
|
205
|
-
|
|
205
|
+
// Runtime GET returns persisted aggregates after terminal processing.
|
|
206
|
+
const summary = run.summary;
|
|
207
|
+
if (!summary || typeof summary.overallPassRate !== "number")
|
|
208
|
+
throw new Error("Missing aggregate scores; inspect the terminal run");
|
|
209
|
+
console.log({ overallPassRate: summary.overallPassRate, byEvaluator: summary.byEvaluator });
|
|
210
|
+
return { runId, results, summary }; // passed:false is a valid evaluation outcome.
|
|
206
211
|
}
|
|
207
212
|
await new Promise((resolve) =>
|
|
208
213
|
setTimeout(resolve, options.pollMs ?? 2000),
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
// Generated from prompt-rollback.ts. Do not edit.
|
|
2
|
+
import { Nirmos } from "@nirmos/sdk";
|
|
3
|
+
/** Disposable management rollback example. No provider call is needed. */
|
|
4
|
+
export async function promptRollback(nirmos) {
|
|
5
|
+
const suffix = `rollback-${Date.now()}`;
|
|
6
|
+
const prompt = await nirmos.prompts.create({ name: suffix, slug: suffix });
|
|
7
|
+
const save = async (text, parentVersionId) => {
|
|
8
|
+
const version = await nirmos.prompts.versions.create(prompt.promptId, {
|
|
9
|
+
branchId: prompt.branchId,
|
|
10
|
+
parentVersionId,
|
|
11
|
+
commitMessage: text,
|
|
12
|
+
temperature: 0,
|
|
13
|
+
maxTokens: 64,
|
|
14
|
+
topP: 1,
|
|
15
|
+
messages: [
|
|
16
|
+
{
|
|
17
|
+
order: 0,
|
|
18
|
+
role: "system",
|
|
19
|
+
contentBlocks: [{ order: 0, type: "text", text }],
|
|
20
|
+
},
|
|
21
|
+
],
|
|
22
|
+
});
|
|
23
|
+
if (!version.versionId)
|
|
24
|
+
throw new Error("Missing saved version ID");
|
|
25
|
+
return version.versionId;
|
|
26
|
+
};
|
|
27
|
+
const active = async (versionId, text) => {
|
|
28
|
+
const released = await nirmos.managedPrompts.retrieveActive(prompt.promptId, { cache: "reload" });
|
|
29
|
+
const rendered = await nirmos.managedPrompts.render(released, {});
|
|
30
|
+
if (released.version.id !== versionId ||
|
|
31
|
+
rendered.messages[0]?.content !== text)
|
|
32
|
+
throw new Error("Published content differs from the requested release");
|
|
33
|
+
console.log(rendered.messages[0].content);
|
|
34
|
+
};
|
|
35
|
+
try {
|
|
36
|
+
const v1 = await save("V1: Answer concisely.");
|
|
37
|
+
await nirmos.prompts.versions.publish(prompt.promptId, v1);
|
|
38
|
+
await active(v1, "V1: Answer concisely.");
|
|
39
|
+
const v2 = await save("V2: Include policy citations.", v1);
|
|
40
|
+
await nirmos.prompts.versions.publish(prompt.promptId, v2);
|
|
41
|
+
await active(v2, "V2: Include policy citations.");
|
|
42
|
+
const saved = await save("V3: Unpublished work.", v2);
|
|
43
|
+
await nirmos.prompts.versions.publish(prompt.promptId, v1);
|
|
44
|
+
await active(v1, "V1: Answer concisely.");
|
|
45
|
+
const branches = await nirmos.prompts.branches.list(prompt.promptId);
|
|
46
|
+
if (branches.items.find((branch) => branch.id === prompt.branchId)
|
|
47
|
+
?.headVersionId !== saved)
|
|
48
|
+
throw new Error("Rollback changed the saved branch head");
|
|
49
|
+
await nirmos.prompts.versions.publish(prompt.promptId, v2);
|
|
50
|
+
await active(v2, "V2: Include policy citations.");
|
|
51
|
+
return { v1, v2, saved };
|
|
52
|
+
}
|
|
53
|
+
finally {
|
|
54
|
+
await nirmos.prompts.delete(prompt.promptId);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
// NIRMOS_API_KEY=... node prompt-rollback.mjs (or run the .ts file with tsx).
|
|
58
|
+
if (process.env.NIRMOS_API_KEY) {
|
|
59
|
+
await promptRollback(new Nirmos({
|
|
60
|
+
auth: { type: "api-key", key: process.env.NIRMOS_API_KEY },
|
|
61
|
+
apiBaseUrl: process.env.NIRMOS_API_URL ?? "http://localhost:4001",
|
|
62
|
+
runtimeBaseUrl: process.env.NIRMOS_RUNTIME_URL ?? "http://localhost:4000",
|
|
63
|
+
maxRetries: 0,
|
|
64
|
+
}));
|
|
65
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { Nirmos } from "@nirmos/sdk";
|
|
2
|
+
|
|
3
|
+
/** Disposable management rollback example. No provider call is needed. */
|
|
4
|
+
export async function promptRollback(nirmos: Nirmos) {
|
|
5
|
+
const suffix = `rollback-${Date.now()}`;
|
|
6
|
+
const prompt = await nirmos.prompts.create({ name: suffix, slug: suffix });
|
|
7
|
+
const save = async (text: string, parentVersionId?: string) => {
|
|
8
|
+
const version = await nirmos.prompts.versions.create(prompt.promptId, {
|
|
9
|
+
branchId: prompt.branchId,
|
|
10
|
+
parentVersionId,
|
|
11
|
+
commitMessage: text,
|
|
12
|
+
temperature: 0,
|
|
13
|
+
maxTokens: 64,
|
|
14
|
+
topP: 1,
|
|
15
|
+
messages: [
|
|
16
|
+
{
|
|
17
|
+
order: 0,
|
|
18
|
+
role: "system",
|
|
19
|
+
contentBlocks: [{ order: 0, type: "text", text }],
|
|
20
|
+
},
|
|
21
|
+
],
|
|
22
|
+
});
|
|
23
|
+
if (!version.versionId) throw new Error("Missing saved version ID");
|
|
24
|
+
return version.versionId;
|
|
25
|
+
};
|
|
26
|
+
const active = async (versionId: string, text: string) => {
|
|
27
|
+
const released = await nirmos.managedPrompts.retrieveActive(
|
|
28
|
+
prompt.promptId,
|
|
29
|
+
{ cache: "reload" },
|
|
30
|
+
);
|
|
31
|
+
const rendered = await nirmos.managedPrompts.render(released, {});
|
|
32
|
+
if (
|
|
33
|
+
released.version.id !== versionId ||
|
|
34
|
+
rendered.messages[0]?.content !== text
|
|
35
|
+
)
|
|
36
|
+
throw new Error("Published content differs from the requested release");
|
|
37
|
+
console.log(rendered.messages[0].content);
|
|
38
|
+
};
|
|
39
|
+
try {
|
|
40
|
+
const v1 = await save("V1: Answer concisely.");
|
|
41
|
+
await nirmos.prompts.versions.publish(prompt.promptId, v1);
|
|
42
|
+
await active(v1, "V1: Answer concisely.");
|
|
43
|
+
const v2 = await save("V2: Include policy citations.", v1);
|
|
44
|
+
await nirmos.prompts.versions.publish(prompt.promptId, v2);
|
|
45
|
+
await active(v2, "V2: Include policy citations.");
|
|
46
|
+
const saved = await save("V3: Unpublished work.", v2);
|
|
47
|
+
await nirmos.prompts.versions.publish(prompt.promptId, v1);
|
|
48
|
+
await active(v1, "V1: Answer concisely.");
|
|
49
|
+
const branches = await nirmos.prompts.branches.list(prompt.promptId);
|
|
50
|
+
if (
|
|
51
|
+
branches.items.find((branch) => branch.id === prompt.branchId)
|
|
52
|
+
?.headVersionId !== saved
|
|
53
|
+
)
|
|
54
|
+
throw new Error("Rollback changed the saved branch head");
|
|
55
|
+
await nirmos.prompts.versions.publish(prompt.promptId, v2);
|
|
56
|
+
await active(v2, "V2: Include policy citations.");
|
|
57
|
+
return { v1, v2, saved };
|
|
58
|
+
} finally {
|
|
59
|
+
await nirmos.prompts.delete(prompt.promptId);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// This example remains type-checkable without Node type dependencies.
|
|
64
|
+
declare const process: { env: Record<string, string | undefined> };
|
|
65
|
+
|
|
66
|
+
// NIRMOS_API_KEY=... node prompt-rollback.mjs (or run the .ts file with tsx).
|
|
67
|
+
if (process.env.NIRMOS_API_KEY) {
|
|
68
|
+
await promptRollback(
|
|
69
|
+
new Nirmos({
|
|
70
|
+
auth: { type: "api-key", key: process.env.NIRMOS_API_KEY },
|
|
71
|
+
apiBaseUrl: process.env.NIRMOS_API_URL ?? "http://localhost:4001",
|
|
72
|
+
runtimeBaseUrl: process.env.NIRMOS_RUNTIME_URL ?? "http://localhost:4000",
|
|
73
|
+
maxRetries: 0,
|
|
74
|
+
}),
|
|
75
|
+
);
|
|
76
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nirmos/sdk",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.6",
|
|
4
4
|
"description": "Official TypeScript SDK for the Nirmos AI platform.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"build": "node ./scripts/generate-version.mjs && node ./scripts/clean.mjs && tsc -p tsconfig.build.json && tsc -p tsconfig.cjs.json && node ./scripts/write-cjs-package.mjs && node ./scripts/generate-examples.mjs",
|
|
26
26
|
"check-types": "tsc --noEmit",
|
|
27
27
|
"lint": "eslint src tests --max-warnings 0",
|
|
28
|
-
"prepack": "pnpm build",
|
|
28
|
+
"prepack": "pnpm build && pnpm --dir ../.. docs:sdk && pnpm --dir ../.. docs:sdk:check",
|
|
29
29
|
"test": "node ./scripts/ensure-built.mjs && tsc -p examples/tsconfig.json && tsc -p tests/tsconfig.json && node --test tests/*.test.mjs"
|
|
30
30
|
},
|
|
31
31
|
"engines": {
|
package/src/client.ts
CHANGED
|
@@ -138,7 +138,7 @@ export class Nirmos {
|
|
|
138
138
|
...common,
|
|
139
139
|
runtime: true,
|
|
140
140
|
baseUrl: normalizeBaseUrl(
|
|
141
|
-
options.runtimeBaseUrl ?? "https://
|
|
141
|
+
options.runtimeBaseUrl ?? "https://runtime.nirmos.com",
|
|
142
142
|
),
|
|
143
143
|
});
|
|
144
144
|
const resources = managementResources(api);
|
package/src/core/version.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// Generated from package.json by scripts/generate-version.mjs.
|
|
2
|
-
export const SDK_VERSION = "0.3.
|
|
2
|
+
export const SDK_VERSION = "0.3.6";
|