cognia-sdk 0.1.7 → 0.2.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 +13 -0
- package/dist/cjs/client.js +4 -1
- package/dist/esm/client.d.ts +4 -0
- package/dist/esm/client.js +4 -1
- package/dist/esm/types.d.ts +4 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -94,3 +94,16 @@ unverified reports listed apart.
|
|
|
94
94
|
**Credits.** Reporting on other owners' knowledge earns Cloud credits (verified outcomes most, used receipts a little,
|
|
95
95
|
context calls that injected a little), and your own memories earn when an independent agent's verified success lands on
|
|
96
96
|
them. Credits pay for Workbench messages beyond your plan. They are not money. `GET /v1/cloud/me/credits` lists them.
|
|
97
|
+
|
|
98
|
+
## Namespaces: one key, many end users (0.2.0)
|
|
99
|
+
|
|
100
|
+
If you build an app where many people each have their own agent, give each of them a namespace:
|
|
101
|
+
|
|
102
|
+
```ts
|
|
103
|
+
const cognia = new Cognia({ apiKey: process.env.COGNIA_API_KEY, namespace: `user:${userId}` });
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
Every context call then carries that namespace. A private memory saved under it is returned only to the same
|
|
107
|
+
namespace: the `mine` scope never crosses from one of your users to another, and the `organization` and `network`
|
|
108
|
+
scopes add only what is shared with your organizations or public. Omit the namespace for a single-agent integration.
|
|
109
|
+
Your own Cognia Cloud still shows everything the key owns: you are the data controller for your users' memories.
|
package/dist/cjs/client.js
CHANGED
|
@@ -62,7 +62,9 @@ class Cognia {
|
|
|
62
62
|
tokenProvider;
|
|
63
63
|
f;
|
|
64
64
|
onError;
|
|
65
|
+
namespace;
|
|
65
66
|
constructor(o) {
|
|
67
|
+
this.namespace = o.namespace;
|
|
66
68
|
if (!o.apiKey && !o.tokenProvider)
|
|
67
69
|
throw new Error("Cognia: apiKey or tokenProvider is required");
|
|
68
70
|
this.key = o.apiKey ?? null;
|
|
@@ -166,7 +168,8 @@ class Cognia {
|
|
|
166
168
|
*/
|
|
167
169
|
async context(req) {
|
|
168
170
|
const body = typeof req === "string" ? { task: req } : req;
|
|
169
|
-
const
|
|
171
|
+
const ns = body.identity?.namespace ?? this.namespace;
|
|
172
|
+
const payload = { task: body.task, scope: body.scope ?? this.scope, ...(body.budget ?? this.budget ? { budget: { ...this.budget, ...body.budget } } : {}), ...(body.session ? { session: body.session } : {}), ...(ns ? { identity: { namespace: ns } } : {}) };
|
|
170
173
|
try {
|
|
171
174
|
const r = await this.call("POST", "/v1/context", payload, this.timeoutMs);
|
|
172
175
|
const shaped = shapeContext(r);
|
package/dist/esm/client.d.ts
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import type { ReceiptResponse, ContextRequest, ContextResponse, ContextResult, OutcomeInput, OutcomeResponse, ExtractResponse, Scope } from "./types.js";
|
|
2
2
|
export interface CogniaOptions {
|
|
3
|
+
/** end-user namespace sent on every context call (0.2.0). Use one per end user of YOUR app: their private memories
|
|
4
|
+
* are then invisible to every other namespace under the same key. Omit for a single-agent integration. */
|
|
5
|
+
namespace?: string;
|
|
3
6
|
/** the agent's credential (cognia_sk_…, a developer or SDK credential); never logged, never put in a URL */
|
|
4
7
|
apiKey?: string;
|
|
5
8
|
/** Delegated auth: called at REQUEST time to obtain the bearer (e.g. an MCP OAuth access token the host already
|
|
@@ -39,6 +42,7 @@ export declare class Cognia {
|
|
|
39
42
|
private readonly tokenProvider;
|
|
40
43
|
private readonly f;
|
|
41
44
|
private readonly onError;
|
|
45
|
+
readonly namespace: string | undefined;
|
|
42
46
|
constructor(o: CogniaOptions);
|
|
43
47
|
/** Every string that reaches the host through an error or a reason has the bearer removed first (independent E2E F28). */
|
|
44
48
|
private scrub;
|
package/dist/esm/client.js
CHANGED
|
@@ -57,7 +57,9 @@ export class Cognia {
|
|
|
57
57
|
tokenProvider;
|
|
58
58
|
f;
|
|
59
59
|
onError;
|
|
60
|
+
namespace;
|
|
60
61
|
constructor(o) {
|
|
62
|
+
this.namespace = o.namespace;
|
|
61
63
|
if (!o.apiKey && !o.tokenProvider)
|
|
62
64
|
throw new Error("Cognia: apiKey or tokenProvider is required");
|
|
63
65
|
this.key = o.apiKey ?? null;
|
|
@@ -161,7 +163,8 @@ export class Cognia {
|
|
|
161
163
|
*/
|
|
162
164
|
async context(req) {
|
|
163
165
|
const body = typeof req === "string" ? { task: req } : req;
|
|
164
|
-
const
|
|
166
|
+
const ns = body.identity?.namespace ?? this.namespace;
|
|
167
|
+
const payload = { task: body.task, scope: body.scope ?? this.scope, ...(body.budget ?? this.budget ? { budget: { ...this.budget, ...body.budget } } : {}), ...(body.session ? { session: body.session } : {}), ...(ns ? { identity: { namespace: ns } } : {}) };
|
|
165
168
|
try {
|
|
166
169
|
const r = await this.call("POST", "/v1/context", payload, this.timeoutMs);
|
|
167
170
|
const shaped = shapeContext(r);
|
package/dist/esm/types.d.ts
CHANGED
|
@@ -12,6 +12,10 @@ export interface ContextRequest {
|
|
|
12
12
|
id: string;
|
|
13
13
|
turn: number;
|
|
14
14
|
};
|
|
15
|
+
/** end-user namespace (0.2.0): one developer key, many end users; private memories are isolated per namespace */
|
|
16
|
+
identity?: {
|
|
17
|
+
namespace?: string;
|
|
18
|
+
};
|
|
15
19
|
}
|
|
16
20
|
export interface MemoryItem {
|
|
17
21
|
kind: "memory";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cognia-sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
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",
|