@byfriends/agent-core 0.1.0

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.
@@ -0,0 +1,79 @@
1
+ //#region src/agent/records/migration/v1.1.ts
2
+ function isLegacyToolCall(v) {
3
+ if (!isRecord(v)) return false;
4
+ return v["type"] === "function" && typeof v["id"] === "string" && isRecord(v["function"]);
5
+ }
6
+ function migrateToolCall(v) {
7
+ const { function: fn, ...rest } = v;
8
+ return {
9
+ ...rest,
10
+ name: fn.name,
11
+ arguments: fn.arguments
12
+ };
13
+ }
14
+ function isRecord(value) {
15
+ return typeof value === "object" && value !== null && !Array.isArray(value);
16
+ }
17
+ const migrateV1_0ToV1_1 = {
18
+ sourceVersion: "1.0",
19
+ targetVersion: "1.1",
20
+ migrateRecord(record) {
21
+ if (record.type !== "context.append_message") return record;
22
+ const message = record["message"];
23
+ let changed = false;
24
+ const toolCalls = message.toolCalls.map((toolCall) => {
25
+ if (!isLegacyToolCall(toolCall)) return toolCall;
26
+ changed = true;
27
+ return migrateToolCall(toolCall);
28
+ });
29
+ if (!changed) return record;
30
+ return {
31
+ ...record,
32
+ message: {
33
+ ...message,
34
+ toolCalls
35
+ }
36
+ };
37
+ }
38
+ };
39
+ //#endregion
40
+ //#region src/agent/records/migration/index.ts
41
+ const AGENT_WIRE_PROTOCOL_VERSION = "1.1";
42
+ const MIGRATIONS = [migrateV1_0ToV1_1];
43
+ function isNewerWireVersion(readVersion) {
44
+ return compareWireVersions(readVersion, "1.1") > 0;
45
+ }
46
+ function resolveWireMigrations(readVersion) {
47
+ if (compareWireVersions(readVersion, "1.1") >= 0) return [];
48
+ const migrations = [];
49
+ let version = readVersion;
50
+ while (compareWireVersions(version, "1.1") < 0) {
51
+ const migration = findMigration(version);
52
+ if (migration === void 0) throw new Error(`Missing wire migration for version ${version}`);
53
+ migrations.push(migration);
54
+ version = migration.targetVersion;
55
+ }
56
+ return migrations;
57
+ }
58
+ function migrateWireRecord(record, migrations) {
59
+ return migrations.reduce((current, migration) => migration.migrateRecord(current), record);
60
+ }
61
+ function migrateWireRecords(records, readVersion) {
62
+ const migrations = readVersion === void 0 ? MIGRATIONS : resolveWireMigrations(readVersion);
63
+ return records.map((record) => migrateWireRecord(record, migrations));
64
+ }
65
+ function findMigration(sourceVersion) {
66
+ for (const migration of MIGRATIONS) if (migration.sourceVersion === sourceVersion) return migration;
67
+ }
68
+ function compareWireVersions(a, b) {
69
+ const partsA = a.split(".");
70
+ const partsB = b.split(".");
71
+ const maxLength = Math.max(partsA.length, partsB.length);
72
+ for (let i = 0; i < maxLength; i++) {
73
+ const diff = Number(partsA[i] ?? "0") - Number(partsB[i] ?? "0");
74
+ if (diff !== 0) return diff;
75
+ }
76
+ return 0;
77
+ }
78
+ //#endregion
79
+ export { resolveWireMigrations as a, migrateWireRecords as i, isNewerWireVersion as n, migrateWireRecord as r, AGENT_WIRE_PROTOCOL_VERSION as t };
@@ -0,0 +1,42 @@
1
+ import { ct as JsonObject, dt as ListSessionsPayload, wt as SessionSummary } from "../../index-BUBoyyCX.mjs";
2
+
3
+ //#region src/session/store/session-store.d.ts
4
+ interface CreateSessionRecordInput {
5
+ readonly id: string;
6
+ readonly workDir: string;
7
+ }
8
+ interface ForkSessionRecordInput {
9
+ readonly sourceId: string;
10
+ readonly targetId: string;
11
+ readonly title?: string;
12
+ readonly metadata?: JsonObject;
13
+ }
14
+ type SessionStoreOptions = Record<string, never>;
15
+ declare class SessionStore {
16
+ readonly homeDir: string;
17
+ readonly sessionsDir: string;
18
+ constructor(homeDir: string, _options?: SessionStoreOptions);
19
+ sessionDirFor(input: {
20
+ readonly id: string;
21
+ readonly workDir: string;
22
+ }): string;
23
+ create(input: CreateSessionRecordInput): Promise<SessionSummary>;
24
+ fork(input: ForkSessionRecordInput): Promise<SessionSummary>;
25
+ get(id: string): Promise<SessionSummary>;
26
+ rename(id: string, title: string): Promise<void>;
27
+ list(options: ListSessionsPayload): Promise<readonly SessionSummary[]>;
28
+ assertDirectory(id: string): Promise<string>;
29
+ private findSessionEntry;
30
+ private findExistingSessionEntry;
31
+ private writeForkedState;
32
+ private summaryFromDir;
33
+ }
34
+ //#endregion
35
+ //#region src/session/store/session-index.d.ts
36
+ declare function sessionIndexPath(homeDir: string): string;
37
+ //#endregion
38
+ //#region src/session/store/workdir-key.d.ts
39
+ declare function normalizeWorkDir(workDir: string): string;
40
+ declare function encodeWorkDirKey(workDir: string): string;
41
+ //#endregion
42
+ export { type CreateSessionRecordInput, type ForkSessionRecordInput, SessionStore, type SessionStoreOptions, encodeWorkDirKey, normalizeWorkDir, sessionIndexPath };
@@ -0,0 +1,2 @@
1
+ import { i as sessionIndexPath, n as encodeWorkDirKey, r as normalizeWorkDir, t as SessionStore } from "../../store-DhTph1cB.mjs";
2
+ export { SessionStore, encodeWorkDirKey, normalizeWorkDir, sessionIndexPath };