@ainecto/mcp 0.14.0-next.2 → 0.14.0-next.4

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.
@@ -5678,7 +5678,7 @@ function legacyRoleInput(flag, envVars = process.env) {
5678
5678
 
5679
5679
  // src/core/version.ts
5680
5680
  var UNBUNDLED_VERSION = "dev";
5681
- var CLI_VERSION = true ? "0.14.0-next.2" : UNBUNDLED_VERSION;
5681
+ var CLI_VERSION = true ? "0.14.0-next.4" : UNBUNDLED_VERSION;
5682
5682
  var PACKAGE_NAME = "@ainecto/mcp";
5683
5683
  var CLI_USER_AGENT = `${PACKAGE_NAME} ${CLI_VERSION}`;
5684
5684
  function bridgePackageSpec(version = CLI_VERSION) {
@@ -12859,23 +12859,29 @@ function claudeCodeAdapter(deps) {
12859
12859
  if (run.spawnError || run.timedOut) {
12860
12860
  return { ready: false, detail: run.spawnError ?? "timed out" };
12861
12861
  }
12862
- return claudeAuthFromJson(run.stdout, run.code, run.stderrTail);
12862
+ return claudeAuthFromJson(run.stdout, run.code, run.stderrTail, hasApiKeyVariable(deps.env));
12863
12863
  },
12864
12864
  open: ({ conversationUuid, resumeRef, textMaxCharacters }) => new ClaudeCodeSession(conversationUuid, resumeRef, deps.args({ textMaxCharacters, resumeSessionId: resumeRef }), deps)
12865
12865
  };
12866
12866
  }
12867
- function claudeAuthFromJson(stdout, code, stderrTail) {
12867
+ function hasApiKeyVariable(env) {
12868
+ return (env.ANTHROPIC_API_KEY ?? "") !== "";
12869
+ }
12870
+ function claudeAuthFromJson(stdout, code, stderrTail, apiKeyVariable) {
12868
12871
  let parsed;
12869
12872
  try {
12870
12873
  const value = JSON.parse(stdout);
12871
12874
  if (value && typeof value === "object" && !Array.isArray(value)) parsed = value;
12872
12875
  } catch {
12873
12876
  }
12877
+ if (apiKeyVariable) return { ready: true, mode: "apiKey", method: "ANTHROPIC_API_KEY" };
12874
12878
  if (!parsed) {
12875
12879
  return { ready: false, detail: `unreadable auth status (exit ${code ?? "-"})${stderrTail ? `: ${stderrTail}` : ""}` };
12876
12880
  }
12881
+ const ready = parsed.loggedIn === true;
12877
12882
  return {
12878
- ready: parsed.loggedIn === true,
12883
+ ready,
12884
+ ...ready ? { mode: "subscription" } : {},
12879
12885
  method: typeof parsed.authMethod === "string" ? parsed.authMethod : void 0,
12880
12886
  plan: typeof parsed.subscriptionType === "string" ? parsed.subscriptionType : void 0
12881
12887
  };
@@ -12953,6 +12959,8 @@ var ClaudeCodeSession = class {
12953
12959
  }
12954
12960
  if (event.type === "system" && event.subtype === "init" && typeof event.session_id === "string") {
12955
12961
  this.sessionRef = event.session_id;
12962
+ const source = typeof event.apiKeySource === "string" ? event.apiKeySource : "none";
12963
+ this.deps.log.write({ event: "agent_auth_source", pid: this.child.pid, agent: this.agent, apiKeySource: source });
12956
12964
  return;
12957
12965
  }
12958
12966
  const content = event.message?.content;
@@ -13048,9 +13056,9 @@ function codexAuthFromAccount(result) {
13048
13056
  const account = result.account && typeof result.account === "object" ? result.account : void 0;
13049
13057
  const method = typeof account?.type === "string" ? account.type : void 0;
13050
13058
  const plan = typeof account?.planType === "string" ? account.planType : void 0;
13051
- if (account) return { ready: true, method, plan };
13059
+ if (account) return { ready: true, mode: method === "apiKey" ? "apiKey" : "subscription", method, plan };
13052
13060
  if (result.requiresOpenaiAuth === false) return { ready: true, method: "none-required" };
13053
- return { ready: false, detail: "not signed in (run `codex login`)" };
13061
+ return { ready: false, detail: "not signed in with an API key or ChatGPT (run `codex login`, or `codex login --with-api-key`)" };
13054
13062
  }
13055
13063
  function codexTurnResult(turn, lastMessage) {
13056
13064
  const status = typeof turn.status === "string" ? turn.status : "unknown";
@@ -13504,13 +13512,20 @@ async function checkAgents(adapters, log) {
13504
13512
  adapter.id,
13505
13513
  "auth",
13506
13514
  () => adapter.authStatus(),
13507
- (a) => ({ ready: a.ready, method: a.method, plan: a.plan, detail: a.detail })
13515
+ (a) => ({ ready: a.ready, mode: a.mode, method: a.method, plan: a.plan, detail: a.detail })
13508
13516
  );
13509
- return { id: adapter.id, installed: true, version: detected.version, ready: auth?.ready === true, detail: auth?.detail };
13517
+ return {
13518
+ id: adapter.id,
13519
+ installed: true,
13520
+ version: detected.version,
13521
+ ready: auth?.ready === true,
13522
+ auth: auth?.ready === true ? auth.mode : void 0,
13523
+ detail: auth?.detail
13524
+ };
13510
13525
  }));
