modjules 0.1.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/README.md +319 -0
- package/dist/activities/client.d.ts +79 -0
- package/dist/activities/types.d.ts +56 -0
- package/dist/api.d.ts +21 -0
- package/dist/artifacts.d.ts +54 -0
- package/dist/browser.d.ts +12 -0
- package/dist/browser.es.js +158 -0
- package/dist/client-D2GRjxRE.mjs +927 -0
- package/dist/client.d.ts +112 -0
- package/dist/errors.d.ts +69 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.es.js +140 -0
- package/dist/mappers.d.ts +34 -0
- package/dist/network/adapter.d.ts +32 -0
- package/dist/platform/browser.d.ts +25 -0
- package/dist/platform/node.d.ts +16 -0
- package/dist/platform/types.d.ts +18 -0
- package/dist/polling.d.ts +24 -0
- package/dist/session.d.ts +121 -0
- package/dist/sources.d.ts +8 -0
- package/dist/storage/browser.d.ts +48 -0
- package/dist/storage/memory.d.ts +40 -0
- package/dist/storage/node-fs.d.ts +54 -0
- package/dist/storage/types.d.ts +38 -0
- package/dist/streaming.d.ts +16 -0
- package/dist/types.d.ts +799 -0
- package/dist/utils.d.ts +12 -0
- package/package.json +81 -0
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
import { J as u } from "./client-D2GRjxRE.mjs";
|
|
2
|
+
import { A as v, I as A, c as E, d as D, a as P, b as x, e as T, M as j, S as N } from "./client-D2GRjxRE.mjs";
|
|
3
|
+
import { openDB as l } from "idb";
|
|
4
|
+
const h = "jules-activities", a = "activities";
|
|
5
|
+
class m {
|
|
6
|
+
sessionId;
|
|
7
|
+
dbPromise = null;
|
|
8
|
+
constructor(t) {
|
|
9
|
+
this.sessionId = t;
|
|
10
|
+
}
|
|
11
|
+
getDb() {
|
|
12
|
+
return this.dbPromise || (this.dbPromise = l(h, 2, {
|
|
13
|
+
upgrade(t, s, e, r) {
|
|
14
|
+
s < 1 && (t.objectStoreNames.contains(a) || t.createObjectStore(a, {
|
|
15
|
+
keyPath: "id"
|
|
16
|
+
}).createIndex("sessionTimestamp", [
|
|
17
|
+
"sessionId",
|
|
18
|
+
"createTime"
|
|
19
|
+
])), t.objectStoreNames.contains("artifacts") || t.createObjectStore("artifacts", {
|
|
20
|
+
keyPath: "filepath"
|
|
21
|
+
}).createIndex("activityId", "activityId");
|
|
22
|
+
}
|
|
23
|
+
})), this.dbPromise;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Initializes the storage.
|
|
27
|
+
*
|
|
28
|
+
* **Side Effects:**
|
|
29
|
+
* - Opens an IndexedDB connection.
|
|
30
|
+
* - Upgrades the database schema to v2 if necessary (creating object stores).
|
|
31
|
+
*/
|
|
32
|
+
async init() {
|
|
33
|
+
await this.getDb();
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Closes the storage connection.
|
|
37
|
+
*/
|
|
38
|
+
async close() {
|
|
39
|
+
this.dbPromise && ((await this.dbPromise).close(), this.dbPromise = null);
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Appends an activity to IndexedDB.
|
|
43
|
+
*
|
|
44
|
+
* **Side Effects:**
|
|
45
|
+
* - Adds a `sessionId` field to the activity for indexing.
|
|
46
|
+
* - Writes the modified activity to the `activities` object store.
|
|
47
|
+
*/
|
|
48
|
+
async append(t) {
|
|
49
|
+
const e = (await this.getDb()).transaction(a, "readwrite"), r = e.objectStore(a), i = { ...t, sessionId: this.sessionId };
|
|
50
|
+
await r.put(i), await e.done;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Retrieves an activity by ID.
|
|
54
|
+
*/
|
|
55
|
+
async get(t) {
|
|
56
|
+
const e = await (await this.getDb()).get(a, t);
|
|
57
|
+
return e && delete e.sessionId, e;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Retrieves the latest activity for the current session.
|
|
61
|
+
*
|
|
62
|
+
* **Logic:**
|
|
63
|
+
* - Uses the `sessionTimestamp` index to query efficiently.
|
|
64
|
+
* - Opens a cursor in 'prev' direction to find the last entry first.
|
|
65
|
+
*/
|
|
66
|
+
async latest() {
|
|
67
|
+
const r = (await this.getDb()).transaction(a, "readonly").objectStore(a).index("sessionTimestamp"), i = IDBKeyRange.bound(
|
|
68
|
+
[this.sessionId, ""],
|
|
69
|
+
[this.sessionId, (/* @__PURE__ */ new Date(864e13)).toISOString()]
|
|
70
|
+
), o = await r.openCursor(i, "prev");
|
|
71
|
+
if (!o)
|
|
72
|
+
return;
|
|
73
|
+
const n = o.value;
|
|
74
|
+
return n && delete n.sessionId, n;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Yields all activities for the current session.
|
|
78
|
+
*/
|
|
79
|
+
async *scan() {
|
|
80
|
+
const r = (await this.getDb()).transaction(a, "readonly").objectStore(a).index("sessionTimestamp"), i = IDBKeyRange.bound(
|
|
81
|
+
[this.sessionId, ""],
|
|
82
|
+
[this.sessionId, (/* @__PURE__ */ new Date(864e13)).toISOString()]
|
|
83
|
+
);
|
|
84
|
+
let o = await r.openCursor(i, "next");
|
|
85
|
+
for (; o; ) {
|
|
86
|
+
const n = o.value;
|
|
87
|
+
n && delete n.sessionId, yield n, o = await o.continue();
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
const w = "jules-activities", d = "artifacts", b = "activities";
|
|
92
|
+
class I {
|
|
93
|
+
dbPromise = null;
|
|
94
|
+
getDb() {
|
|
95
|
+
return this.dbPromise || (this.dbPromise = l(w, 2, {
|
|
96
|
+
upgrade(t, s, e, r) {
|
|
97
|
+
t.objectStoreNames.contains(b) || t.createObjectStore(b, {
|
|
98
|
+
keyPath: "id"
|
|
99
|
+
}).createIndex("sessionTimestamp", ["sessionId", "createTime"]), t.objectStoreNames.contains(d) || t.createObjectStore(d, {
|
|
100
|
+
keyPath: "filepath"
|
|
101
|
+
}).createIndex("activityId", "activityId");
|
|
102
|
+
}
|
|
103
|
+
})), this.dbPromise;
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Saves a file to IndexedDB.
|
|
107
|
+
*
|
|
108
|
+
* **Data Transformation:**
|
|
109
|
+
* - Decodes base64 data into a `Blob`.
|
|
110
|
+
*
|
|
111
|
+
* **Side Effects:**
|
|
112
|
+
* - Stores the blob in the `artifacts` object store.
|
|
113
|
+
* - Associates the file with the `activityId` (if provided).
|
|
114
|
+
*
|
|
115
|
+
* @throws {Error} If the encoding is not 'base64'.
|
|
116
|
+
*/
|
|
117
|
+
async saveFile(t, s, e, r) {
|
|
118
|
+
if (e !== "base64")
|
|
119
|
+
throw new Error(`Unsupported encoding for browser saveFile: ${e}`);
|
|
120
|
+
const i = await this.getDb(), o = this.base64ToBlob(s);
|
|
121
|
+
await i.put(d, {
|
|
122
|
+
filepath: t,
|
|
123
|
+
blob: o,
|
|
124
|
+
activityId: r,
|
|
125
|
+
createdAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
async sleep(t) {
|
|
129
|
+
await new Promise((s) => setTimeout(s, t));
|
|
130
|
+
}
|
|
131
|
+
createDataUrl(t, s) {
|
|
132
|
+
return `data:${s};base64,${t}`;
|
|
133
|
+
}
|
|
134
|
+
base64ToBlob(t, s) {
|
|
135
|
+
const e = atob(t), r = new Array(e.length);
|
|
136
|
+
for (let o = 0; o < e.length; o++)
|
|
137
|
+
r[o] = e.charCodeAt(o);
|
|
138
|
+
const i = new Uint8Array(r);
|
|
139
|
+
return new Blob([i], s ? { type: s } : void 0);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
const p = new u(
|
|
143
|
+
{},
|
|
144
|
+
(c) => new m(c),
|
|
145
|
+
new I()
|
|
146
|
+
);
|
|
147
|
+
export {
|
|
148
|
+
v as AutomatedSessionFailedError,
|
|
149
|
+
A as InvalidStateError,
|
|
150
|
+
E as JulesApiError,
|
|
151
|
+
D as JulesAuthenticationError,
|
|
152
|
+
P as JulesError,
|
|
153
|
+
x as JulesNetworkError,
|
|
154
|
+
T as JulesRateLimitError,
|
|
155
|
+
j as MissingApiKeyError,
|
|
156
|
+
N as SourceNotFoundError,
|
|
157
|
+
p as jules
|
|
158
|
+
};
|