cognia-sdk 0.1.4 → 0.1.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.
@@ -101,13 +101,40 @@ class Cognia {
101
101
  let token = null;
102
102
  try {
103
103
  // delegated auth: the provider is asked on EVERY request, INSIDE the same deadline as the request itself (independent
104
- // E2E F27: a pending provider used to block the host model), and its answer is used once, never stored on the client
105
- const deadline = new Promise((_, reject) => { if (timeoutMs)
106
- setTimeout(() => reject(Object.assign(new Error("tokenProvider timed out"), { name: "AbortError" })), timeoutMs); });
107
- token = this.tokenProvider ? await (timeoutMs ? Promise.race([Promise.resolve(this.tokenProvider()), deadline]) : this.tokenProvider()) : this.key;
104
+ // E2E F27: a pending provider used to block the host model), and its answer is used once, never stored on the client.
105
+ // The deadline exists only while a provider is pending and is always observed (F30: an unobserved rejection in the
106
+ // apiKey path crashed the host process). A provider failure is reported WITHOUT its message (F28: the SDK cannot
107
+ // scrub a bearer it never received) — the host owns that error and can log it itself.
108
+ if (this.tokenProvider) {
109
+ let dt = null;
110
+ const provider = new Promise((resolve, reject) => { try {
111
+ resolve(this.tokenProvider());
112
+ }
113
+ catch (e) {
114
+ reject(e);
115
+ } });
116
+ const deadline = new Promise((_, reject) => { if (timeoutMs)
117
+ dt = setTimeout(() => reject(Object.assign(new Error("tokenProvider timed out"), { name: "AbortError" })), timeoutMs); });
118
+ deadline.catch(() => undefined); // never an unhandled rejection
119
+ try {
120
+ token = await (timeoutMs ? Promise.race([provider, deadline]) : provider);
121
+ }
122
+ catch (e) {
123
+ // never the provider's own object or message (it may carry the bearer): a fresh error either way
124
+ if (e?.name === "AbortError")
125
+ throw Object.assign(new Error("tokenProvider timed out"), { name: "AbortError" });
126
+ throw new CogniaError(`Cognia ${method} ${path} → token provider failed`, 0, null);
127
+ }
128
+ finally {
129
+ if (dt)
130
+ clearTimeout(dt);
131
+ }
132
+ }
133
+ else
134
+ token = this.key;
108
135
  if (!token)
109
136
  throw new CogniaError(`Cognia ${method} ${path} → no credential`, 0, null);
110
- const r = await this.f(this.baseUrl + path, { method, headers: { authorization: `Bearer ${token}`, "content-type": "application/json", "user-agent": "cognia-sdk/0.1.4" }, body: body === undefined ? undefined : JSON.stringify(body), signal: ac.signal });
137
+ const r = await this.f(this.baseUrl + path, { method, headers: { authorization: `Bearer ${token}`, "content-type": "application/json", "user-agent": "cognia-sdk/0.1.6" }, body: body === undefined ? undefined : JSON.stringify(body), signal: ac.signal });
111
138
  let j = null;
112
139
  try {
113
140
  j = await r.json();
@@ -96,13 +96,40 @@ export class Cognia {
96
96
  let token = null;
97
97
  try {
98
98
  // delegated auth: the provider is asked on EVERY request, INSIDE the same deadline as the request itself (independent
99
- // E2E F27: a pending provider used to block the host model), and its answer is used once, never stored on the client
100
- const deadline = new Promise((_, reject) => { if (timeoutMs)
101
- setTimeout(() => reject(Object.assign(new Error("tokenProvider timed out"), { name: "AbortError" })), timeoutMs); });
102
- token = this.tokenProvider ? await (timeoutMs ? Promise.race([Promise.resolve(this.tokenProvider()), deadline]) : this.tokenProvider()) : this.key;
99
+ // E2E F27: a pending provider used to block the host model), and its answer is used once, never stored on the client.
100
+ // The deadline exists only while a provider is pending and is always observed (F30: an unobserved rejection in the
101
+ // apiKey path crashed the host process). A provider failure is reported WITHOUT its message (F28: the SDK cannot
102
+ // scrub a bearer it never received) — the host owns that error and can log it itself.
103
+ if (this.tokenProvider) {
104
+ let dt = null;
105
+ const provider = new Promise((resolve, reject) => { try {
106
+ resolve(this.tokenProvider());
107
+ }
108
+ catch (e) {
109
+ reject(e);
110
+ } });
111
+ const deadline = new Promise((_, reject) => { if (timeoutMs)
112
+ dt = setTimeout(() => reject(Object.assign(new Error("tokenProvider timed out"), { name: "AbortError" })), timeoutMs); });
113
+ deadline.catch(() => undefined); // never an unhandled rejection
114
+ try {
115
+ token = await (timeoutMs ? Promise.race([provider, deadline]) : provider);
116
+ }
117
+ catch (e) {
118
+ // never the provider's own object or message (it may carry the bearer): a fresh error either way
119
+ if (e?.name === "AbortError")
120
+ throw Object.assign(new Error("tokenProvider timed out"), { name: "AbortError" });
121
+ throw new CogniaError(`Cognia ${method} ${path} → token provider failed`, 0, null);
122
+ }
123
+ finally {
124
+ if (dt)
125
+ clearTimeout(dt);
126
+ }
127
+ }
128
+ else
129
+ token = this.key;
103
130
  if (!token)
104
131
  throw new CogniaError(`Cognia ${method} ${path} → no credential`, 0, null);
105
- const r = await this.f(this.baseUrl + path, { method, headers: { authorization: `Bearer ${token}`, "content-type": "application/json", "user-agent": "cognia-sdk/0.1.4" }, body: body === undefined ? undefined : JSON.stringify(body), signal: ac.signal });
132
+ const r = await this.f(this.baseUrl + path, { method, headers: { authorization: `Bearer ${token}`, "content-type": "application/json", "user-agent": "cognia-sdk/0.1.6" }, body: body === undefined ? undefined : JSON.stringify(body), signal: ac.signal });
106
133
  let j = null;
107
134
  try {
108
135
  j = await r.json();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cognia-sdk",
3
- "version": "0.1.4",
3
+ "version": "0.1.6",
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",