13511
13526
  }
13512
13527
  function openAgents(checks) {
13513
- return checks.filter((check) => check.installed).map((check) => ({ id: check.id, ready: check.ready }));
13528
+ return checks.filter((check) => check.installed).map((check) => ({ id: check.id, ready: check.ready, ...check.auth ? { auth: check.auth } : {} }));
13514
13529
  }
13515
13530
  async function probe(log, agent, kind, work, summary) {
13516
13531
  const callId = randomUUID3();
@@ -13556,15 +13571,7 @@ function str(value) {
13556
13571
 
13557
13572
  // src/core/agent/reply.ts
13558
13573
  function replyForOutcome(outcome, limits, agentName) {
13559
- const facts = outcome.kind === "result" ? outcome.facts : void 0;
13560
- const documentUuids = facts ? facts.documents.slice(0, limits.documentsMax) : [];
13561
- const createdDocumentUuids = facts ? facts.createdDocuments.filter((uuid) => documentUuids.includes(uuid)) : [];
13562
- const cardUuids = facts ? facts.cards.slice(0, limits.documentsMax) : [];
13563
- const attached = {
13564
- documentUuids,
13565
- ...createdDocumentUuids.length > 0 ? { createdDocumentUuids } : {},
13566
- ...cardUuids.length > 0 ? { cardUuids } : {}
13567
- };
13574
+ const attached = attachedWork(outcome, limits);
13568
13575
  const failed = (errorCode2, text) => ({ status: "FAILED", errorCode: errorCode2, reply: clip(text, limits.textMaxCharacters), ...attached });
13569
13576
  switch (outcome.kind) {
13570
13577
  case "timeout":
@@ -13589,6 +13596,24 @@ ${raw}`);
13589
13596
  }
13590
13597
  }
13591
13598
  }
13599
+ function stoppedReply(outcome, limits) {
13600
+ return {
13601
+ status: "STOPPED",
13602
+ reply: clip("\uC911\uB2E8\uD588\uC5B4\uC694. \uADF8\uB54C\uAE4C\uC9C0 \uD55C \uC77C(\uBB38\uC11C\xB7\uCE74\uB4DC)\uC740 \uB0A8\uC544 \uC788\uC5B4\uC694.", limits.textMaxCharacters),
13603
+ ...outcome ? attachedWork(outcome, limits) : { documentUuids: [] }
13604
+ };
13605
+ }
13606
+ function attachedWork(outcome, limits) {
13607
+ const facts = outcome.kind === "result" ? outcome.facts : void 0;
13608
+ const documentUuids = facts ? facts.documents.slice(0, limits.documentsMax) : [];
13609
+ const createdDocumentUuids = facts ? facts.createdDocuments.filter((uuid) => documentUuids.includes(uuid)) : [];
13610
+ const cardUuids = facts ? facts.cards.slice(0, limits.documentsMax) : [];
13611
+ return {
13612
+ documentUuids,
13613
+ ...createdDocumentUuids.length > 0 ? { createdDocumentUuids } : {},
13614
+ ...cardUuids.length > 0 ? { cardUuids } : {}
13615
+ };
13616
+ }
13592
13617
  function codePoints(text) {
13593
13618
  return Array.from(text).length;
13594
13619
  }
@@ -13598,8 +13623,9 @@ function clip(text, max) {
13598
13623
  }
13599
13624
 
13600
13625
  // src/core/agent/serve.ts
13626
+ var PC_FEATURES = ["stop"];
13601
13627
  async function runAgentServe(deps) {
13602
- const opened = await deps.http.call("open", { hostName: deps.hostName, cliVersion: deps.cliVersion, agents: deps.agents });
13628
+ const opened = await openLink(deps);
13603
13629
  const linkId = String(opened.linkId);
13604
13630
  deps.http.useLinkToken(String(opened.linkToken));
13605
13631
  const limits = serverLimits(opened.limits);
@@ -13612,6 +13638,15 @@ async function runAgentServe(deps) {
13612
13638
  const live = /* @__PURE__ */ new Map();
13613
13639
  const received = /* @__PURE__ */ new Set();
13614
13640
  const queue = [];
13641
+ const stopping = /* @__PURE__ */ new Set();
13642
+ let current;
13643
+ const requestStop = (turnUuid) => {
13644
+ if (stopping.has(turnUuid)) return;
13645
+ stopping.add(turnUuid);
13646
+ const running = current?.turnUuid === turnUuid;
13647
+ deps.log.write({ event: "stop_request", turnUuid, running, queued: queue.some((o) => o.turnUuid === turnUuid) });
13648
+ if (running) void current?.session.interrupt();
13649
+ };
13615
13650
  const stop = (reason, code, message) => {
13616
13651
  if (stopReason) return;
13617
13652
  stopReason = reason;
@@ -13649,6 +13684,7 @@ async function runAgentServe(deps) {
13649
13684
  queue.push(offer);
13650
13685
  wakeWorker?.();
13651
13686
  }
13687
+ for (const turnUuid of stopsIn(res)) requestStop(turnUuid);
13652
13688
  } catch (error) {
13653
13689
  if (stopReason) return;
13654
13690
  if (error instanceof AgentCallError && !error.retryable) {
@@ -13695,6 +13731,10 @@ async function runAgentServe(deps) {
13695
13731
  textLength: offer.text.length
13696
13732
  });
13697
13733
  }
13734
+ if (stopping.has(offer.turnUuid)) {
13735
+ reply = stoppedReply(void 0, limits);
13736
+ return reply;
13737
+ }
13698
13738
  if (!adapter || !session) {
13699
13739
  failure2 = "agent not installed";
13700
13740
  reply = {
@@ -13705,7 +13745,12 @@ async function runAgentServe(deps) {
13705
13745
  };
13706
13746
  return reply;
13707
13747
  }
13708
- outcome = await session.send(agentPromptText(offer.text, offer.context), deps.turnTimeoutMs ?? AGENT_TURN_TIMEOUT_MS);
13748
+ current = { turnUuid: offer.turnUuid, session };
13749
+ try {
13750
+ outcome = await session.send(agentPromptText(offer.text, offer.context), deps.turnTimeoutMs ?? AGENT_TURN_TIMEOUT_MS);
13751
+ } finally {
13752
+ current = void 0;
13753
+ }
13709
13754
  if (outcome.kind === "timeout") {
13710
13755
  await session.interrupt();
13711
13756
  await session.close();
@@ -13716,7 +13761,7 @@ async function runAgentServe(deps) {
13716
13761
  } else if (session.sessionRef) {
13717
13762
  await deps.sessions.set(offer.conversationUuid, adapter.id, session.sessionRef);
13718
13763
  }
13719
- reply = replyForOutcome(outcome, limits, adapter.displayName);
13764
+ reply = stopping.has(offer.turnUuid) ? stoppedReply(outcome, limits) : replyForOutcome(outcome, limits, adapter.displayName);
13720
13765
  return reply;
13721
13766
  } catch (error) {
13722
13767
  failure2 = error instanceof Error ? error.message : String(error);
@@ -13805,6 +13850,19 @@ function serverLimits(value) {
13805
13850
  };
13806
13851
  return { pollHoldSeconds: num("pollHoldSeconds"), textMaxCharacters: num("textMaxCharacters"), documentsMax: num("documentsMax") };
13807
13852
  }
13853
+ async function openLink(deps) {
13854
+ const base = { hostName: deps.hostName, cliVersion: deps.cliVersion, agents: deps.agents };
13855
+ try {
13856
+ return await deps.http.call("open", { ...base, features: [...PC_FEATURES] });
13857
+ } catch (error) {
13858
+ if (!(error instanceof AgentCallError) || error.status !== 400 || error.code !== "INVALID") throw error;
13859
+ deps.log.write({ event: "open_without_features", features: [...PC_FEATURES] });
13860
+ return await deps.http.call("open", base);
13861
+ }
13862
+ }
13863
+ function stopsIn(res) {
13864
+ return Array.isArray(res.stops) ? res.stops.filter((t) => typeof t === "string") : [];
13865
+ }
13808
13866
  function offersIn(res) {
13809
13867
  if (!Array.isArray(res.offers)) return [];
13810
13868
  return res.offers.flatMap((o) => {
@@ -13902,6 +13960,7 @@ var AGENT_HELP_LINES = [
13902
13960
  function isAgentCommand(domain, action) {
13903
13961
  return domain === "agent" && action === "serve";
13904
13962
  }
13963
+ var BILLED_TO = { "claude-code": "Anthropic", codex: "OpenAI" };
13905
13964
  async function executeAgentServe(input) {
13906
13965
  const paths = agentPaths();
13907
13966
  await ensurePrivateDir(paths.dir);
@@ -13942,7 +14001,7 @@ async function executeAgentServe(input) {
13942
14001
  version: CLI_VERSION,
13943
14002
  endpoint: input.endpoint,
13944
14003
  host,
13945
- agents: checks.map(({ id, installed, ready, version }) => ({ id, installed, ready, ...version ? { version } : {} }))
14004
+ agents: checks.map(({ id, installed, ready, auth, version }) => ({ id, installed, ready, ...auth ? { auth } : {}, ...version ? { version } : {} }))
13946
14005
  });
13947
14006
  const agents = openAgents(checks);
13948
14007
  if (agents.length === 0) {
@@ -13950,7 +14009,12 @@ async function executeAgentServe(input) {
13950
14009
  }
13951
14010
  for (const check of checks) {
13952
14011
  const name = all.find((adapter) => adapter.id === check.id)?.displayName ?? check.id;
13953
- if (check.installed && !check.ready) {
14012
+ if (!check.installed) continue;
14013
+ if (check.ready) {
14014
+ input.io.stderr.write(check.auth === "apiKey" ? `${name}: runs on your own API key (billed to your ${BILLED_TO[check.id]} API account; AiNecto credits are not used).
14015
+ ` : `${name}: runs on your subscription login (uses your plan's limits; AiNecto credits are not used).
14016
+ `);
14017
+ } else {
13954
14018
  input.io.stderr.write(`${name} is installed but not signed in${check.detail ? ` (${check.detail})` : ""}. Requests to ${name} will be refused until you sign in and run \`ainecto agent serve\` again.
13955
14019
  `);
13956
14020
  }
@@ -14103,7 +14167,7 @@ async function runAinectoCli(argv, io) {
14103
14167
  });
14104
14168
  }
14105
14169
  if (isAgentCommand(domain, action)) {
14106
- return await executeAgentServe({ endpoint: resolved.endpoint, auth: connect2().auth, io });
14170
+ return await executeAgentServe({ endpoint: resolved.endpoint, env: resolved.env, auth: connect2().auth, io });
14107
14171
  }
14108
14172
  if (domain === "auth") {
14109
14173
  return await handleAuth(action, connect2().auth, resolved.endpoint, parsed.json, io);