@nirmos/sdk 0.2.0 → 0.3.2
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 +81 -44
- package/dist/cjs/client.js +112 -20
- package/dist/cjs/client.js.map +1 -1
- package/dist/cjs/core/errors.js +4 -2
- package/dist/cjs/core/errors.js.map +1 -1
- package/dist/cjs/core/metadata.js +3 -3
- package/dist/cjs/core/metadata.js.map +1 -1
- package/dist/cjs/core/transport.js +36 -9
- package/dist/cjs/core/transport.js.map +1 -1
- package/dist/cjs/index.js +10 -2
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/management/contracts.js +3 -0
- package/dist/cjs/management/contracts.js.map +1 -0
- package/dist/cjs/management/execution-types.js +3 -0
- package/dist/cjs/management/execution-types.js.map +1 -0
- package/dist/cjs/management/manifest.js +1551 -0
- package/dist/cjs/management/manifest.js.map +1 -0
- package/dist/cjs/management/resources.js +199 -0
- package/dist/cjs/management/resources.js.map +1 -0
- package/dist/cjs/memory/memory.js +68 -0
- package/dist/cjs/memory/memory.js.map +1 -0
- package/dist/cjs/memory/types.js +3 -0
- package/dist/cjs/memory/types.js.map +1 -0
- package/dist/cjs/prompts/render.js +12 -4
- package/dist/cjs/prompts/render.js.map +1 -1
- package/dist/cjs/prompts/variables.js +117 -0
- package/dist/cjs/prompts/variables.js.map +1 -0
- package/dist/esm/client.d.ts +140 -13
- package/dist/esm/client.d.ts.map +1 -1
- package/dist/esm/client.js +111 -20
- package/dist/esm/client.js.map +1 -1
- package/dist/esm/core/errors.d.ts +4 -0
- package/dist/esm/core/errors.d.ts.map +1 -1
- package/dist/esm/core/errors.js +4 -2
- package/dist/esm/core/errors.js.map +1 -1
- package/dist/esm/core/metadata.d.ts.map +1 -1
- package/dist/esm/core/metadata.js +3 -3
- package/dist/esm/core/metadata.js.map +1 -1
- package/dist/esm/core/transport.d.ts +9 -2
- package/dist/esm/core/transport.d.ts.map +1 -1
- package/dist/esm/core/transport.js +36 -9
- package/dist/esm/core/transport.js.map +1 -1
- package/dist/esm/gateway/types.d.ts +2 -0
- package/dist/esm/gateway/types.d.ts.map +1 -1
- package/dist/esm/index.d.ts +7 -2
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +3 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/management/contracts.d.ts +30184 -0
- package/dist/esm/management/contracts.d.ts.map +1 -0
- package/dist/esm/management/contracts.js +2 -0
- package/dist/esm/management/contracts.js.map +1 -0
- package/dist/esm/management/execution-types.d.ts +246 -0
- package/dist/esm/management/execution-types.d.ts.map +1 -0
- package/dist/esm/management/execution-types.js +2 -0
- package/dist/esm/management/execution-types.js.map +1 -0
- package/dist/esm/management/manifest.d.ts +1353 -0
- package/dist/esm/management/manifest.d.ts.map +1 -0
- package/dist/esm/management/manifest.js +1548 -0
- package/dist/esm/management/manifest.js.map +1 -0
- package/dist/esm/management/resources.d.ts +290 -0
- package/dist/esm/management/resources.d.ts.map +1 -0
- package/dist/esm/management/resources.js +196 -0
- package/dist/esm/management/resources.js.map +1 -0
- package/dist/esm/memory/memory.d.ts +35 -0
- package/dist/esm/memory/memory.d.ts.map +1 -0
- package/dist/esm/memory/memory.js +64 -0
- package/dist/esm/memory/memory.js.map +1 -0
- package/dist/esm/memory/types.d.ts +135 -0
- package/dist/esm/memory/types.d.ts.map +1 -0
- package/dist/esm/memory/types.js +2 -0
- package/dist/esm/memory/types.js.map +1 -0
- package/dist/esm/prompts/render.js +11 -3
- package/dist/esm/prompts/render.js.map +1 -1
- package/dist/esm/prompts/variables.d.ts +29 -0
- package/dist/esm/prompts/variables.d.ts.map +1 -0
- package/dist/esm/prompts/variables.js +108 -0
- package/dist/esm/prompts/variables.js.map +1 -0
- package/package.json +2 -2
- package/src/client.ts +299 -36
- package/src/core/errors.ts +8 -2
- package/src/core/metadata.ts +3 -12
- package/src/core/transport.ts +47 -11
- package/src/gateway/types.ts +2 -0
- package/src/index.ts +71 -2
- package/src/management/contracts.ts +1179 -0
- package/src/management/execution-types.ts +10 -0
- package/src/management/manifest.ts +1547 -0
- package/src/management/resources.ts +198 -0
- package/src/memory/memory.ts +108 -0
- package/src/memory/types.ts +157 -0
- package/src/prompts/render.ts +9 -4
- package/src/prompts/variables.ts +156 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"render.js","sourceRoot":"","sources":["../../../src/prompts/render.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAWtD,
|
|
1
|
+
{"version":3,"file":"render.js","sourceRoot":"","sources":["../../../src/prompts/render.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAWtD,OAAO,EAAE,uBAAuB,IAAI,WAAW,EAAE,mBAAmB,EAAE,sBAAsB,EAAE,4BAA4B,EAAE,MAAM,gBAAgB,CAAC;AAEnJ,MAAM,UAAU,YAAY,CAC1B,MAAc,EACd,SAA+B,EAAE,EACjC,UAA+B,EAAE;IAEjC,MAAM,QAAQ,GAAG,gBAAgB,CAAC,MAAM,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC;IAC5D,MAAM,cAAc,GAClB,MAAM,CAAC,OAAO,CAAC,IAAI,KAAK,MAAM;QAC5B,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,QAAQ;QACzB,CAAC,CAAC;YACE;gBACE,IAAI,EAAE,MAAM,CAAC,OAAO,CAAC,IAAI,IAAI,MAAM;gBACnC,OAAO,EAAE,MAAM,CAAC,OAAO,CAAC,IAAI;aAC7B;SACF,CAAC;IAER,MAAM,QAAQ,GAAG,cAAc,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC;QAChD,GAAG,OAAO;QACV,OAAO,EACL,OAAO,OAAO,CAAC,OAAO,KAAK,QAAQ;YACjC,CAAC,CAAC,WAAW,CAAC,OAAO,CAAC,OAAO,EAAE,QAAQ,EAAE,OAAO,CAAC;Y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EAAE,CAAC;YACxB,UAAU,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;YACrB,OAAO,WAAW,CAAC;QACrB,CAAC;QACD,OAAO,SAAS,CAAC,KAAkB,CAAC,CAAC;IACvC,CAAC,CAAC,CAAC;IAEH,IAAI,UAAU,CAAC,IAAI,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC,eAAe,EAAE,CAAC;QACpD,MAAM,KAAK,GAAG,CAAC,GAAG,UAAU,CAAC,CAAC;QAC9B,MAAM,IAAI,iBAAiB,CACzB,gCAAgC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,EACnD,KAAK,CACN,CAAC;IACJ,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,SAAS,SAAS,CAAC,KAAgB;IACjC,IAAI,KAAK,KAAK,IAAI;QAAE,OAAO,MAAM,CAAC;IAClC,IAAI,OAAO,KAAK,KAAK,QAAQ;QAAE,OAAO,KAAK,CAAC;IAC5C,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,OAAO,KAAK,KAAK,SAAS,EAAE,CAAC;QAC5D,OAAO,MAAM,CAAC,KAAK,CAAC,CAAC;IACvB,CAAC;IACD,OAAO,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;AAC/B,CAAC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/** Shared placeholder semantics for managed prompts, the dashboard and execution. */
|
|
2
|
+
export declare const PROMPT_VARIABLE_PATTERN: RegExp;
|
|
3
|
+
export declare function extractPromptVariableNames(...values: Array<string | null | undefined>): string[];
|
|
4
|
+
export declare function promptVariableValue(values: Record<string, unknown>, name: string): unknown;
|
|
5
|
+
export declare function interpolatePromptVariables(text: string, values: Record<string, unknown>): string;
|
|
6
|
+
export declare function validatePromptTemplate(text: string): string[];
|
|
7
|
+
export type VariableDefinition = {
|
|
8
|
+
name: string;
|
|
9
|
+
type: string;
|
|
10
|
+
required?: boolean;
|
|
11
|
+
default?: unknown;
|
|
12
|
+
enum?: readonly string[];
|
|
13
|
+
values?: readonly string[];
|
|
14
|
+
min?: number;
|
|
15
|
+
max?: number;
|
|
16
|
+
minLength?: number;
|
|
17
|
+
maxLength?: number;
|
|
18
|
+
min_length?: number;
|
|
19
|
+
max_length?: number;
|
|
20
|
+
itemType?: string;
|
|
21
|
+
item_type?: string;
|
|
22
|
+
};
|
|
23
|
+
export declare function validatePromptVariableValues(definitions: readonly VariableDefinition[], values: Record<string, unknown>): Record<string, string>;
|
|
24
|
+
export declare function validatePromptSettings(settings: {
|
|
25
|
+
temperature: unknown;
|
|
26
|
+
topP: unknown;
|
|
27
|
+
maxTokens: unknown;
|
|
28
|
+
}): Record<string, string>;
|
|
29
|
+
//# sourceMappingURL=variables.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"variables.d.ts","sourceRoot":"","sources":["../../../src/prompts/variables.ts"],"names":[],"mappings":"AAAA,qFAAqF;AACrF,eAAO,MAAM,uBAAuB,QACQ,CAAC;AAC7C,wBAAgB,0BAA0B,CACxC,GAAG,MAAM,EAAE,KAAK,CAAC,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC,GAC1C,MAAM,EAAE,CAUV;AACD,wBAAgB,mBAAmB,CACjC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC/B,IAAI,EAAE,MAAM,GACX,OAAO,CAcT;AACD,wBAAgB,0BAA0B,CACxC,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAC9B,MAAM,CASR;AACD,wBAAgB,sBAAsB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,CAO7D;AACD,MAAM,MAAM,kBAAkB,GAAG;IAC/B,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,IAAI,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IACzB,MAAM,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IAC3B,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,CAAC;AACF,wBAAgB,4BAA4B,CAC1C,WAAW,EAAE,SAAS,kBAAkB,EAAE,EAC1C,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAC9B,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAsDxB;AACD,wBAAgB,sBAAsB,CAAC,QAAQ,EAAE;IAC/C,WAAW,EAAE,OAAO,CAAC;IACrB,IAAI,EAAE,OAAO,CAAC;IACd,SAAS,EAAE,OAAO,CAAC;CACpB,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAsBzB"}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
/** Shared placeholder semantics for managed prompts, the dashboard and execution. */
|
|
2
|
+
export const PROMPT_VARIABLE_PATTERN = /\{\{\s*([a-zA-Z][a-zA-Z0-9_.-]*)\s*\}\}/g;
|
|
3
|
+
export function extractPromptVariableNames(...values) {
|
|
4
|
+
return [
|
|
5
|
+
...new Set(values.flatMap((value) => [...(value ?? "").matchAll(PROMPT_VARIABLE_PATTERN)].map((match) => match[1]))),
|
|
6
|
+
];
|
|
7
|
+
}
|
|
8
|
+
export function promptVariableValue(values, name) {
|
|
9
|
+
if (Object.hasOwn(values, name))
|
|
10
|
+
return values[name];
|
|
11
|
+
let current = values;
|
|
12
|
+
for (const key of name.split(".")) {
|
|
13
|
+
if (["__proto__", "prototype", "constructor"].includes(key) ||
|
|
14
|
+
!current ||
|
|
15
|
+
typeof current !== "object" ||
|
|
16
|
+
!Object.hasOwn(current, key))
|
|
17
|
+
return undefined;
|
|
18
|
+
current = current[key];
|
|
19
|
+
}
|
|
20
|
+
return current;
|
|
21
|
+
}
|
|
22
|
+
export function interpolatePromptVariables(text, values) {
|
|
23
|
+
return text.replace(PROMPT_VARIABLE_PATTERN, (token, name) => {
|
|
24
|
+
const value = promptVariableValue(values, name);
|
|
25
|
+
return value === undefined
|
|
26
|
+
? token
|
|
27
|
+
: typeof value === "string"
|
|
28
|
+
? value
|
|
29
|
+
: JSON.stringify(value);
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
export function validatePromptTemplate(text) {
|
|
33
|
+
const remaining = text.replace(PROMPT_VARIABLE_PATTERN, "");
|
|
34
|
+
return /\{\{|\{%/.test(remaining)
|
|
35
|
+
? [
|
|
36
|
+
"Unsupported variable syntax. Use {{name}}, {{ spaced }}, or {{user.name}}. Expressions, filters and template blocks cannot run as managed prompt variables.",
|
|
37
|
+
]
|
|
38
|
+
: [];
|
|
39
|
+
}
|
|
40
|
+
export function validatePromptVariableValues(definitions, values) {
|
|
41
|
+
const errors = {};
|
|
42
|
+
for (const definition of definitions) {
|
|
43
|
+
const supplied = promptVariableValue(values, definition.name);
|
|
44
|
+
const value = supplied === undefined ? definition.default : supplied;
|
|
45
|
+
let error = "";
|
|
46
|
+
if (value === undefined || value === "") {
|
|
47
|
+
if (definition.required)
|
|
48
|
+
error = "A value is required.";
|
|
49
|
+
}
|
|
50
|
+
else {
|
|
51
|
+
const type = definition.type;
|
|
52
|
+
if (type === "number" &&
|
|
53
|
+
(typeof value !== "number" || !Number.isFinite(value)))
|
|
54
|
+
error = "Enter a valid number.";
|
|
55
|
+
if (type === "boolean" && typeof value !== "boolean")
|
|
56
|
+
error = "Choose true or false.";
|
|
57
|
+
if (type === "string" && typeof value !== "string")
|
|
58
|
+
error = "Enter text.";
|
|
59
|
+
if (type === "enum" &&
|
|
60
|
+
!(definition.enum ?? definition.values)?.includes(String(value)))
|
|
61
|
+
error = "Choose one of the allowed values.";
|
|
62
|
+
if (type === "array" && !Array.isArray(value))
|
|
63
|
+
error = "Enter a valid array.";
|
|
64
|
+
if (typeof value === "number" &&
|
|
65
|
+
((definition.min !== undefined && value < definition.min) ||
|
|
66
|
+
(definition.max !== undefined && value > definition.max)))
|
|
67
|
+
error = `Enter a number between ${definition.min ?? "−∞"} and ${definition.max ?? "∞"}.`;
|
|
68
|
+
const minLength = definition.minLength ?? definition.min_length;
|
|
69
|
+
const maxLength = definition.maxLength ?? definition.max_length;
|
|
70
|
+
if (typeof value === "string" &&
|
|
71
|
+
((minLength !== undefined && value.length < minLength) ||
|
|
72
|
+
(maxLength !== undefined && value.length > maxLength)))
|
|
73
|
+
error = `Use ${minLength ?? 0} to ${maxLength ?? "any number of"} characters.`;
|
|
74
|
+
const itemType = definition.itemType ?? definition.item_type;
|
|
75
|
+
if (Array.isArray(value) &&
|
|
76
|
+
itemType &&
|
|
77
|
+
value.some((item) => itemType === "array"
|
|
78
|
+
? !Array.isArray(item)
|
|
79
|
+
: itemType !== "enum" && typeof item !== itemType))
|
|
80
|
+
error = `Every item must be ${itemType}.`;
|
|
81
|
+
}
|
|
82
|
+
if (error)
|
|
83
|
+
errors[definition.name] = error;
|
|
84
|
+
}
|
|
85
|
+
return errors;
|
|
86
|
+
}
|
|
87
|
+
export function validatePromptSettings(settings) {
|
|
88
|
+
const errors = {};
|
|
89
|
+
for (const [field, label, min, max] of [
|
|
90
|
+
["temperature", "Temperature", 0, 2],
|
|
91
|
+
["topP", "Top P", 0, 1],
|
|
92
|
+
["maxTokens", "Max tokens", 1, 200000],
|
|
93
|
+
]) {
|
|
94
|
+
const raw = settings[field];
|
|
95
|
+
const value = Number(raw);
|
|
96
|
+
if (raw === "" ||
|
|
97
|
+
raw === null ||
|
|
98
|
+
raw === undefined ||
|
|
99
|
+
!Number.isFinite(value) ||
|
|
100
|
+
value < min ||
|
|
101
|
+
value > max ||
|
|
102
|
+
(field === "maxTokens" && !Number.isInteger(value)))
|
|
103
|
+
errors[field] =
|
|
104
|
+
`${label} must be ${field === "maxTokens" ? "a whole number" : "a number"} between ${min} and ${max}.`;
|
|
105
|
+
}
|
|
106
|
+
return errors;
|
|
107
|
+
}
|
|
108
|
+
//# sourceMappingURL=variables.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"variables.js","sourceRoot":"","sources":["../../../src/prompts/variables.ts"],"names":[],"mappings":"AAAA,qFAAqF;AACrF,MAAM,CAAC,MAAM,uBAAuB,GAClC,0CAA0C,CAAC;AAC7C,MAAM,UAAU,0BAA0B,CACxC,GAAG,MAAwC;IAE3C,OAAO;QACL,GAAG,IAAI,GAAG,CACR,MAAM,CAAC,OAAO,CAAC,CAAC,KAAK,EAAE,EAAE,CACvB,CAAC,GAAG,CAAC,KAAK,IAAI,EAAE,CAAC,CAAC,QAAQ,CAAC,uBAAuB,CAAC,CAAC,CAAC,GAAG,CACtD,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,CAAC,CAAE,CACrB,CACF,CACF;KACF,CAAC;AACJ,CAAC;AACD,MAAM,UAAU,mBAAmB,CACjC,MAA+B,EAC/B,IAAY;IAEZ,IAAI,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC;QAAE,OAAO,MAAM,CAAC,IAAI,CAAC,CAAC;IACrD,IAAI,OAAO,GAAY,MAAM,CAAC;IAC9B,KAAK,MAAM,GAAG,IAAI,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE,CAAC;QAClC,IACE,CAAC,WAAW,EAAE,WAAW,EAAE,aAAa,CAAC,CAAC,QAAQ,CAAC,GAAG,CAAC;YACvD,CAAC,OAAO;YACR,OAAO,OAAO,KAAK,QAAQ;YAC3B,CAAC,MAAM,CAAC,MAAM,CAAC,OAAO,EAAE,GAAG,CAAC;YAE5B,OAAO,SAAS,CAAC;QACnB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G,MAAM,CAAC,GAAG,CAAC,CAAC;QAC1B,IACE,GAAG,KAAK,EAAE;YACV,GAAG,KAAK,IAAI;YACZ,GAAG,KAAK,SAAS;YACjB,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC;YACvB,KAAK,GAAG,GAAG;YACX,KAAK,GAAG,GAAG;YACX,CAAC,KAAK,KAAK,WAAW,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;YAEnD,MAAM,CAAC,KAAK,CAAC;gBACX,GAAG,KAAK,YAAY,KAAK,KAAK,WAAW,CAAC,CAAC,CAAC,gBAAgB,CAAC,CAAC,CAAC,UAAU,YAAY,GAAG,QAAQ,GAAG,GAAG,CAAC;IAC7G,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nirmos/sdk",
|
|
3
|
-
"version": "0.2
|
|
3
|
+
"version": "0.3.2",
|
|
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
|
"check-types": "tsc --noEmit",
|
|
26
26
|
"lint": "eslint src tests --max-warnings 0",
|
|
27
27
|
"prepack": "pnpm build",
|
|
28
|
-
"test": "
|
|
28
|
+
"test": "node ./scripts/ensure-built.mjs && tsc -p tests/tsconfig.json && node --test tests/*.test.mjs"
|
|
29
29
|
},
|
|
30
30
|
"engines": {
|
|
31
31
|
"node": ">=18"
|
package/src/client.ts
CHANGED
|
@@ -1,70 +1,283 @@
|
|
|
1
|
-
import { ConfigurationError } from "./core/errors.js";
|
|
1
|
+
import { ConfigurationError, type APIError } from "./core/errors.js";
|
|
2
2
|
import { HttpTransport } from "./core/transport.js";
|
|
3
|
-
import type { HeadersInput } from "./core/types.js";
|
|
3
|
+
import type { HeadersInput, RequestOptions } from "./core/types.js";
|
|
4
|
+
import { Memory } from "./memory/memory.js";
|
|
4
5
|
import { Gateway } from "./gateway/gateway.js";
|
|
5
6
|
import { Prompts } from "./prompts/prompts.js";
|
|
6
7
|
import type { PromptCacheConfig } from "./prompts/types.js";
|
|
8
|
+
import {
|
|
9
|
+
managementResources,
|
|
10
|
+
type ManagementResources,
|
|
11
|
+
} from "./management/resources.js";
|
|
12
|
+
import type {
|
|
13
|
+
StartEvaluationRunRequest,
|
|
14
|
+
RunMutationResponse,
|
|
15
|
+
EvaluationRun,
|
|
16
|
+
EvaluationRunResults,
|
|
17
|
+
EvaluationRunCases,
|
|
18
|
+
EvaluationRunCaseDetail,
|
|
19
|
+
EvaluationResultsQuery,
|
|
20
|
+
} from "./management/execution-types.js";
|
|
7
21
|
|
|
22
|
+
export type NirmosAuth =
|
|
23
|
+
| { type: "browser-session" }
|
|
24
|
+
| { type: "api-key"; key: string }
|
|
25
|
+
| { type: "access-token"; token: string };
|
|
8
26
|
export interface NirmosOptions {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
baseUrl?: string;
|
|
13
|
-
/** Default request timeout. Defaults to 60 seconds. Set to 0 to disable. */
|
|
27
|
+
auth: NirmosAuth;
|
|
28
|
+
apiBaseUrl?: string;
|
|
29
|
+
runtimeBaseUrl?: string;
|
|
14
30
|
timeoutMs?: number;
|
|
15
|
-
/** Retry count for safe GET requests. Defaults to 2. */
|
|
16
31
|
maxRetries?: number;
|
|
17
|
-
/** Custom fetch implementation for tests or specialized runtimes. */
|
|
18
32
|
fetch?: typeof globalThis.fetch;
|
|
19
|
-
/** Headers added to every request. */
|
|
20
33
|
headers?: HeadersInput;
|
|
21
|
-
/** In-memory managed prompt cache configuration. Set false to disable. */
|
|
22
34
|
promptCache?: PromptCacheConfig | false;
|
|
35
|
+
/** Observe HTTP failures centrally, without changing method error semantics. */
|
|
36
|
+
onError?: (error: APIError) => void;
|
|
23
37
|
}
|
|
24
38
|
|
|
25
39
|
export class Nirmos {
|
|
26
40
|
readonly gateway: Gateway;
|
|
27
|
-
readonly
|
|
41
|
+
readonly auth: ManagementResources["auth"];
|
|
42
|
+
readonly permissions: ManagementResources["permissions"];
|
|
43
|
+
/** Runtime prompt rendering/caching protocol; management uses prompts. */
|
|
44
|
+
readonly managedPrompts: Prompts;
|
|
45
|
+
readonly apiKeys: ManagementResources["apiKeys"];
|
|
46
|
+
readonly invitations: ManagementResources["invitations"];
|
|
47
|
+
readonly logs: ManagementResources["logs"];
|
|
48
|
+
readonly models: ManagementResources["models"];
|
|
49
|
+
readonly observability: ManagementResources["observability"];
|
|
50
|
+
readonly organizations: ManagementResources["organizations"];
|
|
51
|
+
readonly prompts: ManagementResources["prompts"] & {
|
|
52
|
+
test: (
|
|
53
|
+
body: PromptTestRequest,
|
|
54
|
+
options?: RequestOptions,
|
|
55
|
+
) => Promise<PromptTestResponse>;
|
|
56
|
+
};
|
|
57
|
+
readonly providerCredentials: ManagementResources["providerCredentials"];
|
|
58
|
+
readonly providers: ManagementResources["providers"];
|
|
59
|
+
readonly routes: ManagementResources["routes"];
|
|
60
|
+
readonly traces: ManagementResources["traces"];
|
|
61
|
+
readonly users: ManagementResources["users"];
|
|
62
|
+
readonly vectorStores: ManagementResources["vectorStores"];
|
|
63
|
+
readonly workspace: ManagementResources["workspace"];
|
|
64
|
+
readonly endpoints: ManagementResources["endpoints"] & {
|
|
65
|
+
execute: (
|
|
66
|
+
id: string,
|
|
67
|
+
body: {
|
|
68
|
+
variables?: Record<string, unknown>;
|
|
69
|
+
metadata?: Record<string, unknown>;
|
|
70
|
+
},
|
|
71
|
+
options?: RequestOptions,
|
|
72
|
+
) => Promise<EndpointExecution>;
|
|
73
|
+
};
|
|
74
|
+
readonly memory: Memory;
|
|
75
|
+
readonly knowledge: ManagementResources["knowledge"];
|
|
76
|
+
readonly evaluations: Omit<ManagementResources["evaluations"], "runs"> & {
|
|
77
|
+
runs: ManagementResources["evaluations"]["runs"] & {
|
|
78
|
+
create: (
|
|
79
|
+
body: StartEvaluationRunRequest,
|
|
80
|
+
options?: RequestOptions,
|
|
81
|
+
) => Promise<RunMutationResponse>;
|
|
82
|
+
get: (id: string, options?: RequestOptions) => Promise<EvaluationRun>;
|
|
83
|
+
cancel: (
|
|
84
|
+
id: string,
|
|
85
|
+
options?: RequestOptions,
|
|
86
|
+
) => Promise<RunMutationResponse>;
|
|
87
|
+
retry: (
|
|
88
|
+
id: string,
|
|
89
|
+
options?: RequestOptions,
|
|
90
|
+
) => Promise<RunMutationResponse>;
|
|
91
|
+
results: (
|
|
92
|
+
id: string,
|
|
93
|
+
query?: EvaluationResultsQuery,
|
|
94
|
+
options?: RequestOptions,
|
|
95
|
+
) => Promise<EvaluationRunResults>;
|
|
96
|
+
cases: (
|
|
97
|
+
id: string,
|
|
98
|
+
query?: Pick<EvaluationResultsQuery, "page" | "pageSize">,
|
|
99
|
+
options?: RequestOptions,
|
|
100
|
+
) => Promise<EvaluationRunCases>;
|
|
101
|
+
case: (
|
|
102
|
+
id: string,
|
|
103
|
+
caseId: string,
|
|
104
|
+
options?: RequestOptions,
|
|
105
|
+
) => Promise<EvaluationRunCaseDetail>;
|
|
106
|
+
};
|
|
107
|
+
};
|
|
28
108
|
|
|
29
109
|
constructor(options: NirmosOptions) {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
110
|
+
if (
|
|
111
|
+
!options?.auth ||
|
|
112
|
+
typeof (options.fetch ?? globalThis.fetch) !== "function"
|
|
113
|
+
)
|
|
114
|
+
throw configError("Nirmos auth and a fetch implementation are required.");
|
|
115
|
+
if (options.auth.type === "api-key" && !options.auth.key.trim())
|
|
116
|
+
throw configError("Nirmos API key is required.");
|
|
117
|
+
if (options.auth.type === "access-token" && !options.auth.token.trim())
|
|
118
|
+
throw configError("Nirmos access token is required.");
|
|
119
|
+
const common = {
|
|
120
|
+
apiKey: options.auth.type === "api-key" ? options.auth.key : undefined,
|
|
121
|
+
accessToken:
|
|
122
|
+
options.auth.type === "access-token" ? options.auth.token : undefined,
|
|
123
|
+
credentials:
|
|
124
|
+
options.auth.type === "browser-session"
|
|
125
|
+
? ("include" as const)
|
|
126
|
+
: undefined,
|
|
34
127
|
timeoutMs: nonNegative(options.timeoutMs, 60_000),
|
|
35
128
|
maxRetries: nonNegativeInteger(options.maxRetries, 2),
|
|
36
129
|
fetch: options.fetch ?? globalThis.fetch,
|
|
37
130
|
headers: options.headers,
|
|
131
|
+
onError: options.onError,
|
|
132
|
+
};
|
|
133
|
+
const api = new HttpTransport({
|
|
134
|
+
...common,
|
|
135
|
+
baseUrl: normalizeBaseUrl(options.apiBaseUrl ?? "https://api.nirmos.com"),
|
|
38
136
|
});
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
137
|
+
const runtime = new HttpTransport({
|
|
138
|
+
...common,
|
|
139
|
+
runtime: true,
|
|
140
|
+
baseUrl: normalizeBaseUrl(
|
|
141
|
+
options.runtimeBaseUrl ?? "https://gateway.nirmos.com",
|
|
142
|
+
),
|
|
143
|
+
});
|
|
144
|
+
const resources = managementResources(api);
|
|
145
|
+
this.permissions = resources.permissions;
|
|
146
|
+
this.memory = new Memory(resources.memory, runtime);
|
|
147
|
+
this.auth = resources.auth;
|
|
148
|
+
this.apiKeys = resources.apiKeys;
|
|
149
|
+
this.invitations = resources.invitations;
|
|
150
|
+
this.logs = resources.logs;
|
|
151
|
+
this.models = resources.models;
|
|
152
|
+
this.observability = resources.observability;
|
|
153
|
+
this.organizations = resources.organizations;
|
|
154
|
+
this.prompts = {
|
|
155
|
+
...resources.prompts,
|
|
156
|
+
test: async (body, options) =>
|
|
157
|
+
(
|
|
158
|
+
await runtime.request<PromptTestResponse>({
|
|
159
|
+
method: "POST",
|
|
160
|
+
path: "/v1/test/prompt",
|
|
161
|
+
body,
|
|
162
|
+
options,
|
|
163
|
+
})
|
|
164
|
+
).data,
|
|
165
|
+
};
|
|
166
|
+
this.providerCredentials = resources.providerCredentials;
|
|
167
|
+
this.providers = resources.providers;
|
|
168
|
+
this.routes = resources.routes;
|
|
169
|
+
this.traces = resources.traces;
|
|
170
|
+
this.users = resources.users;
|
|
171
|
+
this.vectorStores = resources.vectorStores;
|
|
172
|
+
this.workspace = resources.workspace;
|
|
173
|
+
this.endpoints = {
|
|
174
|
+
...resources.endpoints,
|
|
175
|
+
execute: async (id, body, options) =>
|
|
176
|
+
(
|
|
177
|
+
await runtime.request<EndpointExecution>({
|
|
178
|
+
method: "POST",
|
|
179
|
+
path: `/v1/endpoints/${encodeURIComponent(id)}/execute`,
|
|
180
|
+
body,
|
|
181
|
+
options,
|
|
182
|
+
})
|
|
183
|
+
).data,
|
|
184
|
+
};
|
|
185
|
+
this.knowledge = resources.knowledge;
|
|
186
|
+
const runPath = (id: string) =>
|
|
187
|
+
`/v1/evaluations/runs/${encodeURIComponent(id)}`;
|
|
188
|
+
const command = async (
|
|
189
|
+
path: string,
|
|
190
|
+
body: unknown,
|
|
191
|
+
options?: RequestOptions,
|
|
192
|
+
) =>
|
|
193
|
+
(
|
|
194
|
+
await runtime.request<RunMutationResponse>({
|
|
195
|
+
method: "POST",
|
|
196
|
+
path,
|
|
197
|
+
body,
|
|
198
|
+
options,
|
|
199
|
+
})
|
|
200
|
+
).data;
|
|
201
|
+
const read = async <T>(
|
|
202
|
+
path: string,
|
|
203
|
+
query?: EvaluationResultsQuery,
|
|
204
|
+
options?: RequestOptions,
|
|
205
|
+
) =>
|
|
206
|
+
(
|
|
207
|
+
await runtime.request<T>({
|
|
208
|
+
method: "GET",
|
|
209
|
+
path,
|
|
210
|
+
query: { ...query },
|
|
211
|
+
options,
|
|
212
|
+
})
|
|
213
|
+
).data;
|
|
214
|
+
this.evaluations = {
|
|
215
|
+
...resources.evaluations,
|
|
216
|
+
runs: {
|
|
217
|
+
...resources.evaluations.runs,
|
|
218
|
+
create: (body, options) =>
|
|
219
|
+
command("/v1/evaluations/runs", body, options),
|
|
220
|
+
get: (id, options) =>
|
|
221
|
+
read<EvaluationRun>(runPath(id), undefined, options),
|
|
222
|
+
cancel: (id, options) =>
|
|
223
|
+
command(runPath(id) + "/cancel", undefined, options),
|
|
224
|
+
retry: (id, options) =>
|
|
225
|
+
command(runPath(id) + "/retry", undefined, options),
|
|
226
|
+
results: (id, query, options) =>
|
|
227
|
+
read<EvaluationRunResults>(runPath(id) + "/results", query, options),
|
|
228
|
+
cases: (id, query, options) =>
|
|
229
|
+
read<EvaluationRunCases>(runPath(id) + "/cases", query, options),
|
|
230
|
+
case: (id, caseId, options) =>
|
|
231
|
+
read<EvaluationRunCaseDetail>(
|
|
232
|
+
runPath(id) + "/cases/" + encodeURIComponent(caseId),
|
|
233
|
+
undefined,
|
|
234
|
+
options,
|
|
235
|
+
),
|
|
236
|
+
},
|
|
237
|
+
};
|
|
238
|
+
this.managedPrompts = new Prompts(runtime, options.promptCache);
|
|
239
|
+
this.gateway = new Gateway(runtime, this.managedPrompts);
|
|
42
240
|
}
|
|
43
241
|
}
|
|
44
242
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
243
|
+
export type KnowledgeSearchRequest =
|
|
244
|
+
import("./management/contracts.js").Requests["searchKnowledgeBase"];
|
|
245
|
+
export type KnowledgeSearchResponse =
|
|
246
|
+
import("./management/contracts.js").Responses["searchKnowledgeBase"];
|
|
247
|
+
export type KnowledgeSearchMode = KnowledgeSearchResponse["mode"];
|
|
248
|
+
export type KnowledgeMatch = KnowledgeSearchResponse["items"][number];
|
|
249
|
+
export type KnowledgeSearchStatus =
|
|
250
|
+
import("./management/contracts.js").Responses["getKnowledgeSearchStatus"];
|
|
251
|
+
export interface EndpointExecution {
|
|
252
|
+
success: boolean;
|
|
253
|
+
data: {
|
|
254
|
+
output: unknown;
|
|
255
|
+
raw_content?: string;
|
|
256
|
+
model: string;
|
|
257
|
+
provider: string;
|
|
258
|
+
output_valid: boolean;
|
|
259
|
+
repair_attempts: number;
|
|
260
|
+
};
|
|
261
|
+
usage: {
|
|
262
|
+
prompt_tokens: number;
|
|
263
|
+
completion_tokens: number;
|
|
264
|
+
total_tokens: number;
|
|
265
|
+
};
|
|
266
|
+
meta: {
|
|
267
|
+
endpoint_id: string;
|
|
268
|
+
version_id: string;
|
|
269
|
+
prompt_version_id: string;
|
|
270
|
+
request_id: string;
|
|
271
|
+
trace_id: string;
|
|
272
|
+
latency_ms: number;
|
|
273
|
+
};
|
|
60
274
|
}
|
|
61
|
-
|
|
62
275
|
function normalizeBaseUrl(value: string): string {
|
|
63
276
|
let url: URL;
|
|
64
277
|
try {
|
|
65
278
|
url = new URL(value);
|
|
66
279
|
} catch {
|
|
67
|
-
throw configError("Nirmos
|
|
280
|
+
throw configError("Nirmos base URL must be a valid absolute URL.");
|
|
68
281
|
}
|
|
69
282
|
return url.toString().replace(/\/+$/, "");
|
|
70
283
|
}
|
|
@@ -87,3 +300,53 @@ function nonNegativeInteger(
|
|
|
87
300
|
function configError(message: string): ConfigurationError {
|
|
88
301
|
return new ConfigurationError(message);
|
|
89
302
|
}
|
|
303
|
+
|
|
304
|
+
export interface PromptTestRequest {
|
|
305
|
+
messages: Array<{
|
|
306
|
+
role: string;
|
|
307
|
+
name?: string | null;
|
|
308
|
+
order?: number;
|
|
309
|
+
contentBlocks: Array<{
|
|
310
|
+
order?: number;
|
|
311
|
+
type: string;
|
|
312
|
+
text?: string | null;
|
|
313
|
+
uri?: string | null;
|
|
314
|
+
mimeType?: string | null;
|
|
315
|
+
data?: unknown;
|
|
316
|
+
}>;
|
|
317
|
+
}>;
|
|
318
|
+
selectedModel?: string;
|
|
319
|
+
temperature?: number;
|
|
320
|
+
maxTokens?: number;
|
|
321
|
+
topP?: number;
|
|
322
|
+
variables?: string[];
|
|
323
|
+
variablesInput?: Record<string, unknown>;
|
|
324
|
+
provider?: string;
|
|
325
|
+
structuredOutput?: unknown;
|
|
326
|
+
}
|
|
327
|
+
export interface PromptTestResponse {
|
|
328
|
+
success: boolean;
|
|
329
|
+
data?: {
|
|
330
|
+
output?: unknown;
|
|
331
|
+
raw_content?: string;
|
|
332
|
+
model?: string;
|
|
333
|
+
provider?: string;
|
|
334
|
+
output_valid?: boolean;
|
|
335
|
+
repair_attempts?: number;
|
|
336
|
+
structuredOutput?: {
|
|
337
|
+
validationPassed?: boolean;
|
|
338
|
+
validationErrors?: string[];
|
|
339
|
+
healingDetails?: {
|
|
340
|
+
llmRetryUsed?: boolean;
|
|
341
|
+
programmaticApplied?: boolean;
|
|
342
|
+
};
|
|
343
|
+
};
|
|
344
|
+
};
|
|
345
|
+
error?: string;
|
|
346
|
+
usage?: {
|
|
347
|
+
prompt_tokens?: number;
|
|
348
|
+
completion_tokens?: number;
|
|
349
|
+
total_tokens?: number;
|
|
350
|
+
};
|
|
351
|
+
meta?: { latency_ms?: number; request_id?: string; trace_id?: string };
|
|
352
|
+
}
|
package/src/core/errors.ts
CHANGED
|
@@ -5,12 +5,16 @@ export interface NirmosErrorOptions {
|
|
|
5
5
|
code?: string;
|
|
6
6
|
requestId?: string;
|
|
7
7
|
traceId?: string;
|
|
8
|
+
status?: number;
|
|
9
|
+
details?: unknown;
|
|
8
10
|
}
|
|
9
11
|
|
|
10
12
|
export class NirmosError extends Error {
|
|
11
13
|
readonly code?: string;
|
|
12
14
|
readonly requestId?: string;
|
|
13
15
|
readonly traceId?: string;
|
|
16
|
+
readonly status?: number;
|
|
17
|
+
readonly details?: unknown;
|
|
14
18
|
|
|
15
19
|
constructor(message: string, options: NirmosErrorOptions = {}) {
|
|
16
20
|
super(message, { cause: options.cause });
|
|
@@ -18,6 +22,8 @@ export class NirmosError extends Error {
|
|
|
18
22
|
this.code = options.code;
|
|
19
23
|
this.requestId = options.requestId;
|
|
20
24
|
this.traceId = options.traceId;
|
|
25
|
+
this.status = options.status;
|
|
26
|
+
this.details = options.details;
|
|
21
27
|
}
|
|
22
28
|
}
|
|
23
29
|
|
|
@@ -41,10 +47,10 @@ export interface APIErrorOptions extends NirmosErrorOptions {
|
|
|
41
47
|
}
|
|
42
48
|
|
|
43
49
|
export class APIError extends NirmosError {
|
|
44
|
-
readonly status: number;
|
|
50
|
+
declare readonly status: number;
|
|
45
51
|
readonly retryable: boolean;
|
|
46
52
|
readonly retryAfterMs?: number;
|
|
47
|
-
readonly details?: unknown;
|
|
53
|
+
declare readonly details?: unknown;
|
|
48
54
|
readonly metadata?: RequestMetadata;
|
|
49
55
|
readonly headers?: Headers;
|
|
50
56
|
|
package/src/core/metadata.ts
CHANGED
|
@@ -62,20 +62,11 @@ export function extractMetadata(
|
|
|
62
62
|
numericHeader(response, "x-nirmos-response-time", "x-response-time"),
|
|
63
63
|
};
|
|
64
64
|
|
|
65
|
-
const cacheStatus = header(
|
|
66
|
-
|
|
67
|
-
"x-nirmos-cache-status",
|
|
68
|
-
"x-promptnetra-cache-status",
|
|
69
|
-
);
|
|
70
|
-
const cacheLayer = header(
|
|
71
|
-
response,
|
|
72
|
-
"x-nirmos-cache-layer",
|
|
73
|
-
"x-promptnetra-cache-layer",
|
|
74
|
-
);
|
|
65
|
+
const cacheStatus = header(response, "nirmos-cache-status");
|
|
66
|
+
const cacheLayer = header(response, "nirmos-cache-layer");
|
|
75
67
|
const remainingTtlSeconds = numericHeader(
|
|
76
68
|
response,
|
|
77
|
-
"
|
|
78
|
-
"x-promptnetra-cache-remaining-ttl",
|
|
69
|
+
"nirmos-cache-remaining-ttl",
|
|
79
70
|
);
|
|
80
71
|
|
|
81
72
|
if (cacheStatus || cacheLayer || remainingTtlSeconds !== undefined) {
|