cognia-sdk 0.1.4 → 0.1.5

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,39 @@ 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
+ if (e?.name === "AbortError")
124
+ throw e;
125
+ throw new CogniaError(`Cognia ${method} ${path} → token provider failed`, 0, null);
126
+ }
127
+ finally {
128
+ if (dt)
129
+ clearTimeout(dt);
130
+ }
131
+ }
132
+ else
133
+ token = this.key;
108
134
  if (!token)
109
135
  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 });
136
+ const r = await this.f(this.baseUrl + path, { method, headers: { authorization: `Bearer ${token}`, "content-type": "application/json", "user-agent": "cognia-sdk/0.1.5" }, body: body === undefined ? undefined : JSON.stringify(body), signal: ac.signal });
111
137
  let j = null;
112
138
  try {
113
139
  j = await r.json();
@@ -96,13 +96,39 @@ 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
+ if (e?.name === "AbortError")
119
+ throw e;
120
+ throw new CogniaError(`Cognia ${method} ${path} → token provider failed`, 0, null);
121
+ }
122
+ finally {
123
+ if (dt)
124
+ clearTimeout(dt);
125
+ }
126
+ }
127
+ else
128
+ token = this.key;
103
129
  if (!token)
104
130
  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 });
131
+ const r = await this.f(this.baseUrl + path, { method, headers: { authorization: `Bearer ${token}`, "content-type": "application/json", "user-agent": "cognia-sdk/0.1.5" }, body: body === undefined ? undefined : JSON.stringify(body), signal: ac.signal });
106
132
  let j = null;
107
133
  try {
108
134
  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.5",
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",