@cohortapp/agent-sdk 2.11.7 → 2.11.8

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cohortapp/agent-sdk",
3
- "version": "2.11.7",
3
+ "version": "2.11.8",
4
4
  "description": "Cohort Agent SDK — autonomous AI colleague runtime. Deploy senior AI colleagues on dedicated Mac minis, wired to the Cohort operating surface.",
5
5
  "type": "module",
6
6
  "bin": {
@@ -1118,13 +1118,26 @@ export async function resolveSelfMemberId(deps = {}) {
1118
1118
  try {
1119
1119
  const cfg = daemonOrgCfg();
1120
1120
  const conn = configFromAgent(cfg) || {};
1121
- const apiKey = conn.apiKey || process.env.COHORT_API_KEY || "";
1121
+ // configFromAgent returns the org key as `token` (NOT `apiKey`), and the
1122
+ // daemon's creds come from config/org.yaml, not process.env — so read `token`
1123
+ // first and only fall back to env. The slug lives at cfg.org.cohort.agentId
1124
+ // (same source ladderMemberId used); without it fetchSelfProfile can't hit
1125
+ // /members/<slug> and whoami is ambiguous in a multi-agent org.
1126
+ const apiKey = conn.token || conn.apiKey || process.env.COHORT_API_KEY || "";
1122
1127
  const orgId = conn.orgId || process.env.COHORT_ORG_ID || "";
1123
- const agentId = conn.agentId || process.env.COHORT_AGENT_ID || "";
1128
+ const agentId =
1129
+ conn.agentId ||
1130
+ (cfg && cfg.org && cfg.org.cohort && cfg.org.cohort.agentId) ||
1131
+ process.env.COHORT_AGENT_ID ||
1132
+ "";
1133
+ const base = conn.base || process.env.COHORT_BASE || "";
1124
1134
  if (!apiKey || !orgId) return _selfMemberId;
1125
1135
  const fetchSelf = deps.fetchSelfProfileImpl || fetchSelfProfile;
1126
- const res = await fetchSelf({ base: conn.base, apiKey, orgId, agentId });
1127
- const mid = res && res.ok && res.member && res.member.memberId ? String(res.member.memberId) : "";
1136
+ const res = await fetchSelf({ base, apiKey, orgId, agentId });
1137
+ // fetchSelfProfile returns a res frame with the member under `result` (the
1138
+ // authed call() shape); tolerate `member` too for the raw directory route.
1139
+ const m = res && res.ok ? (res.result || res.member) : null;
1140
+ const mid = m && m.memberId ? String(m.memberId) : "";
1128
1141
  if (mid) {
1129
1142
  _selfMemberId = mid;
1130
1143
  try {
@@ -830,3 +830,35 @@ test("NO FALLTHROUGH: a TRANSIENT quick-reply failure still falls through to a f
830
830
  assert.equal(dispatched, true, "a transient failure falls through to the full session, as before");
831
831
  assert.equal(res.path, "session");
832
832
  });
833
+
834
+ test("resolveSelfMemberId reads the member cuid from the res frame's `result` (own-echo keystone)", async () => {
835
+ daemon._resetSelfMemberId();
836
+ const pk = process.env.COHORT_API_KEY, po = process.env.COHORT_ORG_ID, pa = process.env.COHORT_AGENT_ID;
837
+ process.env.COHORT_API_KEY = "nlk_test";
838
+ process.env.COHORT_ORG_ID = "org_test";
839
+ process.env.COHORT_AGENT_ID = "A016";
840
+ try {
841
+ let calls = 0;
842
+ // fetchSelfProfile returns the authed call() res frame: the member is under
843
+ // `result`, and the org key is passed as apiKey. (Both were wrong in 2.11.7.)
844
+ const mid = await daemon.resolveSelfMemberId({
845
+ fetchSelfProfileImpl: async (o) => {
846
+ calls++;
847
+ assert.equal(o.agentId, "A016", "must pass the slug so /members/<slug> resolves");
848
+ return { ok: true, result: { memberId: "cmSELFcuid", slug: o.agentId } };
849
+ },
850
+ });
851
+ assert.equal(mid, "cmSELFcuid");
852
+ // cached: a second call must NOT refetch
853
+ const again = await daemon.resolveSelfMemberId({
854
+ fetchSelfProfileImpl: async () => { throw new Error("must not refetch a cached self id"); },
855
+ });
856
+ assert.equal(again, "cmSELFcuid");
857
+ assert.equal(calls, 1);
858
+ } finally {
859
+ daemon._resetSelfMemberId();
860
+ if (pk === undefined) delete process.env.COHORT_API_KEY; else process.env.COHORT_API_KEY = pk;
861
+ if (po === undefined) delete process.env.COHORT_ORG_ID; else process.env.COHORT_ORG_ID = po;
862
+ if (pa === undefined) delete process.env.COHORT_AGENT_ID; else process.env.COHORT_AGENT_ID = pa;
863
+ }
864
+ });