orchajs 0.24.0 → 0.25.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.
- package/README.md +50 -3
- package/dist/amarsia/analytics.js +12 -0
- package/dist/amarsia/inference.d.ts +6 -0
- package/dist/amarsia/inference.js +337 -0
- package/dist/browser.js +5 -0
- package/dist/cli-agents-template.d.ts +1 -1
- package/dist/cli-agents-template.js +31 -7
- package/dist/compiler/build-project.js +57 -14
- package/dist/compiler/node-esm-banner.d.ts +2 -0
- package/dist/compiler/node-esm-banner.js +5 -0
- package/dist/orcha.js +5 -0
- package/dist/project-loader.js +4 -2
- package/dist/providers/types.d.ts +4 -0
- package/dist/react-native.js +5 -0
- package/dist/runtime/agent.js +103 -14
- package/dist/runtime/compiler-hook.d.ts +4 -0
- package/dist/runtime/compiler-hook.js +9 -0
- package/dist/runtime/create-orcha.d.ts +19 -0
- package/dist/runtime/create-orcha.js +109 -12
- package/dist/runtime/optional-features.d.ts +19 -0
- package/dist/runtime/optional-features.js +22 -0
- package/dist/runtime/platform-browser.js +16 -3
- package/dist/runtime/platform-node.js +16 -2
- package/dist/runtime/platform-react-native.js +16 -3
- package/dist/storage/browser-indexeddb.d.ts +3 -0
- package/dist/storage/browser-indexeddb.js +72 -8
- package/dist/storage/cloud-outbox.d.ts +30 -0
- package/dist/storage/cloud-outbox.js +628 -0
- package/dist/storage/cloud.d.ts +1 -0
- package/dist/storage/cloud.js +1 -0
- package/dist/storage/node-jsonl.d.ts +3 -0
- package/dist/storage/node-jsonl.js +273 -4
- package/dist/storage/node-sqlite.d.ts +3 -0
- package/dist/storage/node-sqlite.js +66 -17
- package/dist/storage/react-native-jsonl.d.ts +3 -0
- package/dist/storage/react-native-jsonl.js +223 -0
- package/dist/types.d.ts +21 -2
- package/dist-cjs/amarsia/analytics.js +12 -0
- package/dist-cjs/amarsia/inference.js +335 -0
- package/dist-cjs/browser.js +5 -0
- package/dist-cjs/cli-agents-template.js +31 -7
- package/dist-cjs/compiler/build-project.js +68 -4
- package/dist-cjs/compiler/node-esm-banner.js +32 -0
- package/dist-cjs/orcha.js +5 -0
- package/dist-cjs/project-loader.js +7 -5
- package/dist-cjs/react-native.js +5 -0
- package/dist-cjs/runtime/agent.js +137 -30
- package/dist-cjs/runtime/compiler-hook.js +11 -0
- package/dist-cjs/runtime/create-orcha.js +117 -12
- package/dist-cjs/runtime/optional-features.js +58 -0
- package/dist-cjs/runtime/platform-browser.js +16 -3
- package/dist-cjs/runtime/platform-node.js +16 -2
- package/dist-cjs/runtime/platform-react-native.js +18 -3
- package/dist-cjs/storage/browser-indexeddb.js +73 -8
- package/dist-cjs/storage/cloud-outbox.js +646 -0
- package/dist-cjs/storage/cloud.js +29 -0
- package/dist-cjs/storage/node-jsonl.js +246 -3
- package/dist-cjs/storage/node-sqlite.js +70 -19
- package/dist-cjs/storage/react-native-jsonl.js +207 -0
- package/package.json +1 -1
|
@@ -3,8 +3,11 @@ export declare class BrowserIndexedDbSessionStore implements SessionStore {
|
|
|
3
3
|
#private;
|
|
4
4
|
constructor(namespace: string, databaseName?: string);
|
|
5
5
|
read(sessionId: string): Promise<SessionEvent[]>;
|
|
6
|
+
readAfterSequence(sessionId: string, afterSequence: number, limit: number): Promise<SessionEvent[]>;
|
|
6
7
|
append(sessionId: string, events: SessionEvent[]): Promise<void>;
|
|
7
8
|
listSessionIds(): Promise<string[]>;
|
|
9
|
+
getCloudAcknowledgement(sessionId: string): Promise<number>;
|
|
10
|
+
setCloudAcknowledgement(sessionId: string, sequence: number): Promise<void>;
|
|
8
11
|
subscribe(sessionId: string, listener: (events: SessionEvent[]) => void): () => void;
|
|
9
12
|
subscribeAll(listener: (sessionId: string, events: SessionEvent[]) => void): () => void;
|
|
10
13
|
describeLocation(sessionId: string): Promise<string>;
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
const DATABASE_VERSION =
|
|
1
|
+
const DATABASE_VERSION = 3;
|
|
2
2
|
const EVENT_STORE = "events";
|
|
3
|
+
const CLOUD_ACK_STORE = "cloud-acknowledgements";
|
|
4
|
+
const SESSION_SEQUENCE_INDEX = "session-sequence";
|
|
3
5
|
export class BrowserIndexedDbSessionStore {
|
|
4
6
|
#databaseName;
|
|
5
7
|
#namespace;
|
|
@@ -19,6 +21,17 @@ export class BrowserIndexedDbSessionStore {
|
|
|
19
21
|
.sort((left, right) => left.sequence - right.sequence)
|
|
20
22
|
.map((record) => record.event);
|
|
21
23
|
}
|
|
24
|
+
async readAfterSequence(sessionId, afterSequence, limit) {
|
|
25
|
+
validateTailArguments(afterSequence, limit);
|
|
26
|
+
const database = await this.#open();
|
|
27
|
+
const transaction = database.transaction(EVENT_STORE, "readonly");
|
|
28
|
+
const index = transaction
|
|
29
|
+
.objectStore(EVENT_STORE)
|
|
30
|
+
.index(SESSION_SEQUENCE_INDEX);
|
|
31
|
+
const records = await request(index.getAll(IDBKeyRange.bound([this.#namespace, sessionId, afterSequence], [this.#namespace, sessionId, Number.MAX_SAFE_INTEGER], true), limit));
|
|
32
|
+
await transactionComplete(transaction);
|
|
33
|
+
return records.map((record) => record.event);
|
|
34
|
+
}
|
|
22
35
|
async append(sessionId, events) {
|
|
23
36
|
if (events.length === 0) {
|
|
24
37
|
return;
|
|
@@ -47,6 +60,33 @@ export class BrowserIndexedDbSessionStore {
|
|
|
47
60
|
await transactionComplete(transaction);
|
|
48
61
|
return [...new Set(records.map((record) => record.sessionId))].sort();
|
|
49
62
|
}
|
|
63
|
+
async getCloudAcknowledgement(sessionId) {
|
|
64
|
+
const database = await this.#open();
|
|
65
|
+
const transaction = database.transaction(CLOUD_ACK_STORE, "readonly");
|
|
66
|
+
const value = await request(transaction.objectStore(CLOUD_ACK_STORE).get(acknowledgementId(this.#namespace, sessionId)));
|
|
67
|
+
await transactionComplete(transaction);
|
|
68
|
+
return typeof value === "number" &&
|
|
69
|
+
Number.isInteger(value) &&
|
|
70
|
+
value >= 0
|
|
71
|
+
? value
|
|
72
|
+
: 0;
|
|
73
|
+
}
|
|
74
|
+
async setCloudAcknowledgement(sessionId, sequence) {
|
|
75
|
+
if (!Number.isInteger(sequence) || sequence < 0) {
|
|
76
|
+
throw new Error("Invalid cloud acknowledgement sequence.");
|
|
77
|
+
}
|
|
78
|
+
const database = await this.#open();
|
|
79
|
+
const transaction = database.transaction(CLOUD_ACK_STORE, "readwrite");
|
|
80
|
+
const store = transaction.objectStore(CLOUD_ACK_STORE);
|
|
81
|
+
const id = acknowledgementId(this.#namespace, sessionId);
|
|
82
|
+
const current = await request(store.get(id));
|
|
83
|
+
if (typeof current !== "number" ||
|
|
84
|
+
!Number.isInteger(current) ||
|
|
85
|
+
current < sequence) {
|
|
86
|
+
store.put(sequence, id);
|
|
87
|
+
}
|
|
88
|
+
await transactionComplete(transaction);
|
|
89
|
+
}
|
|
50
90
|
subscribe(sessionId, listener) {
|
|
51
91
|
const listeners = this.#listeners.get(sessionId) ?? new Set();
|
|
52
92
|
listeners.add(listener);
|
|
@@ -73,14 +113,27 @@ export class BrowserIndexedDbSessionStore {
|
|
|
73
113
|
const openRequest = indexedDB.open(this.#databaseName, DATABASE_VERSION);
|
|
74
114
|
openRequest.onupgradeneeded = () => {
|
|
75
115
|
const database = openRequest.result;
|
|
76
|
-
|
|
77
|
-
|
|
116
|
+
let eventStore;
|
|
117
|
+
if (!database.objectStoreNames.contains(EVENT_STORE)) {
|
|
118
|
+
eventStore = database.createObjectStore(EVENT_STORE, {
|
|
119
|
+
keyPath: "id",
|
|
120
|
+
});
|
|
121
|
+
eventStore.createIndex("session", ["namespace", "sessionId"]);
|
|
122
|
+
eventStore.createIndex("namespace", "namespace");
|
|
123
|
+
}
|
|
124
|
+
else {
|
|
125
|
+
eventStore = openRequest.transaction.objectStore(EVENT_STORE);
|
|
126
|
+
}
|
|
127
|
+
if (!eventStore.indexNames.contains(SESSION_SEQUENCE_INDEX)) {
|
|
128
|
+
eventStore.createIndex(SESSION_SEQUENCE_INDEX, [
|
|
129
|
+
"namespace",
|
|
130
|
+
"sessionId",
|
|
131
|
+
"sequence",
|
|
132
|
+
]);
|
|
133
|
+
}
|
|
134
|
+
if (!database.objectStoreNames.contains(CLOUD_ACK_STORE)) {
|
|
135
|
+
database.createObjectStore(CLOUD_ACK_STORE);
|
|
78
136
|
}
|
|
79
|
-
const store = database.createObjectStore(EVENT_STORE, {
|
|
80
|
-
keyPath: "id",
|
|
81
|
-
});
|
|
82
|
-
store.createIndex("session", ["namespace", "sessionId"]);
|
|
83
|
-
store.createIndex("namespace", "namespace");
|
|
84
137
|
};
|
|
85
138
|
openRequest.onsuccess = () => resolve(openRequest.result);
|
|
86
139
|
openRequest.onerror = () => reject(openRequest.error);
|
|
@@ -88,6 +141,9 @@ export class BrowserIndexedDbSessionStore {
|
|
|
88
141
|
});
|
|
89
142
|
}
|
|
90
143
|
}
|
|
144
|
+
function acknowledgementId(namespace, sessionId) {
|
|
145
|
+
return `${namespace}\u0000${sessionId}`;
|
|
146
|
+
}
|
|
91
147
|
function eventId(namespace, sessionId, sequence) {
|
|
92
148
|
return `${namespace}\u0000${sessionId}\u0000${sequence
|
|
93
149
|
.toString()
|
|
@@ -106,3 +162,11 @@ function transactionComplete(transaction) {
|
|
|
106
162
|
transaction.onabort = () => reject(transaction.error ?? new Error("IndexedDB transaction aborted."));
|
|
107
163
|
});
|
|
108
164
|
}
|
|
165
|
+
function validateTailArguments(afterSequence, limit) {
|
|
166
|
+
if (!Number.isInteger(afterSequence) ||
|
|
167
|
+
afterSequence < 0 ||
|
|
168
|
+
!Number.isInteger(limit) ||
|
|
169
|
+
limit <= 0) {
|
|
170
|
+
throw new Error("Invalid session event tail range.");
|
|
171
|
+
}
|
|
172
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { SessionEvent, SessionStore } from "../types.js";
|
|
2
|
+
export interface CloudSessionStoreOptions {
|
|
3
|
+
local: SessionStore;
|
|
4
|
+
key: string;
|
|
5
|
+
endpoint?: string;
|
|
6
|
+
agentName: string;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* A durable local-first outbox. Local appends never wait for cloud I/O; the
|
|
10
|
+
* persisted acknowledgement lets a new process recover unsent session tails.
|
|
11
|
+
*/
|
|
12
|
+
export declare class CloudSessionStore implements SessionStore {
|
|
13
|
+
#private;
|
|
14
|
+
constructor(options: CloudSessionStoreOptions);
|
|
15
|
+
get cloudStoragePendingCount(): number;
|
|
16
|
+
get cloudStorageLastError(): Error | undefined;
|
|
17
|
+
read(sessionId: string): Promise<SessionEvent[]>;
|
|
18
|
+
append(sessionId: string, events: SessionEvent[]): Promise<void>;
|
|
19
|
+
refreshCloudSession(sessionId: string): Promise<void>;
|
|
20
|
+
listSessionIds(): Promise<string[]>;
|
|
21
|
+
subscribe(sessionId: string, listener: (events: SessionEvent[]) => void): () => void;
|
|
22
|
+
subscribeAll(listener: (sessionId: string, events: SessionEvent[]) => void): () => void;
|
|
23
|
+
describeLocation(sessionId: string): Promise<string>;
|
|
24
|
+
flushCloudStorage(options?: {
|
|
25
|
+
timeoutMs?: number;
|
|
26
|
+
}): Promise<void>;
|
|
27
|
+
closeCloudStorage(options?: {
|
|
28
|
+
timeoutMs?: number;
|
|
29
|
+
}): Promise<void>;
|
|
30
|
+
}
|