ainecto 0.14.0-next.3 → 0.14.0-next.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.
@@ -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.3" : UNBUNDLED_VERSION;
5681
+ var CLI_VERSION = true ? "0.14.0-next.5" : 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) {
@@ -13560,6 +13560,10 @@ function agentPromptText(text, context) {
13560
13560
  if (d && typeof d.uuid === "string") {
13561
13561
  parts.push(`open document \xAB${str(d.title)}\xBB (documentUuid ${d.uuid}${typeof d.type === "string" ? `, ${d.type}` : ""})`);
13562
13562
  }
13563
+ const files = Array.isArray(context?.attachments) ? context.attachments.map((f) => str(f?.filename)).filter((name) => name !== "") : [];
13564
+ if (files.length > 0) {
13565
+ parts.push(`attached files ${files.map((name) => `\xAB${name}\xBB`).join(", ")} (names only \u2014 the files are not available on this machine)`);
13566
+ }
13563
13567
  if (parts.length === 0) return text;
13564
13568
  return `[AiNecto context \u2014 "this project" / "this document" mean these] ${parts.join(" \xB7 ")}
13565
13569
 
@@ -13571,15 +13575,7 @@ function str(value) {
13571
13575
 
13572
13576
  // src/core/agent/reply.ts
13573
13577
  function replyForOutcome(outcome, limits, agentName) {
13574
- const facts = outcome.kind === "result" ? outcome.facts : void 0;
13575
- const documentUuids = facts ? facts.documents.slice(0, limits.documentsMax) : [];
13576
- const createdDocumentUuids = facts ? facts.createdDocuments.filter((uuid) => documentUuids.includes(uuid)) : [];
13577
- const cardUuids = facts ? facts.cards.slice(0, limits.documentsMax) : [];
13578
- const attached = {
13579
- documentUuids,
13580
- ...createdDocumentUuids.length > 0 ? { createdDocumentUuids } : {},
13581
- ...cardUuids.length > 0 ? { cardUuids } : {}
13582
- };
13578
+ const attached = attachedWork(outcome, limits);
13583
13579
  const failed = (errorCode2, text) => ({ status: "FAILED", errorCode: errorCode2, reply: clip(text, limits.textMaxCharacters), ...attached });
13584
13580
  switch (outcome.kind) {
13585
13581
  case "timeout":
@@ -13604,6 +13600,24 @@ ${raw}`);
13604
13600
  }
13605
13601
  }
13606
13602
  }
13603
+ function stoppedReply(outcome, limits) {
13604
+ return {
13605
+ status: "STOPPED",
13606
+ 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),
13607
+ ...outcome ? attachedWork(outcome, limits) : { documentUuids: [] }
13608
+ };
13609
+ }
13610
+ function attachedWork(outcome, limits) {
13611
+ const facts = outcome.kind === "result" ? outcome.facts : void 0;
13612
+ const documentUuids = facts ? facts.documents.slice(0, limits.documentsMax) : [];
13613
+ const createdDocumentUuids = facts ? facts.createdDocuments.filter((uuid) => documentUuids.includes(uuid)) : [];
13614
+ const cardUuids = facts ? facts.cards.slice(0, limits.documentsMax) : [];
13615
+ return {
13616
+ documentUuids,
13617
+ ...createdDocumentUuids.length > 0 ? { createdDocumentUuids } : {},
13618
+ ...cardUuids.length > 0 ? { cardUuids } : {}
13619
+ };
13620
+ }
13607
13621
  function codePoints(text) {
13608
13622
  return Array.from(text).length;
13609
13623
  }
@@ -13613,8 +13627,9 @@ function clip(text, max) {
13613
13627
  }
13614
13628
 
13615
13629
  // src/core/agent/serve.ts
