@statelyai/agent 2.0.0-alpha.22 → 2.0.0-alpha.24

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.
Files changed (48) hide show
  1. package/dist/ai-sdk.cjs +53 -25
  2. package/dist/ai-sdk.d.cts +20 -12
  3. package/dist/ai-sdk.d.mts +20 -12
  4. package/dist/ai-sdk.mjs +53 -25
  5. package/dist/{decision-DxSTqzgZ.mjs → decision-BBZ2jMO1.mjs} +444 -79
  6. package/dist/{decision-1o45_ZrS.cjs → decision-Cv6SfNWl.cjs} +525 -94
  7. package/dist/index.cjs +2224 -1032
  8. package/dist/index.d.cts +413 -275
  9. package/dist/index.d.mts +413 -275
  10. package/dist/index.mjs +2163 -983
  11. package/dist/machines.cjs +30 -2
  12. package/dist/machines.d.cts +1 -1
  13. package/dist/machines.d.mts +1 -1
  14. package/dist/machines.mjs +30 -2
  15. package/dist/openai.cjs +447 -0
  16. package/dist/openai.d.cts +177 -0
  17. package/dist/openai.d.mts +177 -0
  18. package/dist/openai.mjs +437 -0
  19. package/dist/otel.cjs +3 -6
  20. package/dist/otel.d.cts +1 -1
  21. package/dist/otel.d.mts +1 -1
  22. package/dist/otel.mjs +3 -6
  23. package/dist/run-agent-Ck7Sa3Tb.d.mts +968 -0
  24. package/dist/run-agent-DWqA8KiI.d.cts +968 -0
  25. package/dist/setup-agent-CeO2fARv.mjs +639 -0
  26. package/dist/setup-agent-Dl2VELLi.cjs +663 -0
  27. package/dist/{text-logic-BaxPrcLk.d.cts → text-logic-C7bSnH_B.d.cts} +195 -44
  28. package/dist/{text-logic-DhfFWzu9.d.mts → text-logic-DJBK3LbG.d.mts} +195 -44
  29. package/dist/{types-DSdj2tGs.d.cts → types-CjHk5OdH.d.cts} +4 -19
  30. package/dist/{types-CvWRGFxP.d.mts → types-DWA6X9R-.d.mts} +4 -19
  31. package/package.json +17 -21
  32. package/readme.md +32 -17
  33. package/dist/errors-BQRk9eiZ.d.cts +0 -19
  34. package/dist/errors-C9rxnWbX.d.mts +0 -19
  35. package/dist/errors-CeSXQx0v.mjs +0 -23
  36. package/dist/errors-DUBBzRLP.cjs +0 -28
  37. package/dist/event-log-store-Bz7HDBkE.d.cts +0 -145
  38. package/dist/event-log-store-DmIDosD6.mjs +0 -427
  39. package/dist/event-log-store-a_TKy1gk.cjs +0 -468
  40. package/dist/event-log-store-hrA1vqtN.d.mts +0 -145
  41. package/dist/run-agent-0fpEZ1wJ.d.mts +0 -1098
  42. package/dist/run-agent-Zbkx7XP8.d.cts +0 -1098
  43. package/dist/setup-agent-DkCTy5Eu.cjs +0 -1707
  44. package/dist/setup-agent-nSFYrNTP.mjs +0 -1587
  45. package/dist/sqlite.cjs +0 -129
  46. package/dist/sqlite.d.cts +0 -57
  47. package/dist/sqlite.d.mts +0 -57
  48. package/dist/sqlite.mjs +0 -127
