@moxt-ai/mobius 0.0.129 → 0.0.130
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/dist/acp/agent-session.d.ts +0 -4
- package/dist/acp/agent-session.d.ts.map +1 -1
- package/dist/acp/agent-session.js +5 -36
- package/dist/acp/agent-session.js.map +1 -1
- package/dist/acp/{session-state.d.ts → agent-turn.d.ts} +5 -22
- package/dist/acp/agent-turn.d.ts.map +1 -0
- package/dist/acp/agent-turn.js +51 -0
- package/dist/acp/agent-turn.js.map +1 -0
- package/dist/acp/pending-interactions.d.ts +22 -0
- package/dist/acp/pending-interactions.d.ts.map +1 -0
- package/dist/acp/{session-state.js → pending-interactions.js} +1 -23
- package/dist/acp/pending-interactions.js.map +1 -0
- package/dist/acp/session-interactions.d.ts.map +1 -1
- package/dist/acp/session-interactions.js +1 -1
- package/dist/acp/session-interactions.js.map +1 -1
- package/dist/cli.js +374 -376
- package/dist/cli.js.map +4 -4
- package/dist/index.js +479 -481
- package/dist/index.js.map +4 -4
- package/dist/runtime.js +479 -481
- package/dist/runtime.js.map +4 -4
- package/package.json +1 -1
- package/dist/acp/session-state.d.ts.map +0 -1
- package/dist/acp/session-state.js.map +0 -1
package/dist/cli.js
CHANGED
|
@@ -3381,7 +3381,7 @@ var program = new Command();
|
|
|
3381
3381
|
// package.json
|
|
3382
3382
|
var package_default = {
|
|
3383
3383
|
name: "@moxt-ai/mobius",
|
|
3384
|
-
version: "0.0.
|
|
3384
|
+
version: "0.0.130",
|
|
3385
3385
|
description: "Mobius CLI for pairing and running local AI agent services.",
|
|
3386
3386
|
type: "module",
|
|
3387
3387
|
bin: {
|
|
@@ -31642,6 +31642,374 @@ var AgentConnection = class {
|
|
|
31642
31642
|
};
|
|
31643
31643
|
};
|
|
31644
31644
|
|
|
31645
|
+
// src/acp/activity.ts
|
|
31646
|
+
var AcpActivityNarration = class {
|
|
31647
|
+
activityId;
|
|
31648
|
+
activityType;
|
|
31649
|
+
sequence;
|
|
31650
|
+
text;
|
|
31651
|
+
constructor(activityId, activityType, sequence, text2) {
|
|
31652
|
+
this.activityId = activityId;
|
|
31653
|
+
this.activityType = activityType;
|
|
31654
|
+
this.sequence = sequence;
|
|
31655
|
+
this.text = text2;
|
|
31656
|
+
}
|
|
31657
|
+
};
|
|
31658
|
+
var AcpActivity = class _AcpActivity {
|
|
31659
|
+
activityId;
|
|
31660
|
+
activityType;
|
|
31661
|
+
input;
|
|
31662
|
+
locations;
|
|
31663
|
+
name;
|
|
31664
|
+
output;
|
|
31665
|
+
sequence;
|
|
31666
|
+
status;
|
|
31667
|
+
title;
|
|
31668
|
+
toolKind;
|
|
31669
|
+
content;
|
|
31670
|
+
detail;
|
|
31671
|
+
constructor(activityId, activityType, input2, locations, name, output2, sequence, status, title2, toolKind, content = [], detail = captureActivityDetail(content, input2, output2)) {
|
|
31672
|
+
this.activityId = activityId;
|
|
31673
|
+
this.activityType = activityType;
|
|
31674
|
+
this.input = input2;
|
|
31675
|
+
this.locations = locations;
|
|
31676
|
+
this.name = name;
|
|
31677
|
+
this.output = output2;
|
|
31678
|
+
this.sequence = sequence;
|
|
31679
|
+
this.status = status;
|
|
31680
|
+
this.title = title2;
|
|
31681
|
+
this.toolKind = toolKind;
|
|
31682
|
+
this.content = content;
|
|
31683
|
+
this.detail = detail;
|
|
31684
|
+
}
|
|
31685
|
+
complete = () => (this.activityType === "progress" || this.activityType === "reasoning") && (this.status === "pending" || this.status === "running") ? new _AcpActivity(
|
|
31686
|
+
this.activityId,
|
|
31687
|
+
this.activityType,
|
|
31688
|
+
this.input,
|
|
31689
|
+
this.locations,
|
|
31690
|
+
this.name,
|
|
31691
|
+
this.output,
|
|
31692
|
+
this.sequence,
|
|
31693
|
+
"completed",
|
|
31694
|
+
this.title,
|
|
31695
|
+
this.toolKind,
|
|
31696
|
+
this.content,
|
|
31697
|
+
this.detail
|
|
31698
|
+
) : this;
|
|
31699
|
+
};
|
|
31700
|
+
var ActivityIdentity = class {
|
|
31701
|
+
id;
|
|
31702
|
+
sequence;
|
|
31703
|
+
constructor(id, sequence) {
|
|
31704
|
+
this.id = id;
|
|
31705
|
+
this.sequence = sequence;
|
|
31706
|
+
}
|
|
31707
|
+
};
|
|
31708
|
+
var AcpActivityTracker = class {
|
|
31709
|
+
#activities = /* @__PURE__ */ new Map();
|
|
31710
|
+
#identities = /* @__PURE__ */ new Map();
|
|
31711
|
+
#narrations = /* @__PURE__ */ new Map();
|
|
31712
|
+
#onActivity;
|
|
31713
|
+
#onNarration;
|
|
31714
|
+
#prepareContent;
|
|
31715
|
+
#activeNarrativeKey = "";
|
|
31716
|
+
#nextSequence = 0;
|
|
31717
|
+
constructor(onActivity, onNarration, prepareContent = (content) => Promise.resolve(content)) {
|
|
31718
|
+
this.#onActivity = onActivity;
|
|
31719
|
+
this.#onNarration = onNarration;
|
|
31720
|
+
this.#prepareContent = prepareContent;
|
|
31721
|
+
}
|
|
31722
|
+
recordNarrative = async (activityType, messageId, text2) => {
|
|
31723
|
+
const key = `${activityType}:${messageId}`;
|
|
31724
|
+
if (this.#activeNarrativeKey !== key) {
|
|
31725
|
+
await this.finishNarrative();
|
|
31726
|
+
}
|
|
31727
|
+
const identity2 = this.#identity(key);
|
|
31728
|
+
const previous = this.#narrations.get(key);
|
|
31729
|
+
const previousOutput = previous?.output ?? "";
|
|
31730
|
+
const remaining = Math.max(0, AGENT_ACTIVITY_DETAIL_LIMIT - previousOutput.length);
|
|
31731
|
+
this.#narrations.set(key, {
|
|
31732
|
+
activityId: identity2.id,
|
|
31733
|
+
activityType,
|
|
31734
|
+
output: `${previousOutput}${text2.slice(0, remaining)}`,
|
|
31735
|
+
originalBytes: (previous?.originalBytes ?? 0) + new TextEncoder().encode(text2).byteLength,
|
|
31736
|
+
sequence: identity2.sequence,
|
|
31737
|
+
truncated: (previous?.truncated ?? false) || text2.length > remaining
|
|
31738
|
+
});
|
|
31739
|
+
if (previous === void 0) {
|
|
31740
|
+
await this.#record(key, this.#narrativeSnapshot(identity2, activityType, "", "running"));
|
|
31741
|
+
}
|
|
31742
|
+
this.#activeNarrativeKey = key;
|
|
31743
|
+
if (text2.length > 0) {
|
|
31744
|
+
await this.#onNarration(new AcpActivityNarration(identity2.id, activityType, identity2.sequence, text2));
|
|
31745
|
+
}
|
|
31746
|
+
};
|
|
31747
|
+
#narrativeSnapshot = (identity2, activityType, output2, status) => new AcpActivity(
|
|
31748
|
+
identity2.id,
|
|
31749
|
+
activityType,
|
|
31750
|
+
"",
|
|
31751
|
+
[],
|
|
31752
|
+
"",
|
|
31753
|
+
truncate2(output2, AGENT_ACTIVITY_DETAIL_LIMIT),
|
|
31754
|
+
identity2.sequence,
|
|
31755
|
+
status,
|
|
31756
|
+
activityType === "reasoning" ? "Reasoning" : "Progress update",
|
|
31757
|
+
activityType === "reasoning" ? "think" : ""
|
|
31758
|
+
);
|
|
31759
|
+
recordPlan = async (plan) => {
|
|
31760
|
+
await this.finishNarrative();
|
|
31761
|
+
await this.#recordPlanEntries("plan:default", plan.entries);
|
|
31762
|
+
};
|
|
31763
|
+
recordPlanUpdate = async (update) => {
|
|
31764
|
+
await this.finishNarrative();
|
|
31765
|
+
const plan = update.plan;
|
|
31766
|
+
const key = `plan:${plan.planId}`;
|
|
31767
|
+
if (plan.type === "items") {
|
|
31768
|
+
await this.#recordPlanEntries(key, plan.entries);
|
|
31769
|
+
return;
|
|
31770
|
+
}
|
|
31771
|
+
const identity2 = this.#identity(key);
|
|
31772
|
+
const output2 = plan.type === "markdown" ? plan.content : `Plan file: ${plan.uri}`;
|
|
31773
|
+
await this.#record(
|
|
31774
|
+
key,
|
|
31775
|
+
new AcpActivity(
|
|
31776
|
+
identity2.id,
|
|
31777
|
+
"plan",
|
|
31778
|
+
"",
|
|
31779
|
+
[],
|
|
31780
|
+
"",
|
|
31781
|
+
truncate2(output2, AGENT_ACTIVITY_DETAIL_LIMIT),
|
|
31782
|
+
identity2.sequence,
|
|
31783
|
+
"running",
|
|
31784
|
+
"Plan",
|
|
31785
|
+
""
|
|
31786
|
+
)
|
|
31787
|
+
);
|
|
31788
|
+
};
|
|
31789
|
+
removePlan = async (update) => {
|
|
31790
|
+
await this.finishNarrative();
|
|
31791
|
+
const key = `plan:${update.planId}`;
|
|
31792
|
+
const previous = this.#activities.get(key);
|
|
31793
|
+
if (previous !== void 0) {
|
|
31794
|
+
await this.#record(
|
|
31795
|
+
key,
|
|
31796
|
+
new AcpActivity(
|
|
31797
|
+
previous.activityId,
|
|
31798
|
+
previous.activityType,
|
|
31799
|
+
previous.input,
|
|
31800
|
+
previous.locations,
|
|
31801
|
+
previous.name,
|
|
31802
|
+
previous.output,
|
|
31803
|
+
previous.sequence,
|
|
31804
|
+
"completed",
|
|
31805
|
+
previous.title,
|
|
31806
|
+
previous.toolKind,
|
|
31807
|
+
previous.content,
|
|
31808
|
+
previous.detail
|
|
31809
|
+
)
|
|
31810
|
+
);
|
|
31811
|
+
}
|
|
31812
|
+
};
|
|
31813
|
+
recordToolCall = async (update) => {
|
|
31814
|
+
await this.finishNarrative();
|
|
31815
|
+
const key = `tool:${update.toolCallId}`;
|
|
31816
|
+
const identity2 = this.#identity(key);
|
|
31817
|
+
const output2 = update.rawOutput === void 0 ? readContentOutput(update.content) : formatUnknown(update.rawOutput);
|
|
31818
|
+
const detailInput = update.rawInput === void 0 ? "" : formatUnknownDetail(update.rawInput);
|
|
31819
|
+
const detailOutput = update.rawOutput === void 0 ? readContentOutputDetail(update.content) : formatUnknownDetail(update.rawOutput);
|
|
31820
|
+
const detailContent = await normalizeToolContent(
|
|
31821
|
+
toolContent(update.content, update.rawOutput),
|
|
31822
|
+
this.#prepareContent
|
|
31823
|
+
);
|
|
31824
|
+
await this.#record(
|
|
31825
|
+
key,
|
|
31826
|
+
new AcpActivity(
|
|
31827
|
+
identity2.id,
|
|
31828
|
+
"tool",
|
|
31829
|
+
update.rawInput === void 0 ? "" : formatUnknown(update.rawInput),
|
|
31830
|
+
normalizeLocations(update.locations ?? []),
|
|
31831
|
+
truncate2(update.name ?? "", 128),
|
|
31832
|
+
output2,
|
|
31833
|
+
identity2.sequence,
|
|
31834
|
+
normalizeToolStatus(update.status ?? "pending", "pending"),
|
|
31835
|
+
normalizeTitle(update.title, "Tool call"),
|
|
31836
|
+
update.kind ?? "other",
|
|
31837
|
+
detailContent.slice(0, 100).map(summarizeDisplayContent),
|
|
31838
|
+
captureActivityDetail(detailContent, detailInput, detailOutput)
|
|
31839
|
+
)
|
|
31840
|
+
);
|
|
31841
|
+
};
|
|
31842
|
+
recordToolCallUpdate = async (update) => {
|
|
31843
|
+
await this.finishNarrative();
|
|
31844
|
+
const key = `tool:${update.toolCallId}`;
|
|
31845
|
+
const previous = this.#activities.get(key);
|
|
31846
|
+
const identity2 = this.#identity(key);
|
|
31847
|
+
const previousDetail = recordedDetail(previous);
|
|
31848
|
+
const output2 = update.rawOutput !== void 0 ? formatUnknown(update.rawOutput) : update.content !== void 0 && update.content !== null ? readContentOutput(update.content) : previous?.output ?? "";
|
|
31849
|
+
const nextContent = toolContent(update.content, update.rawOutput);
|
|
31850
|
+
const content = nextContent.length === 0 ? previous?.content ?? [] : await normalizeToolContent(nextContent, this.#prepareContent);
|
|
31851
|
+
const detailInput = update.rawInput === void 0 ? previousDetail?.input ?? previous?.input ?? "" : formatUnknownDetail(update.rawInput);
|
|
31852
|
+
const detailOutput = update.rawOutput !== void 0 ? formatUnknownDetail(update.rawOutput) : update.content !== void 0 && update.content !== null ? readContentOutputDetail(update.content) : previousDetail?.output ?? previous?.output ?? "";
|
|
31853
|
+
const detailContent = nextContent.length === 0 ? previousDetail?.content ?? previous?.content ?? [] : content;
|
|
31854
|
+
await this.#record(
|
|
31855
|
+
key,
|
|
31856
|
+
new AcpActivity(
|
|
31857
|
+
identity2.id,
|
|
31858
|
+
"tool",
|
|
31859
|
+
update.rawInput === void 0 ? previous?.input ?? "" : formatUnknown(update.rawInput),
|
|
31860
|
+
update.locations === void 0 || update.locations === null ? previous?.locations ?? [] : normalizeLocations(update.locations),
|
|
31861
|
+
update.name === void 0 || update.name === null ? previous?.name ?? "" : truncate2(update.name, 128),
|
|
31862
|
+
output2,
|
|
31863
|
+
identity2.sequence,
|
|
31864
|
+
update.status === void 0 || update.status === null ? previous?.status ?? "pending" : normalizeToolStatus(update.status, previous?.status ?? "pending"),
|
|
31865
|
+
update.title === void 0 || update.title === null ? previous?.title ?? "Tool call" : normalizeTitle(update.title, "Tool call"),
|
|
31866
|
+
update.kind === void 0 || update.kind === null ? previous?.toolKind ?? "other" : update.kind,
|
|
31867
|
+
content.slice(0, 100).map(summarizeDisplayContent),
|
|
31868
|
+
captureActivityDetail(detailContent, detailInput, detailOutput)
|
|
31869
|
+
)
|
|
31870
|
+
);
|
|
31871
|
+
};
|
|
31872
|
+
finishNarrative = async () => {
|
|
31873
|
+
const key = this.#activeNarrativeKey;
|
|
31874
|
+
if (key.length === 0) {
|
|
31875
|
+
return;
|
|
31876
|
+
}
|
|
31877
|
+
this.#activeNarrativeKey = "";
|
|
31878
|
+
await this.#completeNarrative(key);
|
|
31879
|
+
};
|
|
31880
|
+
finish = async () => {
|
|
31881
|
+
await this.finishNarrative();
|
|
31882
|
+
for (const key of this.#narrations.keys()) {
|
|
31883
|
+
await this.#completeNarrative(key);
|
|
31884
|
+
}
|
|
31885
|
+
const entries = [...this.#activities.entries()].sort((left, right) => left[1].sequence - right[1].sequence);
|
|
31886
|
+
for (const [key, activity2] of entries) {
|
|
31887
|
+
const completed = activity2.complete();
|
|
31888
|
+
if (completed !== activity2) {
|
|
31889
|
+
await this.#record(key, completed);
|
|
31890
|
+
}
|
|
31891
|
+
}
|
|
31892
|
+
};
|
|
31893
|
+
// Materialize a streamed narration as one completed snapshot activity. The
|
|
31894
|
+
// incremental events carried the text; this final event gives consumers the
|
|
31895
|
+
// whole narration with its terminal status, as a single bounded item.
|
|
31896
|
+
#completeNarrative = async (key) => {
|
|
31897
|
+
const narration = this.#narrations.get(key);
|
|
31898
|
+
if (narration === void 0) {
|
|
31899
|
+
return;
|
|
31900
|
+
}
|
|
31901
|
+
this.#narrations.delete(key);
|
|
31902
|
+
const previous = this.#activities.get(key);
|
|
31903
|
+
const detail = narration.truncated ? {
|
|
31904
|
+
capturedBytes: encodedByteLength({ content: [], input: "", output: narration.output }),
|
|
31905
|
+
kind: "truncated",
|
|
31906
|
+
originalBytes: narration.originalBytes
|
|
31907
|
+
} : captureActivityDetail([], "", narration.output);
|
|
31908
|
+
await this.#record(
|
|
31909
|
+
key,
|
|
31910
|
+
new AcpActivity(
|
|
31911
|
+
narration.activityId,
|
|
31912
|
+
narration.activityType,
|
|
31913
|
+
"",
|
|
31914
|
+
[],
|
|
31915
|
+
"",
|
|
31916
|
+
truncate2(narration.output, AGENT_ACTIVITY_DETAIL_LIMIT),
|
|
31917
|
+
narration.sequence,
|
|
31918
|
+
"completed",
|
|
31919
|
+
narration.activityType === "reasoning" ? "Reasoning" : "Progress update",
|
|
31920
|
+
narration.activityType === "reasoning" ? "think" : "",
|
|
31921
|
+
previous?.content ?? [],
|
|
31922
|
+
detail
|
|
31923
|
+
)
|
|
31924
|
+
);
|
|
31925
|
+
};
|
|
31926
|
+
#identity = (key) => {
|
|
31927
|
+
const existing = this.#identities.get(key);
|
|
31928
|
+
if (existing !== void 0) {
|
|
31929
|
+
return existing;
|
|
31930
|
+
}
|
|
31931
|
+
const identity2 = new ActivityIdentity(`activity-${crypto.randomUUID()}`, this.#nextSequence);
|
|
31932
|
+
this.#nextSequence += 1;
|
|
31933
|
+
this.#identities.set(key, identity2);
|
|
31934
|
+
return identity2;
|
|
31935
|
+
};
|
|
31936
|
+
#record = async (key, activity2) => {
|
|
31937
|
+
this.#activities.set(key, activity2);
|
|
31938
|
+
await this.#onActivity(activity2);
|
|
31939
|
+
};
|
|
31940
|
+
#recordPlanEntries = async (key, entries) => {
|
|
31941
|
+
const identity2 = this.#identity(key);
|
|
31942
|
+
await this.#record(
|
|
31943
|
+
key,
|
|
31944
|
+
new AcpActivity(
|
|
31945
|
+
identity2.id,
|
|
31946
|
+
"plan",
|
|
31947
|
+
"",
|
|
31948
|
+
[],
|
|
31949
|
+
"",
|
|
31950
|
+
formatPlanEntries(entries),
|
|
31951
|
+
identity2.sequence,
|
|
31952
|
+
planStatus(entries),
|
|
31953
|
+
"Plan",
|
|
31954
|
+
""
|
|
31955
|
+
)
|
|
31956
|
+
);
|
|
31957
|
+
};
|
|
31958
|
+
};
|
|
31959
|
+
|
|
31960
|
+
// src/acp/agent-turn.ts
|
|
31961
|
+
var SESSION_CONTROL_COMMAND_ID = "session-control";
|
|
31962
|
+
var AcpTurnState = class {
|
|
31963
|
+
#bufferedText = [];
|
|
31964
|
+
bufferText = (text2, messageId) => {
|
|
31965
|
+
const previous = this.#bufferedText.at(-1);
|
|
31966
|
+
if (previous?.messageId === messageId) {
|
|
31967
|
+
previous.chunks.push(text2);
|
|
31968
|
+
} else {
|
|
31969
|
+
this.#bufferedText.push({ chunks: [text2], messageId });
|
|
31970
|
+
}
|
|
31971
|
+
};
|
|
31972
|
+
flushText = async () => {
|
|
31973
|
+
const buffered = this.#bufferedText;
|
|
31974
|
+
this.#bufferedText = [];
|
|
31975
|
+
for (const message of buffered) {
|
|
31976
|
+
for (const chunk of message.chunks) {
|
|
31977
|
+
await this.onText(chunk, message.messageId);
|
|
31978
|
+
}
|
|
31979
|
+
}
|
|
31980
|
+
};
|
|
31981
|
+
recordTextAsProgress = async () => {
|
|
31982
|
+
const buffered = this.#bufferedText;
|
|
31983
|
+
this.#bufferedText = [];
|
|
31984
|
+
for (const message of buffered) {
|
|
31985
|
+
for (const chunk of message.chunks) {
|
|
31986
|
+
await this.activities.recordNarrative("progress", message.messageId, chunk);
|
|
31987
|
+
}
|
|
31988
|
+
}
|
|
31989
|
+
};
|
|
31990
|
+
};
|
|
31991
|
+
var IdleAcpTurn = class extends AcpTurnState {
|
|
31992
|
+
commandId = SESSION_CONTROL_COMMAND_ID;
|
|
31993
|
+
running = false;
|
|
31994
|
+
activities = new AcpActivityTracker(
|
|
31995
|
+
() => Promise.resolve(),
|
|
31996
|
+
() => Promise.resolve()
|
|
31997
|
+
);
|
|
31998
|
+
onText = () => Promise.resolve();
|
|
31999
|
+
};
|
|
32000
|
+
var RunningAcpTurn = class extends AcpTurnState {
|
|
32001
|
+
commandId;
|
|
32002
|
+
running = true;
|
|
32003
|
+
activities;
|
|
32004
|
+
onText;
|
|
32005
|
+
constructor(commandId, onActivity, onNarration, onText, prepareContent) {
|
|
32006
|
+
super();
|
|
32007
|
+
this.commandId = commandId;
|
|
32008
|
+
this.activities = new AcpActivityTracker(onActivity, onNarration ?? (() => Promise.resolve()), prepareContent);
|
|
32009
|
+
this.onText = onText;
|
|
32010
|
+
}
|
|
32011
|
+
};
|
|
32012
|
+
|
|
31645
32013
|
// src/acp/native-session.ts
|
|
31646
32014
|
var path2 = external_exports.string().min(1).max(2048).refine((value) => !value.includes("\0"));
|
|
31647
32015
|
var title = external_exports.string().transform((value) => value.slice(0, 500));
|
|
@@ -31965,321 +32333,6 @@ var AcpAgentSettingsSnapshot = class {
|
|
|
31965
32333
|
}
|
|
31966
32334
|
};
|
|
31967
32335
|
|
|
31968
|
-
// src/acp/activity.ts
|
|
31969
|
-
var AcpActivityNarration = class {
|
|
31970
|
-
activityId;
|
|
31971
|
-
activityType;
|
|
31972
|
-
sequence;
|
|
31973
|
-
text;
|
|
31974
|
-
constructor(activityId, activityType, sequence, text2) {
|
|
31975
|
-
this.activityId = activityId;
|
|
31976
|
-
this.activityType = activityType;
|
|
31977
|
-
this.sequence = sequence;
|
|
31978
|
-
this.text = text2;
|
|
31979
|
-
}
|
|
31980
|
-
};
|
|
31981
|
-
var AcpActivity = class _AcpActivity {
|
|
31982
|
-
activityId;
|
|
31983
|
-
activityType;
|
|
31984
|
-
input;
|
|
31985
|
-
locations;
|
|
31986
|
-
name;
|
|
31987
|
-
output;
|
|
31988
|
-
sequence;
|
|
31989
|
-
status;
|
|
31990
|
-
title;
|
|
31991
|
-
toolKind;
|
|
31992
|
-
content;
|
|
31993
|
-
detail;
|
|
31994
|
-
constructor(activityId, activityType, input2, locations, name, output2, sequence, status, title2, toolKind, content = [], detail = captureActivityDetail(content, input2, output2)) {
|
|
31995
|
-
this.activityId = activityId;
|
|
31996
|
-
this.activityType = activityType;
|
|
31997
|
-
this.input = input2;
|
|
31998
|
-
this.locations = locations;
|
|
31999
|
-
this.name = name;
|
|
32000
|
-
this.output = output2;
|
|
32001
|
-
this.sequence = sequence;
|
|
32002
|
-
this.status = status;
|
|
32003
|
-
this.title = title2;
|
|
32004
|
-
this.toolKind = toolKind;
|
|
32005
|
-
this.content = content;
|
|
32006
|
-
this.detail = detail;
|
|
32007
|
-
}
|
|
32008
|
-
complete = () => (this.activityType === "progress" || this.activityType === "reasoning") && (this.status === "pending" || this.status === "running") ? new _AcpActivity(
|
|
32009
|
-
this.activityId,
|
|
32010
|
-
this.activityType,
|
|
32011
|
-
this.input,
|
|
32012
|
-
this.locations,
|
|
32013
|
-
this.name,
|
|
32014
|
-
this.output,
|
|
32015
|
-
this.sequence,
|
|
32016
|
-
"completed",
|
|
32017
|
-
this.title,
|
|
32018
|
-
this.toolKind,
|
|
32019
|
-
this.content,
|
|
32020
|
-
this.detail
|
|
32021
|
-
) : this;
|
|
32022
|
-
};
|
|
32023
|
-
var ActivityIdentity = class {
|
|
32024
|
-
id;
|
|
32025
|
-
sequence;
|
|
32026
|
-
constructor(id, sequence) {
|
|
32027
|
-
this.id = id;
|
|
32028
|
-
this.sequence = sequence;
|
|
32029
|
-
}
|
|
32030
|
-
};
|
|
32031
|
-
var AcpActivityTracker = class {
|
|
32032
|
-
#activities = /* @__PURE__ */ new Map();
|
|
32033
|
-
#identities = /* @__PURE__ */ new Map();
|
|
32034
|
-
#narrations = /* @__PURE__ */ new Map();
|
|
32035
|
-
#onActivity;
|
|
32036
|
-
#onNarration;
|
|
32037
|
-
#prepareContent;
|
|
32038
|
-
#activeNarrativeKey = "";
|
|
32039
|
-
#nextSequence = 0;
|
|
32040
|
-
constructor(onActivity, onNarration, prepareContent = (content) => Promise.resolve(content)) {
|
|
32041
|
-
this.#onActivity = onActivity;
|
|
32042
|
-
this.#onNarration = onNarration;
|
|
32043
|
-
this.#prepareContent = prepareContent;
|
|
32044
|
-
}
|
|
32045
|
-
recordNarrative = async (activityType, messageId, text2) => {
|
|
32046
|
-
const key = `${activityType}:${messageId}`;
|
|
32047
|
-
if (this.#activeNarrativeKey !== key) {
|
|
32048
|
-
await this.finishNarrative();
|
|
32049
|
-
}
|
|
32050
|
-
const identity2 = this.#identity(key);
|
|
32051
|
-
const previous = this.#narrations.get(key);
|
|
32052
|
-
const previousOutput = previous?.output ?? "";
|
|
32053
|
-
const remaining = Math.max(0, AGENT_ACTIVITY_DETAIL_LIMIT - previousOutput.length);
|
|
32054
|
-
this.#narrations.set(key, {
|
|
32055
|
-
activityId: identity2.id,
|
|
32056
|
-
activityType,
|
|
32057
|
-
output: `${previousOutput}${text2.slice(0, remaining)}`,
|
|
32058
|
-
originalBytes: (previous?.originalBytes ?? 0) + new TextEncoder().encode(text2).byteLength,
|
|
32059
|
-
sequence: identity2.sequence,
|
|
32060
|
-
truncated: (previous?.truncated ?? false) || text2.length > remaining
|
|
32061
|
-
});
|
|
32062
|
-
if (previous === void 0) {
|
|
32063
|
-
await this.#record(key, this.#narrativeSnapshot(identity2, activityType, "", "running"));
|
|
32064
|
-
}
|
|
32065
|
-
this.#activeNarrativeKey = key;
|
|
32066
|
-
if (text2.length > 0) {
|
|
32067
|
-
await this.#onNarration(new AcpActivityNarration(identity2.id, activityType, identity2.sequence, text2));
|
|
32068
|
-
}
|
|
32069
|
-
};
|
|
32070
|
-
#narrativeSnapshot = (identity2, activityType, output2, status) => new AcpActivity(
|
|
32071
|
-
identity2.id,
|
|
32072
|
-
activityType,
|
|
32073
|
-
"",
|
|
32074
|
-
[],
|
|
32075
|
-
"",
|
|
32076
|
-
truncate2(output2, AGENT_ACTIVITY_DETAIL_LIMIT),
|
|
32077
|
-
identity2.sequence,
|
|
32078
|
-
status,
|
|
32079
|
-
activityType === "reasoning" ? "Reasoning" : "Progress update",
|
|
32080
|
-
activityType === "reasoning" ? "think" : ""
|
|
32081
|
-
);
|
|
32082
|
-
recordPlan = async (plan) => {
|
|
32083
|
-
await this.finishNarrative();
|
|
32084
|
-
await this.#recordPlanEntries("plan:default", plan.entries);
|
|
32085
|
-
};
|
|
32086
|
-
recordPlanUpdate = async (update) => {
|
|
32087
|
-
await this.finishNarrative();
|
|
32088
|
-
const plan = update.plan;
|
|
32089
|
-
const key = `plan:${plan.planId}`;
|
|
32090
|
-
if (plan.type === "items") {
|
|
32091
|
-
await this.#recordPlanEntries(key, plan.entries);
|
|
32092
|
-
return;
|
|
32093
|
-
}
|
|
32094
|
-
const identity2 = this.#identity(key);
|
|
32095
|
-
const output2 = plan.type === "markdown" ? plan.content : `Plan file: ${plan.uri}`;
|
|
32096
|
-
await this.#record(
|
|
32097
|
-
key,
|
|
32098
|
-
new AcpActivity(
|
|
32099
|
-
identity2.id,
|
|
32100
|
-
"plan",
|
|
32101
|
-
"",
|
|
32102
|
-
[],
|
|
32103
|
-
"",
|
|
32104
|
-
truncate2(output2, AGENT_ACTIVITY_DETAIL_LIMIT),
|
|
32105
|
-
identity2.sequence,
|
|
32106
|
-
"running",
|
|
32107
|
-
"Plan",
|
|
32108
|
-
""
|
|
32109
|
-
)
|
|
32110
|
-
);
|
|
32111
|
-
};
|
|
32112
|
-
removePlan = async (update) => {
|
|
32113
|
-
await this.finishNarrative();
|
|
32114
|
-
const key = `plan:${update.planId}`;
|
|
32115
|
-
const previous = this.#activities.get(key);
|
|
32116
|
-
if (previous !== void 0) {
|
|
32117
|
-
await this.#record(
|
|
32118
|
-
key,
|
|
32119
|
-
new AcpActivity(
|
|
32120
|
-
previous.activityId,
|
|
32121
|
-
previous.activityType,
|
|
32122
|
-
previous.input,
|
|
32123
|
-
previous.locations,
|
|
32124
|
-
previous.name,
|
|
32125
|
-
previous.output,
|
|
32126
|
-
previous.sequence,
|
|
32127
|
-
"completed",
|
|
32128
|
-
previous.title,
|
|
32129
|
-
previous.toolKind,
|
|
32130
|
-
previous.content,
|
|
32131
|
-
previous.detail
|
|
32132
|
-
)
|
|
32133
|
-
);
|
|
32134
|
-
}
|
|
32135
|
-
};
|
|
32136
|
-
recordToolCall = async (update) => {
|
|
32137
|
-
await this.finishNarrative();
|
|
32138
|
-
const key = `tool:${update.toolCallId}`;
|
|
32139
|
-
const identity2 = this.#identity(key);
|
|
32140
|
-
const output2 = update.rawOutput === void 0 ? readContentOutput(update.content) : formatUnknown(update.rawOutput);
|
|
32141
|
-
const detailInput = update.rawInput === void 0 ? "" : formatUnknownDetail(update.rawInput);
|
|
32142
|
-
const detailOutput = update.rawOutput === void 0 ? readContentOutputDetail(update.content) : formatUnknownDetail(update.rawOutput);
|
|
32143
|
-
const detailContent = await normalizeToolContent(
|
|
32144
|
-
toolContent(update.content, update.rawOutput),
|
|
32145
|
-
this.#prepareContent
|
|
32146
|
-
);
|
|
32147
|
-
await this.#record(
|
|
32148
|
-
key,
|
|
32149
|
-
new AcpActivity(
|
|
32150
|
-
identity2.id,
|
|
32151
|
-
"tool",
|
|
32152
|
-
update.rawInput === void 0 ? "" : formatUnknown(update.rawInput),
|
|
32153
|
-
normalizeLocations(update.locations ?? []),
|
|
32154
|
-
truncate2(update.name ?? "", 128),
|
|
32155
|
-
output2,
|
|
32156
|
-
identity2.sequence,
|
|
32157
|
-
normalizeToolStatus(update.status ?? "pending", "pending"),
|
|
32158
|
-
normalizeTitle(update.title, "Tool call"),
|
|
32159
|
-
update.kind ?? "other",
|
|
32160
|
-
detailContent.slice(0, 100).map(summarizeDisplayContent),
|
|
32161
|
-
captureActivityDetail(detailContent, detailInput, detailOutput)
|
|
32162
|
-
)
|
|
32163
|
-
);
|
|
32164
|
-
};
|
|
32165
|
-
recordToolCallUpdate = async (update) => {
|
|
32166
|
-
await this.finishNarrative();
|
|
32167
|
-
const key = `tool:${update.toolCallId}`;
|
|
32168
|
-
const previous = this.#activities.get(key);
|
|
32169
|
-
const identity2 = this.#identity(key);
|
|
32170
|
-
const previousDetail = recordedDetail(previous);
|
|
32171
|
-
const output2 = update.rawOutput !== void 0 ? formatUnknown(update.rawOutput) : update.content !== void 0 && update.content !== null ? readContentOutput(update.content) : previous?.output ?? "";
|
|
32172
|
-
const nextContent = toolContent(update.content, update.rawOutput);
|
|
32173
|
-
const content = nextContent.length === 0 ? previous?.content ?? [] : await normalizeToolContent(nextContent, this.#prepareContent);
|
|
32174
|
-
const detailInput = update.rawInput === void 0 ? previousDetail?.input ?? previous?.input ?? "" : formatUnknownDetail(update.rawInput);
|
|
32175
|
-
const detailOutput = update.rawOutput !== void 0 ? formatUnknownDetail(update.rawOutput) : update.content !== void 0 && update.content !== null ? readContentOutputDetail(update.content) : previousDetail?.output ?? previous?.output ?? "";
|
|
32176
|
-
const detailContent = nextContent.length === 0 ? previousDetail?.content ?? previous?.content ?? [] : content;
|
|
32177
|
-
await this.#record(
|
|
32178
|
-
key,
|
|
32179
|
-
new AcpActivity(
|
|
32180
|
-
identity2.id,
|
|
32181
|
-
"tool",
|
|
32182
|
-
update.rawInput === void 0 ? previous?.input ?? "" : formatUnknown(update.rawInput),
|
|
32183
|
-
update.locations === void 0 || update.locations === null ? previous?.locations ?? [] : normalizeLocations(update.locations),
|
|
32184
|
-
update.name === void 0 || update.name === null ? previous?.name ?? "" : truncate2(update.name, 128),
|
|
32185
|
-
output2,
|
|
32186
|
-
identity2.sequence,
|
|
32187
|
-
update.status === void 0 || update.status === null ? previous?.status ?? "pending" : normalizeToolStatus(update.status, previous?.status ?? "pending"),
|
|
32188
|
-
update.title === void 0 || update.title === null ? previous?.title ?? "Tool call" : normalizeTitle(update.title, "Tool call"),
|
|
32189
|
-
update.kind === void 0 || update.kind === null ? previous?.toolKind ?? "other" : update.kind,
|
|
32190
|
-
content.slice(0, 100).map(summarizeDisplayContent),
|
|
32191
|
-
captureActivityDetail(detailContent, detailInput, detailOutput)
|
|
32192
|
-
)
|
|
32193
|
-
);
|
|
32194
|
-
};
|
|
32195
|
-
finishNarrative = async () => {
|
|
32196
|
-
const key = this.#activeNarrativeKey;
|
|
32197
|
-
if (key.length === 0) {
|
|
32198
|
-
return;
|
|
32199
|
-
}
|
|
32200
|
-
this.#activeNarrativeKey = "";
|
|
32201
|
-
await this.#completeNarrative(key);
|
|
32202
|
-
};
|
|
32203
|
-
finish = async () => {
|
|
32204
|
-
await this.finishNarrative();
|
|
32205
|
-
for (const key of this.#narrations.keys()) {
|
|
32206
|
-
await this.#completeNarrative(key);
|
|
32207
|
-
}
|
|
32208
|
-
const entries = [...this.#activities.entries()].sort((left, right) => left[1].sequence - right[1].sequence);
|
|
32209
|
-
for (const [key, activity2] of entries) {
|
|
32210
|
-
const completed = activity2.complete();
|
|
32211
|
-
if (completed !== activity2) {
|
|
32212
|
-
await this.#record(key, completed);
|
|
32213
|
-
}
|
|
32214
|
-
}
|
|
32215
|
-
};
|
|
32216
|
-
// Materialize a streamed narration as one completed snapshot activity. The
|
|
32217
|
-
// incremental events carried the text; this final event gives consumers the
|
|
32218
|
-
// whole narration with its terminal status, as a single bounded item.
|
|
32219
|
-
#completeNarrative = async (key) => {
|
|
32220
|
-
const narration = this.#narrations.get(key);
|
|
32221
|
-
if (narration === void 0) {
|
|
32222
|
-
return;
|
|
32223
|
-
}
|
|
32224
|
-
this.#narrations.delete(key);
|
|
32225
|
-
const previous = this.#activities.get(key);
|
|
32226
|
-
const detail = narration.truncated ? {
|
|
32227
|
-
capturedBytes: encodedByteLength({ content: [], input: "", output: narration.output }),
|
|
32228
|
-
kind: "truncated",
|
|
32229
|
-
originalBytes: narration.originalBytes
|
|
32230
|
-
} : captureActivityDetail([], "", narration.output);
|
|
32231
|
-
await this.#record(
|
|
32232
|
-
key,
|
|
32233
|
-
new AcpActivity(
|
|
32234
|
-
narration.activityId,
|
|
32235
|
-
narration.activityType,
|
|
32236
|
-
"",
|
|
32237
|
-
[],
|
|
32238
|
-
"",
|
|
32239
|
-
truncate2(narration.output, AGENT_ACTIVITY_DETAIL_LIMIT),
|
|
32240
|
-
narration.sequence,
|
|
32241
|
-
"completed",
|
|
32242
|
-
narration.activityType === "reasoning" ? "Reasoning" : "Progress update",
|
|
32243
|
-
narration.activityType === "reasoning" ? "think" : "",
|
|
32244
|
-
previous?.content ?? [],
|
|
32245
|
-
detail
|
|
32246
|
-
)
|
|
32247
|
-
);
|
|
32248
|
-
};
|
|
32249
|
-
#identity = (key) => {
|
|
32250
|
-
const existing = this.#identities.get(key);
|
|
32251
|
-
if (existing !== void 0) {
|
|
32252
|
-
return existing;
|
|
32253
|
-
}
|
|
32254
|
-
const identity2 = new ActivityIdentity(`activity-${crypto.randomUUID()}`, this.#nextSequence);
|
|
32255
|
-
this.#nextSequence += 1;
|
|
32256
|
-
this.#identities.set(key, identity2);
|
|
32257
|
-
return identity2;
|
|
32258
|
-
};
|
|
32259
|
-
#record = async (key, activity2) => {
|
|
32260
|
-
this.#activities.set(key, activity2);
|
|
32261
|
-
await this.#onActivity(activity2);
|
|
32262
|
-
};
|
|
32263
|
-
#recordPlanEntries = async (key, entries) => {
|
|
32264
|
-
const identity2 = this.#identity(key);
|
|
32265
|
-
await this.#record(
|
|
32266
|
-
key,
|
|
32267
|
-
new AcpActivity(
|
|
32268
|
-
identity2.id,
|
|
32269
|
-
"plan",
|
|
32270
|
-
"",
|
|
32271
|
-
[],
|
|
32272
|
-
"",
|
|
32273
|
-
formatPlanEntries(entries),
|
|
32274
|
-
identity2.sequence,
|
|
32275
|
-
planStatus(entries),
|
|
32276
|
-
"Plan",
|
|
32277
|
-
""
|
|
32278
|
-
)
|
|
32279
|
-
);
|
|
32280
|
-
};
|
|
32281
|
-
};
|
|
32282
|
-
|
|
32283
32336
|
// src/acp/session-history.ts
|
|
32284
32337
|
var HISTORY_ACTIVITY_FIELD_LIMIT = 1e5;
|
|
32285
32338
|
var HISTORY_ACTIVITY_LIMIT = 100;
|
|
@@ -32712,31 +32765,7 @@ function validateElicitationContent(encoded, requestedSchema) {
|
|
|
32712
32765
|
return validated;
|
|
32713
32766
|
}
|
|
32714
32767
|
|
|
32715
|
-
// src/acp/
|
|
32716
|
-
var SESSION_CONTROL_COMMAND_ID = "session-control";
|
|
32717
|
-
var AcpTurnState = class {
|
|
32718
|
-
};
|
|
32719
|
-
var IdleAcpTurn = class extends AcpTurnState {
|
|
32720
|
-
commandId = SESSION_CONTROL_COMMAND_ID;
|
|
32721
|
-
running = false;
|
|
32722
|
-
activities = new AcpActivityTracker(
|
|
32723
|
-
() => Promise.resolve(),
|
|
32724
|
-
() => Promise.resolve()
|
|
32725
|
-
);
|
|
32726
|
-
onText = () => Promise.resolve();
|
|
32727
|
-
};
|
|
32728
|
-
var RunningAcpTurn = class extends AcpTurnState {
|
|
32729
|
-
commandId;
|
|
32730
|
-
running = true;
|
|
32731
|
-
activities;
|
|
32732
|
-
onText;
|
|
32733
|
-
constructor(commandId, onActivity, onNarration, onText, prepareContent) {
|
|
32734
|
-
super();
|
|
32735
|
-
this.commandId = commandId;
|
|
32736
|
-
this.activities = new AcpActivityTracker(onActivity, onNarration ?? (() => Promise.resolve()), prepareContent);
|
|
32737
|
-
this.onText = onText;
|
|
32738
|
-
}
|
|
32739
|
-
};
|
|
32768
|
+
// src/acp/pending-interactions.ts
|
|
32740
32769
|
var PendingPermission = class {
|
|
32741
32770
|
completion = Promise.withResolvers();
|
|
32742
32771
|
interactionId;
|
|
@@ -38687,7 +38716,6 @@ var AgentSession = class _AgentSession {
|
|
|
38687
38716
|
#verifiedAgentVersion;
|
|
38688
38717
|
#agentName = "";
|
|
38689
38718
|
#agentVersion = "";
|
|
38690
|
-
#bufferedAgentText = [];
|
|
38691
38719
|
#capabilities = unsupportedSessionCapabilities();
|
|
38692
38720
|
#commands = [];
|
|
38693
38721
|
#configRevision = 0;
|
|
@@ -38833,35 +38861,6 @@ var AgentSession = class _AgentSession {
|
|
|
38833
38861
|
this.#replay = { kind: "idle" };
|
|
38834
38862
|
}
|
|
38835
38863
|
};
|
|
38836
|
-
emitAgentMessage = async (chunks, messageId) => {
|
|
38837
|
-
for (const chunk of chunks) {
|
|
38838
|
-
await this.#turn.onText(chunk, messageId);
|
|
38839
|
-
}
|
|
38840
|
-
};
|
|
38841
|
-
bufferAgentText = async (text2, messageId) => {
|
|
38842
|
-
const previous = this.#bufferedAgentText.at(-1);
|
|
38843
|
-
if (previous?.messageId === messageId) {
|
|
38844
|
-
previous.chunks.push(text2);
|
|
38845
|
-
return;
|
|
38846
|
-
}
|
|
38847
|
-
this.#bufferedAgentText.push({ chunks: [text2], messageId });
|
|
38848
|
-
};
|
|
38849
|
-
flushAgentText = async () => {
|
|
38850
|
-
const buffered = this.#bufferedAgentText;
|
|
38851
|
-
this.#bufferedAgentText = [];
|
|
38852
|
-
for (const message of buffered) {
|
|
38853
|
-
await this.emitAgentMessage(message.chunks, message.messageId);
|
|
38854
|
-
}
|
|
38855
|
-
};
|
|
38856
|
-
recordBufferedAgentTextAsProgress = async () => {
|
|
38857
|
-
const buffered = this.#bufferedAgentText;
|
|
38858
|
-
this.#bufferedAgentText = [];
|
|
38859
|
-
for (const message of buffered) {
|
|
38860
|
-
for (const chunk of message.chunks) {
|
|
38861
|
-
await this.#turn.activities.recordNarrative("progress", message.messageId, chunk);
|
|
38862
|
-
}
|
|
38863
|
-
}
|
|
38864
|
-
};
|
|
38865
38864
|
prepareAgentContent = async (content) => {
|
|
38866
38865
|
if (content.type === "image" && content.uri.length > 0) {
|
|
38867
38866
|
const signal = AbortSignal.timeout(2e4);
|
|
@@ -39359,7 +39358,7 @@ var AgentSession = class _AgentSession {
|
|
|
39359
39358
|
options.signal
|
|
39360
39359
|
);
|
|
39361
39360
|
await this.#updates.drained();
|
|
39362
|
-
await this.
|
|
39361
|
+
await this.#turn.flushText();
|
|
39363
39362
|
await running.activities.finish();
|
|
39364
39363
|
let result;
|
|
39365
39364
|
try {
|
|
@@ -39391,7 +39390,6 @@ var AgentSession = class _AgentSession {
|
|
|
39391
39390
|
cause: error62
|
|
39392
39391
|
});
|
|
39393
39392
|
} finally {
|
|
39394
|
-
this.#bufferedAgentText = [];
|
|
39395
39393
|
this.#turn = new IdleAcpTurn();
|
|
39396
39394
|
}
|
|
39397
39395
|
};
|
|
@@ -39482,11 +39480,11 @@ var AgentSession = class _AgentSession {
|
|
|
39482
39480
|
);
|
|
39483
39481
|
} else {
|
|
39484
39482
|
await this.#turn.activities.finishNarrative();
|
|
39485
|
-
|
|
39483
|
+
this.#turn.bufferText(update.content.text, truncate3(update.messageId ?? "", 255));
|
|
39486
39484
|
}
|
|
39487
39485
|
} else {
|
|
39488
39486
|
await this.#turn.activities.finishNarrative();
|
|
39489
|
-
await this.
|
|
39487
|
+
await this.#turn.flushText();
|
|
39490
39488
|
await this.emitAgentContent(
|
|
39491
39489
|
normalizeContentBlock(update.content),
|
|
39492
39490
|
truncate3(update.messageId ?? "", 255)
|
|
@@ -39505,7 +39503,7 @@ var AgentSession = class _AgentSession {
|
|
|
39505
39503
|
return;
|
|
39506
39504
|
}
|
|
39507
39505
|
if (update.sessionUpdate === "tool_call") {
|
|
39508
|
-
await this.
|
|
39506
|
+
await this.#turn.recordTextAsProgress();
|
|
39509
39507
|
await this.#turn.activities.recordToolCall(update);
|
|
39510
39508
|
return;
|
|
39511
39509
|
}
|