cognia-sdk 0.1.1 → 0.1.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/dist/cjs/client.js +26 -1
- package/dist/cjs/render.js +9 -7
- package/dist/esm/client.js +26 -1
- package/dist/esm/render.js +9 -7
- package/package.json +1 -1
package/dist/cjs/client.js
CHANGED
|
@@ -9,7 +9,32 @@ function shapeContext(r) {
|
|
|
9
9
|
const o = r;
|
|
10
10
|
if (typeof o.contextId !== "string" || (o.decision !== "INJECT" && o.decision !== "ABSTAIN"))
|
|
11
11
|
return null;
|
|
12
|
-
|
|
12
|
+
// every item is NORMALISED, not merely filtered (independent E2E F01 retest, 2026-10-07): a missing or null
|
|
13
|
+
// provenance, a Skill body whose arrays arrive as strings, a non-string title — none of these may reach the
|
|
14
|
+
// renderer and throw, because a throw here means the host model is never called (the fail-open contract)
|
|
15
|
+
const arr = (v) => Array.isArray(v) ? v.filter((x) => typeof x === "string") : typeof v === "string" && v ? [v] : [];
|
|
16
|
+
const str = (v, d = "") => (typeof v === "string" ? v : d);
|
|
17
|
+
const num = (v) => (typeof v === "number" && Number.isFinite(v) ? v : 0);
|
|
18
|
+
const q = (p) => (p && typeof p === "object" ? p : {});
|
|
19
|
+
const sOrNull = (v) => (typeof v === "string" ? v : null);
|
|
20
|
+
const items = (Array.isArray(o.items) ? o.items : []).flatMap((raw) => {
|
|
21
|
+
if (!raw || typeof raw !== "object")
|
|
22
|
+
return [];
|
|
23
|
+
const it = raw;
|
|
24
|
+
if (typeof it.id !== "string" || (it.kind !== "memory" && it.kind !== "skill"))
|
|
25
|
+
return [];
|
|
26
|
+
const owner = it.owner === "mine" ? "mine" : it.owner === "organization" ? "organization" : "network";
|
|
27
|
+
const body = q(it.body), p = q(it.provenance);
|
|
28
|
+
const base = { id: it.id, displayId: str(it.displayId, it.id), title: str(it.title, "(untitled)"), owner, score: typeof it.score === "number" && Number.isFinite(it.score) ? it.score : null };
|
|
29
|
+
if (it.kind === "memory") {
|
|
30
|
+
const m = { ...base, kind: "memory", body: { text: str(body.text), kind: sOrNull(body.kind) },
|
|
31
|
+
provenance: { ownerName: sOrNull(p.ownerName), organizationName: sOrNull(p.organizationName), maturity: sOrNull(p.maturity), verifiedUses: num(p.verifiedUses), created: sOrNull(p.created) } };
|
|
32
|
+
return [m];
|
|
33
|
+
}
|
|
34
|
+
const k = { ...base, kind: "skill", body: { summary: str(body.summary), trigger: arr(body.trigger), procedure: arr(body.procedure), verification: arr(body.verification), doNotApplyWhen: arr(body.doNotApplyWhen) },
|
|
35
|
+
provenance: { ownerName: sOrNull(p.ownerName), maturity: str(p.maturity, "unknown"), verifiedUses: num(p.verifiedUses), routeId: sOrNull(p.routeId) } };
|
|
36
|
+
return [k];
|
|
37
|
+
});
|
|
13
38
|
const decision = o.decision === "INJECT" && items.length ? "INJECT" : "ABSTAIN";
|
|
14
39
|
const scope = o.scope === "mine" || o.scope === "organization" || o.scope === "network" ? o.scope : "organization";
|
|
15
40
|
const metrics = (o.metrics && typeof o.metrics === "object" ? o.metrics : { ms: { search: 0, total: 0 }, considered: 0, returned: items.length });
|
package/dist/cjs/render.js
CHANGED
|
@@ -4,9 +4,10 @@ exports.provenanceLine = provenanceLine;
|
|
|
4
4
|
exports.renderContextBlock = renderContextBlock;
|
|
5
5
|
/** One provenance line the model can cite and a reader can look up: reference · owner · organization · evidence. */
|
|
6
6
|
function provenanceLine(it) {
|
|
7
|
-
const who = it.owner === "mine" ? "yours" : it.owner === "organization" ? `shared by ${neutral(it.provenance
|
|
8
|
-
const
|
|
9
|
-
const
|
|
7
|
+
const who = it.owner === "mine" ? "yours" : it.owner === "organization" ? `shared by ${neutral(it.provenance?.ownerName ?? "a colleague")}` : `public, by ${neutral(it.provenance.ownerName ?? "another owner")}`;
|
|
8
|
+
const uses = Number(it.provenance?.verifiedUses ?? 0) || 0;
|
|
9
|
+
const ev = uses > 0 ? `${uses} verified ${uses === 1 ? "use" : "uses"}` : "no verified use yet";
|
|
10
|
+
const mat = it.provenance?.maturity ? ` · ${String(it.provenance.maturity).toLowerCase()}` : "";
|
|
10
11
|
return `[${it.displayId} · ${who}${mat} · ${ev}]`;
|
|
11
12
|
}
|
|
12
13
|
/** The context block placed before the model's instructions. Plain text, deterministic, nothing invented. */
|
|
@@ -25,10 +26,11 @@ function renderContextBlock(ctx) {
|
|
|
25
26
|
parts.push(`\n[${n}] MEMORY ${provenanceLine(it)}\nTitle: ${neutral(it.title)}\n${neutral(it.body.text)}`);
|
|
26
27
|
}
|
|
27
28
|
else {
|
|
28
|
-
const
|
|
29
|
-
const
|
|
30
|
-
const
|
|
31
|
-
const
|
|
29
|
+
const list = (v) => Array.isArray(v) ? v.map(String) : typeof v === "string" && v ? [v] : [];
|
|
30
|
+
const steps = list(it.body?.procedure).map((s, j) => ` ${j + 1}. ${neutral(s)}`).join("\n");
|
|
31
|
+
const when = list(it.body?.trigger).length ? `When: ${neutral(list(it.body?.trigger).join("; "))}\n` : "";
|
|
32
|
+
const not = list(it.body?.doNotApplyWhen).length ? `Do not apply when: ${neutral(list(it.body?.doNotApplyWhen).join("; "))}\n` : "";
|
|
33
|
+
const verify = list(it.body?.verification).length ? `Verify: ${neutral(list(it.body?.verification).join("; "))}\n` : "";
|
|
32
34
|
parts.push(`\n[${n}] SKILL ${provenanceLine(it)}\nTitle: ${neutral(it.title)}\n${neutral(it.body.summary)}\n${when}${not}Procedure:\n${steps}\n${verify}`.trimEnd());
|
|
33
35
|
}
|
|
34
36
|
});
|
package/dist/esm/client.js
CHANGED
|
@@ -5,7 +5,32 @@ export function shapeContext(r) {
|
|
|
5
5
|
const o = r;
|
|
6
6
|
if (typeof o.contextId !== "string" || (o.decision !== "INJECT" && o.decision !== "ABSTAIN"))
|
|
7
7
|
return null;
|
|
8
|
-
|
|
8
|
+
// every item is NORMALISED, not merely filtered (independent E2E F01 retest, 2026-10-07): a missing or null
|
|
9
|
+
// provenance, a Skill body whose arrays arrive as strings, a non-string title — none of these may reach the
|
|
10
|
+
// renderer and throw, because a throw here means the host model is never called (the fail-open contract)
|
|
11
|
+
const arr = (v) => Array.isArray(v) ? v.filter((x) => typeof x === "string") : typeof v === "string" && v ? [v] : [];
|
|
12
|
+
const str = (v, d = "") => (typeof v === "string" ? v : d);
|
|
13
|
+
const num = (v) => (typeof v === "number" && Number.isFinite(v) ? v : 0);
|
|
14
|
+
const q = (p) => (p && typeof p === "object" ? p : {});
|
|
15
|
+
const sOrNull = (v) => (typeof v === "string" ? v : null);
|
|
16
|
+
const items = (Array.isArray(o.items) ? o.items : []).flatMap((raw) => {
|
|
17
|
+
if (!raw || typeof raw !== "object")
|
|
18
|
+
return [];
|
|
19
|
+
const it = raw;
|
|
20
|
+
if (typeof it.id !== "string" || (it.kind !== "memory" && it.kind !== "skill"))
|
|
21
|
+
return [];
|
|
22
|
+
const owner = it.owner === "mine" ? "mine" : it.owner === "organization" ? "organization" : "network";
|
|
23
|
+
const body = q(it.body), p = q(it.provenance);
|
|
24
|
+
const base = { id: it.id, displayId: str(it.displayId, it.id), title: str(it.title, "(untitled)"), owner, score: typeof it.score === "number" && Number.isFinite(it.score) ? it.score : null };
|
|
25
|
+
if (it.kind === "memory") {
|
|
26
|
+
const m = { ...base, kind: "memory", body: { text: str(body.text), kind: sOrNull(body.kind) },
|
|
27
|
+
provenance: { ownerName: sOrNull(p.ownerName), organizationName: sOrNull(p.organizationName), maturity: sOrNull(p.maturity), verifiedUses: num(p.verifiedUses), created: sOrNull(p.created) } };
|
|
28
|
+
return [m];
|
|
29
|
+
}
|
|
30
|
+
const k = { ...base, kind: "skill", body: { summary: str(body.summary), trigger: arr(body.trigger), procedure: arr(body.procedure), verification: arr(body.verification), doNotApplyWhen: arr(body.doNotApplyWhen) },
|
|
31
|
+
provenance: { ownerName: sOrNull(p.ownerName), maturity: str(p.maturity, "unknown"), verifiedUses: num(p.verifiedUses), routeId: sOrNull(p.routeId) } };
|
|
32
|
+
return [k];
|
|
33
|
+
});
|
|
9
34
|
const decision = o.decision === "INJECT" && items.length ? "INJECT" : "ABSTAIN";
|
|
10
35
|
const scope = o.scope === "mine" || o.scope === "organization" || o.scope === "network" ? o.scope : "organization";
|
|
11
36
|
const metrics = (o.metrics && typeof o.metrics === "object" ? o.metrics : { ms: { search: 0, total: 0 }, considered: 0, returned: items.length });
|
package/dist/esm/render.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
/** One provenance line the model can cite and a reader can look up: reference · owner · organization · evidence. */
|
|
2
2
|
export function provenanceLine(it) {
|
|
3
|
-
const who = it.owner === "mine" ? "yours" : it.owner === "organization" ? `shared by ${neutral(it.provenance
|
|
4
|
-
const
|
|
5
|
-
const
|
|
3
|
+
const who = it.owner === "mine" ? "yours" : it.owner === "organization" ? `shared by ${neutral(it.provenance?.ownerName ?? "a colleague")}` : `public, by ${neutral(it.provenance.ownerName ?? "another owner")}`;
|
|
4
|
+
const uses = Number(it.provenance?.verifiedUses ?? 0) || 0;
|
|
5
|
+
const ev = uses > 0 ? `${uses} verified ${uses === 1 ? "use" : "uses"}` : "no verified use yet";
|
|
6
|
+
const mat = it.provenance?.maturity ? ` · ${String(it.provenance.maturity).toLowerCase()}` : "";
|
|
6
7
|
return `[${it.displayId} · ${who}${mat} · ${ev}]`;
|
|
7
8
|
}
|
|
8
9
|
/** The context block placed before the model's instructions. Plain text, deterministic, nothing invented. */
|
|
@@ -21,10 +22,11 @@ export function renderContextBlock(ctx) {
|
|
|
21
22
|
parts.push(`\n[${n}] MEMORY ${provenanceLine(it)}\nTitle: ${neutral(it.title)}\n${neutral(it.body.text)}`);
|
|
22
23
|
}
|
|
23
24
|
else {
|
|
24
|
-
const
|
|
25
|
-
const
|
|
26
|
-
const
|
|
27
|
-
const
|
|
25
|
+
const list = (v) => Array.isArray(v) ? v.map(String) : typeof v === "string" && v ? [v] : [];
|
|
26
|
+
const steps = list(it.body?.procedure).map((s, j) => ` ${j + 1}. ${neutral(s)}`).join("\n");
|
|
27
|
+
const when = list(it.body?.trigger).length ? `When: ${neutral(list(it.body?.trigger).join("; "))}\n` : "";
|
|
28
|
+
const not = list(it.body?.doNotApplyWhen).length ? `Do not apply when: ${neutral(list(it.body?.doNotApplyWhen).join("; "))}\n` : "";
|
|
29
|
+
const verify = list(it.body?.verification).length ? `Verify: ${neutral(list(it.body?.verification).join("; "))}\n` : "";
|
|
28
30
|
parts.push(`\n[${n}] SKILL ${provenanceLine(it)}\nTitle: ${neutral(it.title)}\n${neutral(it.body.summary)}\n${when}${not}Procedure:\n${steps}\n${verify}`.trimEnd());
|
|
29
31
|
}
|
|
30
32
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cognia-sdk",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"description": "Cognia for your model calls: one line gives any agent the Memories and Skills it may use, with provenance and honest receipts. Fails open.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Cognia",
|