package/dist/sqlite.cjs DELETED
@@ -1,129 +0,0 @@
1
- Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_event_log_store = require("./event-log-store-a_TKy1gk.cjs");
3
- //#region src/sqlite/index.ts
4
- function openDatabase(path) {
5
- const sqlite = process.getBuiltinModule?.("node:sqlite");
6
- if (!sqlite?.DatabaseSync) throw new Error("createSqlite*Store: 'node:sqlite' is unavailable in this runtime; Node >= 22.18 is required.");
7
- return new sqlite.DatabaseSync(path);
8
- }
9
- function quoteIdentifier(name) {
10
- if (!/^[A-Za-z_][A-Za-z0-9_]*$/.test(name)) throw new Error(`Invalid SQLite table name '${name}': use letters, digits, and underscores only.`);
11
- return `"${name}"`;
12
- }
13
- function resolveDatabase(database) {
14
- return typeof database === "string" ? {
15
- db: openDatabase(database),
16
- owned: true
17
- } : {
18
- db: database,
19
- owned: false
20
- };
21
- }
22
- /**
23
- * An {@link AgentEventLogStore} on one SQLite table, keyed by
24
- * `(thread_id, idx)` with a unique `(thread_id, entry_id)` index. Entries are
25
- * stored as JSON text, so reads and writes are deep copies by construction.
26
- * `append` runs its length check and inserts inside one `BEGIN IMMEDIATE`
27
- * transaction: `node:sqlite` is synchronous, so no `await` interleaves between
28
- * the check and the write and racing appends resolve to exactly one winner.
29
- */
30
- function createSqliteEventLogStore(options) {
31
- const { db, owned } = resolveDatabase(options.database);
32
- const table = quoteIdentifier(options.tableName ?? "agent_event_log");
33
- db.exec(`
34
- CREATE TABLE IF NOT EXISTS ${table} (
35
- thread_id TEXT NOT NULL,
36
- idx INTEGER NOT NULL,
37
- entry_id TEXT NOT NULL,
38
- entry TEXT NOT NULL,
39
- PRIMARY KEY (thread_id, idx)
40
- );
41
- CREATE UNIQUE INDEX IF NOT EXISTS ${quoteIdentifier(`${options.tableName ?? "agent_event_log"}_thread_entry_id`)} ON ${table} (thread_id, entry_id);
42
- `);
43
- const lengthOf = (threadId) => {
44
- const row = db.prepare(`SELECT COUNT(*) AS n FROM ${table} WHERE thread_id = ?`).get(threadId);
45
- return Number(row?.n ?? 0);
46
- };
47
- const transact = (fn) => {
48
- db.exec("BEGIN IMMEDIATE");
49
- try {
50
- const result = fn();
51
- db.exec("COMMIT");
52
- return result;
53
- } catch (error) {
54
- try {
55
- db.exec("ROLLBACK");
56
- } catch {}
57
- throw error;
58
- }
59
- };
60
- return {
61
- async append({ threadId, expectedIndex, entries }) {
62
- for (const entry of entries) require_event_log_store.assertAgentLogEntry(entry);
63
- for (let i = 0; i < entries.length; i++) if (entries[i].index !== expectedIndex + i) throw new Error(`AgentEventLogStore.append: entry.index (${entries[i].index}) must be contiguous from expectedIndex (${expectedIndex}); expected ${expectedIndex + i} at position ${i} on thread "${threadId}".`);
64
- transact(() => {
65
- const length = lengthOf(threadId);
66
- if (length !== expectedIndex) throw new require_event_log_store.AgentEventLogConflictError(threadId, expectedIndex, length);
67
- const insert = db.prepare(`INSERT INTO ${table} (thread_id, idx, entry_id, entry) VALUES (?, ?, ?, ?)`);
68
- for (const entry of entries) try {
69
- insert.run(threadId, entry.index, entry.id, JSON.stringify(entry));
70
- } catch (error) {
71
- if (String(error.message).includes("UNIQUE")) throw new Error(`AgentEventLogStore.append: duplicate event id "${entry.id}" in thread "${threadId}".`);
72
- throw error;
73
- }
74
- });
75
- },
76
- async read(threadId, options) {
77
- const from = options?.from ?? 0;
78
- return db.prepare(`SELECT entry FROM ${table} WHERE thread_id = ? AND idx >= ? ORDER BY idx ASC`).all(threadId, from).map((row) => JSON.parse(row.entry));
79
- },
80
- async length(threadId) {
81
- return lengthOf(threadId);
82
- },
83
- async fork({ threadId, newThreadId, upToIndex }) {
84
- transact(() => {
85
- if (lengthOf(newThreadId) > 0) throw new Error(`AgentEventLogStore.fork: newThreadId "${newThreadId}" already has entries.`);
86
- const sourceLength = lengthOf(threadId);
87
- if (sourceLength === 0) throw new Error(`AgentEventLogStore.fork: unknown source thread "${threadId}".`);
88
- const upTo = upToIndex ?? sourceLength;
89
- if (upTo < 0 || upTo > sourceLength) throw new Error(`AgentEventLogStore.fork: thread "${threadId}" (length ${sourceLength}) has no index ${upTo} to fork up to.`);
90
- db.prepare(`INSERT INTO ${table} (thread_id, idx, entry_id, entry)
91
- SELECT ?, idx, entry_id, entry FROM ${table} WHERE thread_id = ? AND idx < ?`).run(newThreadId, threadId, upTo);
92
- });
93
- },
94
- close() {
95
- if (owned) db.close();
96
- }
97
- };
98
- }
99
- /**
100
- * An {@link AgentSnapshotStore} on one SQLite table: a `key -> JSON` upsert.
101
- * Snapshots are the compaction cache over the event log, so `save` overwrites
102
- * whatever the id previously held.
103
- */
104
- function createSqliteSnapshotStore(options) {
105
- const { db, owned } = resolveDatabase(options.database);
106
- const table = quoteIdentifier(options.tableName ?? "agent_snapshots");
107
- db.exec(`
108
- CREATE TABLE IF NOT EXISTS ${table} (
109
- id TEXT PRIMARY KEY,
110
- snapshot TEXT NOT NULL
111
- );
112
- `);
113
- return {
114
- async load(id) {
115
- const row = db.prepare(`SELECT snapshot FROM ${table} WHERE id = ?`).get(id);
116
- return row === void 0 ? void 0 : JSON.parse(row.snapshot);
117
- },
118
- async save(id, snapshot) {
119
- db.prepare(`INSERT INTO ${table} (id, snapshot) VALUES (?, ?)
120
- ON CONFLICT(id) DO UPDATE SET snapshot = excluded.snapshot`).run(id, JSON.stringify(snapshot));
121
- },
122
- close() {
123
- if (owned) db.close();
124
- }
125
- };
126
- }
127
- //#endregion
128
- exports.createSqliteEventLogStore = createSqliteEventLogStore;
129
- exports.createSqliteSnapshotStore = createSqliteSnapshotStore;
package/dist/sqlite.d.cts DELETED
@@ -1,57 +0,0 @@
1
- import { r as AgentSnapshotStore } from "./types-DSdj2tGs.cjs";
2
- import { r as AgentEventLogStore } from "./event-log-store-Bz7HDBkE.cjs";
3
-
4
- //#region src/sqlite/index.d.ts
5
- /** A prepared statement, structurally compatible with `node:sqlite`'s `StatementSync`. */
6
- interface SqliteStatement {
7
- run(...params: any[]): unknown;
8
- all(...params: any[]): unknown[];
9
- get(...params: any[]): unknown;
10
- }
11
- /** A database handle, structurally compatible with `node:sqlite`'s `DatabaseSync`. */
12
- interface SqliteDatabase {
13
- prepare(sql: string): SqliteStatement;
14
- exec(sql: string): void;
15
- close(): void;
16
- }
17
- /** A store that owns nothing unless it opened the file itself.
18
- *
19
- * Exported because it appears in the store factories' return types — without
20
- * it, consumers' declaration emit fails with TS4058 "cannot be named". */
21
- interface Closable {
22
- /**
23
- * Closes the underlying database — but only when this store opened it from a
24
- * path. When a `DatabaseSync` handle was passed in, the caller owns it and
25
- * this is a no-op.
26
- */
27
- close(): void;
28
- }
29
- interface SqliteStoreOptions {
30
- /** A file path (or `':memory:'`) to open, or an existing `node:sqlite` handle to share. */
31
- database: string | SqliteDatabase;
32
- }
33
- interface SqliteEventLogStoreOptions extends SqliteStoreOptions {
34
- /** Table holding the log entries. Defaults to `agent_event_log`. */
35
- tableName?: string;
36
- }
37
- interface SqliteSnapshotStoreOptions extends SqliteStoreOptions {
38
- /** Table holding the snapshots. Defaults to `agent_snapshots`. */
39
- tableName?: string;
40
- }
41
- /**
42
- * An {@link AgentEventLogStore} on one SQLite table, keyed by
43
- * `(thread_id, idx)` with a unique `(thread_id, entry_id)` index. Entries are
44
- * stored as JSON text, so reads and writes are deep copies by construction.
45
- * `append` runs its length check and inserts inside one `BEGIN IMMEDIATE`
46
- * transaction: `node:sqlite` is synchronous, so no `await` interleaves between
47
- * the check and the write and racing appends resolve to exactly one winner.
48
- */
49
- declare function createSqliteEventLogStore(options: SqliteEventLogStoreOptions): AgentEventLogStore & Closable;
50
- /**
51
- * An {@link AgentSnapshotStore} on one SQLite table: a `key -> JSON` upsert.
52
- * Snapshots are the compaction cache over the event log, so `save` overwrites
53
- * whatever the id previously held.
54
- */
55
- declare function createSqliteSnapshotStore(options: SqliteSnapshotStoreOptions): AgentSnapshotStore & Closable;
56
- //#endregion
57
- export { Closable, SqliteDatabase, SqliteEventLogStoreOptions, SqliteSnapshotStoreOptions, SqliteStatement, SqliteStoreOptions, createSqliteEventLogStore, createSqliteSnapshotStore };
package/dist/sqlite.d.mts DELETED
@@ -1,57 +0,0 @@
1
- import { r as AgentSnapshotStore } from "./types-CvWRGFxP.mjs";
2
- import { r as AgentEventLogStore } from "./event-log-store-hrA1vqtN.mjs";
3
-
4
- //#region src/sqlite/index.d.ts
5
- /** A prepared statement, structurally compatible with `node:sqlite`'s `StatementSync`. */
6
- interface SqliteStatement {
7
- run(...params: any[]): unknown;
8
- all(...params: any[]): unknown[];
9
- get(...params: any[]): unknown;
10
- }
11
- /** A database handle, structurally compatible with `node:sqlite`'s `DatabaseSync`. */
12
- interface SqliteDatabase {
13
- prepare(sql: string): SqliteStatement;
14
- exec(sql: string): void;
15
- close(): void;
16
- }
17
- /** A store that owns nothing unless it opened the file itself.
18
- *
19
- * Exported because it appears in the store factories' return types — without
20
- * it, consumers' declaration emit fails with TS4058 "cannot be named". */
21
- interface Closable {
22
- /**
23
- * Closes the underlying database — but only when this store opened it from a
24
- * path. When a `DatabaseSync` handle was passed in, the caller owns it and
25
- * this is a no-op.
26
- */
27
- close(): void;
28
- }
29
- interface SqliteStoreOptions {
30
- /** A file path (or `':memory:'`) to open, or an existing `node:sqlite` handle to share. */
31
- database: string | SqliteDatabase;
32
- }
33
- interface SqliteEventLogStoreOptions extends SqliteStoreOptions {
34
- /** Table holding the log entries. Defaults to `agent_event_log`. */
35
- tableName?: string;
36
- }
37
- interface SqliteSnapshotStoreOptions extends SqliteStoreOptions {
38
- /** Table holding the snapshots. Defaults to `agent_snapshots`. */
39
- tableName?: string;
40
- }
41
- /**
42
- * An {@link AgentEventLogStore} on one SQLite table, keyed by
43
- * `(thread_id, idx)` with a unique `(thread_id, entry_id)` index. Entries are
44
- * stored as JSON text, so reads and writes are deep copies by construction.
45
- * `append` runs its length check and inserts inside one `BEGIN IMMEDIATE`
46
- * transaction: `node:sqlite` is synchronous, so no `await` interleaves between
47
- * the check and the write and racing appends resolve to exactly one winner.
48
- */
49
- declare function createSqliteEventLogStore(options: SqliteEventLogStoreOptions): AgentEventLogStore & Closable;
50
- /**
51
- * An {@link AgentSnapshotStore} on one SQLite table: a `key -> JSON` upsert.
52
- * Snapshots are the compaction cache over the event log, so `save` overwrites
53
- * whatever the id previously held.
54
- */
55
- declare function createSqliteSnapshotStore(options: SqliteSnapshotStoreOptions): AgentSnapshotStore & Closable;
56
- //#endregion
57
- export { Closable, SqliteDatabase, SqliteEventLogStoreOptions, SqliteSnapshotStoreOptions, SqliteStatement, SqliteStoreOptions, createSqliteEventLogStore, createSqliteSnapshotStore };
package/dist/sqlite.mjs DELETED
@@ -1,127 +0,0 @@
1
- import { i as assertAgentLogEntry, n as AgentEventLogConflictError } from "./event-log-store-DmIDosD6.mjs";
2
- //#region src/sqlite/index.ts
3
- function openDatabase(path) {
4
- const sqlite = process.getBuiltinModule?.("node:sqlite");
5
- if (!sqlite?.DatabaseSync) throw new Error("createSqlite*Store: 'node:sqlite' is unavailable in this runtime; Node >= 22.18 is required.");
6
- return new sqlite.DatabaseSync(path);
7
- }
8
- function quoteIdentifier(name) {
9
- if (!/^[A-Za-z_][A-Za-z0-9_]*$/.test(name)) throw new Error(`Invalid SQLite table name '${name}': use letters, digits, and underscores only.`);
10
- return `"${name}"`;
11
- }
12
- function resolveDatabase(database) {
13
- return typeof database === "string" ? {
14
- db: openDatabase(database),
15
- owned: true
16
- } : {
17
- db: database,
18
- owned: false
19
- };
20
- }
21
- /**
22
- * An {@link AgentEventLogStore} on one SQLite table, keyed by
23
- * `(thread_id, idx)` with a unique `(thread_id, entry_id)` index. Entries are
24
- * stored as JSON text, so reads and writes are deep copies by construction.
25
- * `append` runs its length check and inserts inside one `BEGIN IMMEDIATE`
26
- * transaction: `node:sqlite` is synchronous, so no `await` interleaves between
27
- * the check and the write and racing appends resolve to exactly one winner.
28
- */
29
- function createSqliteEventLogStore(options) {
30
- const { db, owned } = resolveDatabase(options.database);
31
- const table = quoteIdentifier(options.tableName ?? "agent_event_log");
32
- db.exec(`
33
- CREATE TABLE IF NOT EXISTS ${table} (
34
- thread_id TEXT NOT NULL,
35
- idx INTEGER NOT NULL,
36
- entry_id TEXT NOT NULL,
37
- entry TEXT NOT NULL,
38
- PRIMARY KEY (thread_id, idx)
39
- );
40
- CREATE UNIQUE INDEX IF NOT EXISTS ${quoteIdentifier(`${options.tableName ?? "agent_event_log"}_thread_entry_id`)} ON ${table} (thread_id, entry_id);
41
- `);
42
- const lengthOf = (threadId) => {
43
- const row = db.prepare(`SELECT COUNT(*) AS n FROM ${table} WHERE thread_id = ?`).get(threadId);
44
- return Number(row?.n ?? 0);
45
- };
46
- const transact = (fn) => {
47
- db.exec("BEGIN IMMEDIATE");
48
- try {
49
- const result = fn();
50
- db.exec("COMMIT");
51
- return result;
52
- } catch (error) {
53
- try {
54
- db.exec("ROLLBACK");
55
- } catch {}
56
- throw error;
57
- }
58
- };
59
- return {
60
- async append({ threadId, expectedIndex, entries }) {
61
- for (const entry of entries) assertAgentLogEntry(entry);
62
- for (let i = 0; i < entries.length; i++) if (entries[i].index !== expectedIndex + i) throw new Error(`AgentEventLogStore.append: entry.index (${entries[i].index}) must be contiguous from expectedIndex (${expectedIndex}); expected ${expectedIndex + i} at position ${i} on thread "${threadId}".`);
63
- transact(() => {
64
- const length = lengthOf(threadId);
65
- if (length !== expectedIndex) throw new AgentEventLogConflictError(threadId, expectedIndex, length);
66
- const insert = db.prepare(`INSERT INTO ${table} (thread_id, idx, entry_id, entry) VALUES (?, ?, ?, ?)`);
67
- for (const entry of entries) try {
68
- insert.run(threadId, entry.index, entry.id, JSON.stringify(entry));
69
- } catch (error) {
70
- if (String(error.message).includes("UNIQUE")) throw new Error(`AgentEventLogStore.append: duplicate event id "${entry.id}" in thread "${threadId}".`);
71
- throw error;
72
- }
73
- });
74
- },
75
- async read(threadId, options) {
76
- const from = options?.from ?? 0;
77
- return db.prepare(`SELECT entry FROM ${table} WHERE thread_id = ? AND idx >= ? ORDER BY idx ASC`).all(threadId, from).map((row) => JSON.parse(row.entry));
78
- },
79
- async length(threadId) {
80
- return lengthOf(threadId);
81
- },
82
- async fork({ threadId, newThreadId, upToIndex }) {
83
- transact(() => {
84
- if (lengthOf(newThreadId) > 0) throw new Error(`AgentEventLogStore.fork: newThreadId "${newThreadId}" already has entries.`);
85
- const sourceLength = lengthOf(threadId);
86
- if (sourceLength === 0) throw new Error(`AgentEventLogStore.fork: unknown source thread "${threadId}".`);
87
- const upTo = upToIndex ?? sourceLength;
88
- if (upTo < 0 || upTo > sourceLength) throw new Error(`AgentEventLogStore.fork: thread "${threadId}" (length ${sourceLength}) has no index ${upTo} to fork up to.`);
89
- db.prepare(`INSERT INTO ${table} (thread_id, idx, entry_id, entry)
90
- SELECT ?, idx, entry_id, entry FROM ${table} WHERE thread_id = ? AND idx < ?`).run(newThreadId, threadId, upTo);
91
- });
92
- },
93
- close() {
94
- if (owned) db.close();
95
- }
96
- };
97
- }
98
- /**
99
- * An {@link AgentSnapshotStore} on one SQLite table: a `key -> JSON` upsert.
100
- * Snapshots are the compaction cache over the event log, so `save` overwrites
101
- * whatever the id previously held.
102
- */
103
- function createSqliteSnapshotStore(options) {
104
- const { db, owned } = resolveDatabase(options.database);
105
- const table = quoteIdentifier(options.tableName ?? "agent_snapshots");
106
- db.exec(`
107
- CREATE TABLE IF NOT EXISTS ${table} (
108
- id TEXT PRIMARY KEY,
109
- snapshot TEXT NOT NULL
110
- );
111
- `);
112
- return {
113
- async load(id) {
114
- const row = db.prepare(`SELECT snapshot FROM ${table} WHERE id = ?`).get(id);
115
- return row === void 0 ? void 0 : JSON.parse(row.snapshot);
116
- },
117
- async save(id, snapshot) {
118
- db.prepare(`INSERT INTO ${table} (id, snapshot) VALUES (?, ?)
119
- ON CONFLICT(id) DO UPDATE SET snapshot = excluded.snapshot`).run(id, JSON.stringify(snapshot));
120
- },
121
- close() {
122
- if (owned) db.close();
123
- }
124
- };
125
- }
126
- //#endregion
127
- export { createSqliteEventLogStore, createSqliteSnapshotStore };