@covia/covia-sdk 1.24.0 → 1.24.1
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/index.d.mts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +33 -2
- package/dist/index.mjs +33 -2
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -1886,9 +1886,9 @@ interface AgentSessionMessage {
|
|
|
1886
1886
|
tokens?: number;
|
|
1887
1887
|
}
|
|
1888
1888
|
/**
|
|
1889
|
-
*
|
|
1889
|
+
* A legacy archived run of turns that compaction replaced with a summary
|
|
1890
1890
|
* (AGENT_CONTEXT.md §1.1 `CompactedSegment`). `items` is the exact recursively
|
|
1891
|
-
* archived vector, so no history is lost — {@link AgentSession.conversation}
|
|
1891
|
+
* archived vector (new frame histories use backward historyRange references), so no history is lost — {@link AgentSession.conversation}
|
|
1892
1892
|
* expands it back into the transcript.
|
|
1893
1893
|
*/
|
|
1894
1894
|
interface AgentCompactedSegment {
|
package/dist/index.d.ts
CHANGED
|
@@ -1886,9 +1886,9 @@ interface AgentSessionMessage {
|
|
|
1886
1886
|
tokens?: number;
|
|
1887
1887
|
}
|
|
1888
1888
|
/**
|
|
1889
|
-
*
|
|
1889
|
+
* A legacy archived run of turns that compaction replaced with a summary
|
|
1890
1890
|
* (AGENT_CONTEXT.md §1.1 `CompactedSegment`). `items` is the exact recursively
|
|
1891
|
-
* archived vector, so no history is lost — {@link AgentSession.conversation}
|
|
1891
|
+
* archived vector (new frame histories use backward historyRange references), so no history is lost — {@link AgentSession.conversation}
|
|
1892
1892
|
* expands it back into the transcript.
|
|
1893
1893
|
*/
|
|
1894
1894
|
interface AgentCompactedSegment {
|
package/dist/index.js
CHANGED
|
@@ -1931,11 +1931,42 @@ function collectTurns(entries, out, depth = 0) {
|
|
|
1931
1931
|
}
|
|
1932
1932
|
}
|
|
1933
1933
|
}
|
|
1934
|
+
function collectHistory(frame, out) {
|
|
1935
|
+
const history = frame.history;
|
|
1936
|
+
const start = frame.contextStart;
|
|
1937
|
+
if (frame.historyVersion !== void 0 && frame.historyVersion !== 1 || "conversation" in frame || !Array.isArray(history) || !Number.isSafeInteger(start) || start < 0 || start > history.length) {
|
|
1938
|
+
throw new Error("Invalid or unsupported agent frame history");
|
|
1939
|
+
}
|
|
1940
|
+
const pending = [[start, history.length]];
|
|
1941
|
+
const visited = /* @__PURE__ */ new Set();
|
|
1942
|
+
while (pending.length) {
|
|
1943
|
+
const [from, end] = pending.pop();
|
|
1944
|
+
for (let i = from; i < end; i++) {
|
|
1945
|
+
if (visited.has(i)) continue;
|
|
1946
|
+
visited.add(i);
|
|
1947
|
+
const entry = record(history[i]);
|
|
1948
|
+
if (!entry) continue;
|
|
1949
|
+
if ("historyRange" in entry) {
|
|
1950
|
+
const range = entry.historyRange;
|
|
1951
|
+
if (typeof entry.summary !== "string" || "items" in entry || !Number.isSafeInteger(entry.turns) || entry.turns < 0 || !Array.isArray(range) || range.length !== 2 || !range.every(Number.isSafeInteger) || range[0] < 0 || range[1] < range[0] || range[1] > i) {
|
|
1952
|
+
throw new Error("Invalid agent summary historyRange");
|
|
1953
|
+
}
|
|
1954
|
+
pending.push([i + 1, end], [range[0], range[1]]);
|
|
1955
|
+
break;
|
|
1956
|
+
}
|
|
1957
|
+
collectTurns([entry], out);
|
|
1958
|
+
}
|
|
1959
|
+
}
|
|
1960
|
+
}
|
|
1934
1961
|
function sessionConversation(frames) {
|
|
1935
1962
|
const turns = [];
|
|
1936
1963
|
for (const frame of frames) {
|
|
1937
|
-
const
|
|
1938
|
-
if (
|
|
1964
|
+
const value = record(frame);
|
|
1965
|
+
if (!value) continue;
|
|
1966
|
+
if ("history" in value) collectHistory(value, turns);
|
|
1967
|
+
else if ("historyVersion" in value || "contextStart" in value) {
|
|
1968
|
+
throw new Error("Invalid or unsupported agent frame history");
|
|
1969
|
+
} else if (Array.isArray(value.conversation)) collectTurns(value.conversation, turns);
|
|
1939
1970
|
}
|
|
1940
1971
|
return turns;
|
|
1941
1972
|
}
|
package/dist/index.mjs
CHANGED
|
@@ -1929,11 +1929,42 @@ function collectTurns(entries, out, depth = 0) {
|
|
|
1929
1929
|
}
|
|
1930
1930
|
}
|
|
1931
1931
|
}
|
|
1932
|
+
function collectHistory(frame, out) {
|
|
1933
|
+
const history = frame.history;
|
|
1934
|
+
const start = frame.contextStart;
|
|
1935
|
+
if (frame.historyVersion !== void 0 && frame.historyVersion !== 1 || "conversation" in frame || !Array.isArray(history) || !Number.isSafeInteger(start) || start < 0 || start > history.length) {
|
|
1936
|
+
throw new Error("Invalid or unsupported agent frame history");
|
|
1937
|
+
}
|
|
1938
|
+
const pending = [[start, history.length]];
|
|
1939
|
+
const visited = /* @__PURE__ */ new Set();
|
|
1940
|
+
while (pending.length) {
|
|
1941
|
+
const [from, end] = pending.pop();
|
|
1942
|
+
for (let i = from; i < end; i++) {
|
|
1943
|
+
if (visited.has(i)) continue;
|
|
1944
|
+
visited.add(i);
|
|
1945
|
+
const entry = record(history[i]);
|
|
1946
|
+
if (!entry) continue;
|
|
1947
|
+
if ("historyRange" in entry) {
|
|
1948
|
+
const range = entry.historyRange;
|
|
1949
|
+
if (typeof entry.summary !== "string" || "items" in entry || !Number.isSafeInteger(entry.turns) || entry.turns < 0 || !Array.isArray(range) || range.length !== 2 || !range.every(Number.isSafeInteger) || range[0] < 0 || range[1] < range[0] || range[1] > i) {
|
|
1950
|
+
throw new Error("Invalid agent summary historyRange");
|
|
1951
|
+
}
|
|
1952
|
+
pending.push([i + 1, end], [range[0], range[1]]);
|
|
1953
|
+
break;
|
|
1954
|
+
}
|
|
1955
|
+
collectTurns([entry], out);
|
|
1956
|
+
}
|
|
1957
|
+
}
|
|
1958
|
+
}
|
|
1932
1959
|
function sessionConversation(frames) {
|
|
1933
1960
|
const turns = [];
|
|
1934
1961
|
for (const frame of frames) {
|
|
1935
|
-
const
|
|
1936
|
-
if (
|
|
1962
|
+
const value = record(frame);
|
|
1963
|
+
if (!value) continue;
|
|
1964
|
+
if ("history" in value) collectHistory(value, turns);
|
|
1965
|
+
else if ("historyVersion" in value || "contextStart" in value) {
|
|
1966
|
+
throw new Error("Invalid or unsupported agent frame history");
|
|
1967
|
+
} else if (Array.isArray(value.conversation)) collectTurns(value.conversation, turns);
|
|
1937
1968
|
}
|
|
1938
1969
|
return turns;
|
|
1939
1970
|
}
|