13630
+ var PC_FEATURES = ["stop"];
13616
13631
  async function runAgentServe(deps) {
13617
- const opened = await deps.http.call("open", { hostName: deps.hostName, cliVersion: deps.cliVersion, agents: deps.agents });
13632
+ const opened = await openLink(deps);
13618
13633
  const linkId = String(opened.linkId);
13619
13634
  deps.http.useLinkToken(String(opened.linkToken));
13620
13635
  const limits = serverLimits(opened.limits);
@@ -13627,6 +13642,15 @@ async function runAgentServe(deps) {
13627
13642
  const live = /* @__PURE__ */ new Map();
13628
13643
  const received = /* @__PURE__ */ new Set();
13629
13644
  const queue = [];
13645
+ const stopping = /* @__PURE__ */ new Set();
13646
+ let current;
13647
+ const requestStop = (turnUuid) => {
13648
+ if (stopping.has(turnUuid)) return;
13649
+ stopping.add(turnUuid);
13650
+ const running = current?.turnUuid === turnUuid;
13651
+ deps.log.write({ event: "stop_request", turnUuid, running, queued: queue.some((o) => o.turnUuid === turnUuid) });
13652
+ if (running) void current?.session.interrupt();
13653
+ };
13630
13654
  const stop = (reason, code, message) => {
13631
13655
  if (stopReason) return;
13632
13656
  stopReason = reason;
@@ -13664,6 +13688,7 @@ async function runAgentServe(deps) {
13664
13688
  queue.push(offer);
13665
13689
  wakeWorker?.();
13666
13690
  }
13691
+ for (const turnUuid of stopsIn(res)) requestStop(turnUuid);
13667
13692
  } catch (error) {
13668
13693
  if (stopReason) return;
13669
13694
  if (error instanceof AgentCallError && !error.retryable) {
@@ -13710,6 +13735,10 @@ async function runAgentServe(deps) {
13710
13735
  textLength: offer.text.length
13711
13736
  });
13712
13737
  }
13738
+ if (stopping.has(offer.turnUuid)) {
13739
+ reply = stoppedReply(void 0, limits);
13740
+ return reply;
13741
+ }
13713
13742
  if (!adapter || !session) {
13714
13743
  failure2 = "agent not installed";
13715
13744
  reply = {
@@ -13720,7 +13749,12 @@ async function runAgentServe(deps) {
13720
13749
  };
13721
13750
  return reply;
13722
13751
  }
13723
- outcome = await session.send(agentPromptText(offer.text, offer.context), deps.turnTimeoutMs ?? AGENT_TURN_TIMEOUT_MS);
13752
+ current = { turnUuid: offer.turnUuid, session };
13753
+ try {
13754
+ outcome = await session.send(agentPromptText(offer.text, offer.context), deps.turnTimeoutMs ?? AGENT_TURN_TIMEOUT_MS);
13755
+ } finally {
13756
+ current = void 0;
13757
+ }
13724
13758
  if (outcome.kind === "timeout") {
13725
13759
  await session.interrupt();
13726
13760
  await session.close();
@@ -13731,7 +13765,7 @@ async function runAgentServe(deps) {
13731
13765
  } else if (session.sessionRef) {
13732
13766
  await deps.sessions.set(offer.conversationUuid, adapter.id, session.sessionRef);
13733
13767
  }
13734
- reply = replyForOutcome(outcome, limits, adapter.displayName);
13768
+ reply = stopping.has(offer.turnUuid) ? stoppedReply(outcome, limits) : replyForOutcome(outcome, limits, adapter.displayName);
13735
13769
  return reply;
13736
13770
  } catch (error) {
13737
13771
  failure2 = error instanceof Error ? error.message : String(error);
@@ -13820,6 +13854,19 @@ function serverLimits(value) {
13820
13854
  };
13821
13855
  return { pollHoldSeconds: num("pollHoldSeconds"), textMaxCharacters: num("textMaxCharacters"), documentsMax: num("documentsMax") };
13822
13856
  }
13857
+ async function openLink(deps) {
13858
+ const base = { hostName: deps.hostName, cliVersion: deps.cliVersion, agents: deps.agents };
13859
+ try {
13860
+ return await deps.http.call("open", { ...base, features: [...PC_FEATURES] });
13861
+ } catch (error) {
13862
+ if (!(error instanceof AgentCallError) || error.status !== 400 || error.code !== "INVALID") throw error;
13863
+ deps.log.write({ event: "open_without_features", features: [...PC_FEATURES] });
13864
+ return await deps.http.call("open", base);
13865
+ }
13866
+ }
13867
+ function stopsIn(res) {
13868
+ return Array.isArray(res.stops) ? res.stops.filter((t) => typeof t === "string") : [];
13869
+ }
13823
13870
  function offersIn(res) {
13824
13871
  if (!Array.isArray(res.offers)) return [];
13825
13872
  return res.offers.flatMap((o) => {
@@ -13968,8 +14015,8 @@ async function executeAgentServe(input) {
13968
14015
  const name = all.find((adapter) => adapter.id === check.id)?.displayName ?? check.id;
13969
14016
  if (!check.installed) continue;
13970
14017
  if (check.ready) {
13971
- input.io.stderr.write(check.auth === "apiKey" ? `${name}: runs on your own API key (billed to your ${BILLED_TO[check.id]} API account).
13972
- ` : `${name}: runs on your subscription login (uses your plan's limits).
14018
+ 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).
14019
+ ` : `${name}: runs on your subscription login (uses your plan's limits; AiNecto credits are not used).
13973
14020
  `);
13974
14021
  } else {
13975
14022
  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.