@adminide-stack/yantra-mobile 12.0.94-alpha.2 → 12.0.95-alpha.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/lib/compute.js +113 -1
- package/lib/compute.js.map +1 -1
- package/lib/features/agent-chat/NativeAgentChat.js +1 -1
- package/lib/features/agent-chat/NativeAgentChat.js.map +1 -1
- package/lib/features/apps/AppsCatalog.js +20 -0
- package/lib/features/apps/AppsCatalog.js.map +1 -1
- package/lib/features/apps/appArt.js +3 -1
- package/lib/features/apps/appArt.js.map +1 -1
- package/lib/features/apps/appFavorites.js +8 -2
- package/lib/features/apps/appFavorites.js.map +1 -1
- package/lib/features/apps/mobileAppCatalog.js +27 -1
- package/lib/features/apps/mobileAppCatalog.js.map +1 -1
- package/lib/features/canvas/VideoGeneratorExperience.js +1 -0
- package/lib/features/canvas/VideoGeneratorExperience.js.map +1 -1
- package/lib/features/canvas/videoEditor/remoteMediaClient.js +51 -24
- package/lib/features/canvas/videoEditor/remoteMediaClient.js.map +1 -1
- package/lib/features/chat/connectorConnect.js +1 -1
- package/lib/features/inbox/InboxAgentChatPane.js +64 -0
- package/lib/features/inbox/InboxAgentChatPane.js.map +1 -0
- package/lib/features/inbox/InboxExperience.js +631 -0
- package/lib/features/inbox/InboxExperience.js.map +1 -0
- package/lib/features/inbox/components/BottomSheet.js +111 -0
- package/lib/features/inbox/components/BottomSheet.js.map +1 -0
- package/lib/features/inbox/components/ComposeSheet.js +298 -0
- package/lib/features/inbox/components/ComposeSheet.js.map +1 -0
- package/lib/features/inbox/components/InboxStates.js +182 -0
- package/lib/features/inbox/components/InboxStates.js.map +1 -0
- package/lib/features/inbox/components/MailBody.js +103 -0
- package/lib/features/inbox/components/MailBody.js.map +1 -0
- package/lib/features/inbox/components/MessageReader.js +396 -0
- package/lib/features/inbox/components/MessageReader.js.map +1 -0
- package/lib/features/inbox/components/MessageRow.js +153 -0
- package/lib/features/inbox/components/MessageRow.js.map +1 -0
- package/lib/features/inbox/components/SenderAvatar.js +24 -0
- package/lib/features/inbox/components/SenderAvatar.js.map +1 -0
- package/lib/features/inbox/components/Tap.js +55 -0
- package/lib/features/inbox/components/Tap.js.map +1 -0
- package/lib/features/inbox/composeDraft.js +89 -0
- package/lib/features/inbox/composeDraft.js.map +1 -0
- package/lib/features/inbox/formatMailDate.js +60 -0
- package/lib/features/inbox/formatMailDate.js.map +1 -0
- package/lib/features/inbox/inboxAccounts.js +110 -0
- package/lib/features/inbox/inboxAccounts.js.map +1 -0
- package/lib/features/inbox/inboxClient.js +293 -0
- package/lib/features/inbox/inboxClient.js.map +1 -0
- package/lib/features/inbox/inboxContext.js +27 -0
- package/lib/features/inbox/inboxContext.js.map +1 -0
- package/lib/features/inbox/inboxFolders.js +47 -0
- package/lib/features/inbox/inboxFolders.js.map +1 -0
- package/lib/features/inbox/inboxNormalize.js +144 -0
- package/lib/features/inbox/inboxNormalize.js.map +1 -0
- package/lib/features/inbox/inboxPreference.js +20 -0
- package/lib/features/inbox/inboxPreference.js.map +1 -0
- package/lib/features/inbox/inboxTheme.js +54 -0
- package/lib/features/inbox/inboxTheme.js.map +1 -0
- package/lib/features/inbox/nativeInboxRegistry.js +15 -0
- package/lib/features/inbox/nativeInboxRegistry.js.map +1 -0
- package/lib/features/inbox/openAttachment.js +43 -0
- package/lib/features/inbox/openAttachment.js.map +1 -0
- package/lib/features/inbox/useInboxMailbox.js +250 -0
- package/lib/features/inbox/useInboxMailbox.js.map +1 -0
- package/lib/features/inbox/useMailMessage.js +101 -0
- package/lib/features/inbox/useMailMessage.js.map +1 -0
- package/lib/features/study/StudyAgentChatPane.js +67 -0
- package/lib/features/study/StudyAgentChatPane.js.map +1 -0
- package/lib/features/study/StudyExperience.js +586 -0
- package/lib/features/study/StudyExperience.js.map +1 -0
- package/lib/features/study/components/CellView.js +133 -0
- package/lib/features/study/components/CellView.js.map +1 -0
- package/lib/features/study/components/IntakeCard.js +203 -0
- package/lib/features/study/components/IntakeCard.js.map +1 -0
- package/lib/features/study/components/NotebookSwitcher.js +74 -0
- package/lib/features/study/components/NotebookSwitcher.js.map +1 -0
- package/lib/features/study/components/SourceStrip.js +69 -0
- package/lib/features/study/components/SourceStrip.js.map +1 -0
- package/lib/features/study/components/StudyComposer.js +118 -0
- package/lib/features/study/components/StudyComposer.js.map +1 -0
- package/lib/features/study/components/StudyOnboarding.js +477 -0
- package/lib/features/study/components/StudyOnboarding.js.map +1 -0
- package/lib/features/study/components/StudySheet.js +120 -0
- package/lib/features/study/components/StudySheet.js.map +1 -0
- package/lib/features/study/components/StudyStates.js +148 -0
- package/lib/features/study/components/StudyStates.js.map +1 -0
- package/lib/features/study/components/TextEntrySheet.js +111 -0
- package/lib/features/study/components/TextEntrySheet.js.map +1 -0
- package/lib/features/study/nativeStudyRegistry.js +15 -0
- package/lib/features/study/nativeStudyRegistry.js.map +1 -0
- package/lib/features/study/shareExport.js +38 -0
- package/lib/features/study/shareExport.js.map +1 -0
- package/lib/features/study/studyClient.js +278 -0
- package/lib/features/study/studyClient.js.map +1 -0
- package/lib/features/study/studyContext.js +25 -0
- package/lib/features/study/studyContext.js.map +1 -0
- package/lib/features/study/studyFiles.js +140 -0
- package/lib/features/study/studyFiles.js.map +1 -0
- package/lib/features/study/studyNormalize.js +116 -0
- package/lib/features/study/studyNormalize.js.map +1 -0
- package/lib/features/study/studyPreference.js +24 -0
- package/lib/features/study/studyPreference.js.map +1 -0
- package/lib/features/study/studyProfile.js +233 -0
- package/lib/features/study/studyProfile.js.map +1 -0
- package/lib/features/study/studyPrompts.js +78 -0
- package/lib/features/study/studyPrompts.js.map +1 -0
- package/lib/features/study/studyTheme.js +47 -0
- package/lib/features/study/studyTheme.js.map +1 -0
- package/lib/features/study/useStudyWorkspace.js +401 -0
- package/lib/features/study/useStudyWorkspace.js.map +1 -0
- package/lib/index.js +1 -1
- package/lib/index.js.map +1 -1
- package/lib/routes.json +108 -0
- package/lib/screens/InboxNative/index.js +77 -0
- package/lib/screens/InboxNative/index.js.map +1 -0
- package/lib/screens/InboxNative/useConnectMailbox.js +42 -0
- package/lib/screens/InboxNative/useConnectMailbox.js.map +1 -0
- package/lib/screens/InboxNative/useInboxHostChat.js +62 -0
- package/lib/screens/InboxNative/useInboxHostChat.js.map +1 -0
- package/lib/screens/InboxNative/useMailAccounts.js +54 -0
- package/lib/screens/InboxNative/useMailAccounts.js.map +1 -0
- package/lib/screens/StudyNative/index.js +80 -0
- package/lib/screens/StudyNative/index.js.map +1 -0
- package/lib/screens/StudyNative/useStudyHostChat.js +62 -0
- package/lib/screens/StudyNative/useStudyHostChat.js.map +1 -0
- package/lib/utils/authUserDisplay.js +11 -1
- package/lib/utils/authUserDisplay.js.map +1 -1
- package/package.json +3 -3
|
@@ -0,0 +1,278 @@
|
|
|
1
|
+
import {normalizeSource,normalizeSummary,normalizeNotebook,normalizeCell}from'./studyNormalize.js';var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
3
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
4
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
5
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
6
|
+
var __spreadValues = (a, b) => {
|
|
7
|
+
for (var prop in b || (b = {}))
|
|
8
|
+
if (__hasOwnProp.call(b, prop))
|
|
9
|
+
__defNormalProp(a, prop, b[prop]);
|
|
10
|
+
if (__getOwnPropSymbols)
|
|
11
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
12
|
+
if (__propIsEnum.call(b, prop))
|
|
13
|
+
__defNormalProp(a, prop, b[prop]);
|
|
14
|
+
}
|
|
15
|
+
return a;
|
|
16
|
+
};
|
|
17
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, key + "" , value);
|
|
18
|
+
const NOTEBOOK = "yantra-notebook";
|
|
19
|
+
const NOTEBOOK_ACTIONS = {
|
|
20
|
+
list: "YANTRA_NOTEBOOK_LIST",
|
|
21
|
+
get: "YANTRA_NOTEBOOK_GET",
|
|
22
|
+
create: "YANTRA_NOTEBOOK_CREATE",
|
|
23
|
+
remove: "YANTRA_NOTEBOOK_DELETE",
|
|
24
|
+
addCell: "YANTRA_NOTEBOOK_ADD_CELL",
|
|
25
|
+
updateCell: "YANTRA_NOTEBOOK_UPDATE_CELL",
|
|
26
|
+
deleteCell: "YANTRA_NOTEBOOK_DELETE_CELL",
|
|
27
|
+
summarize: "YANTRA_NOTEBOOK_SUMMARIZE",
|
|
28
|
+
exportHtml: "YANTRA_NOTEBOOK_EXPORT",
|
|
29
|
+
addSource: "YANTRA_NOTEBOOK_ADD_SOURCE",
|
|
30
|
+
deleteSource: "YANTRA_NOTEBOOK_DELETE_SOURCE"
|
|
31
|
+
};
|
|
32
|
+
const READ_TIMEOUT_MS = 6e4;
|
|
33
|
+
const WRITE_TIMEOUT_MS = 6e4;
|
|
34
|
+
const AI_TIMEOUT_MS = 18e4;
|
|
35
|
+
const SOURCE_TIMEOUT_MS = 6e5;
|
|
36
|
+
const RETRY_DELAYS_MS = [1500, 4e3, 8e3];
|
|
37
|
+
class StudyError extends Error {
|
|
38
|
+
constructor(kind, message) {
|
|
39
|
+
super(message);
|
|
40
|
+
__publicField(this, "kind");
|
|
41
|
+
this.name = "StudyError";
|
|
42
|
+
this.kind = kind;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
const UNKNOWN_ACTION_HINT = /unknown action|action not found|unsupported action|no handler|not a valid action/i;
|
|
46
|
+
const TIMEOUT_HINT = /timed out|timeout|ETIMEDOUT/i;
|
|
47
|
+
const TRANSIENT_HINT = /network request failed|failed to fetch|HTTP 50[234]|ECONNRESET|socket hang up/i;
|
|
48
|
+
const EMPTY_ANSWER_HINT = /did not return (cell content|a summary|an outline)|empty response/i;
|
|
49
|
+
const GONE_HINT = /notebook not found|no longer (in|available)/i;
|
|
50
|
+
const UNREADABLE_PAGE_HINT = /fetch failed \(\d+\)|no readable text|not a valid url|only http\(s\) urls/i;
|
|
51
|
+
const UNREADABLE_PDF_HINT = /pdf-co|extractable text for this pdf|extracted pdf text/i;
|
|
52
|
+
const UNREADABLE_DOCX_HINT = /yantra-docx|no text for this document/i;
|
|
53
|
+
const UNREADABLE_MEDIA_HINT = /transcri/i;
|
|
54
|
+
const INTERNAL_NAME = /\(?\b[A-Z][A-Z0-9]*(?:_[A-Z0-9]+){2,}\b\)?|\b(?:yantra|pdf|cdecli)-[a-z0-9-]+\b/g;
|
|
55
|
+
function cleanFailure(raw, action) {
|
|
56
|
+
return raw.replace(new RegExp(`^${action} failed( \\(HTTP \\d+\\))?:\\s*`), "").split("\n").map((line) => line.trim()).filter((line) => line && !/^(warning|executing):/i.test(line)).join(" ").replace(/^Executing:.*?\([A-Z0-9_]+\)\s*/, "").split("\u{1F4A1}")[0].trim().slice(0, 240);
|
|
57
|
+
}
|
|
58
|
+
function toStudyError(err, action) {
|
|
59
|
+
if (err instanceof StudyError) return err;
|
|
60
|
+
const raw = err instanceof Error ? err.message : String(err != null ? err : "");
|
|
61
|
+
const text = cleanFailure(raw, action);
|
|
62
|
+
if (UNKNOWN_ACTION_HINT.test(text)) {
|
|
63
|
+
return new StudyError("update", "This part of Study isn't available yet. Try again later.");
|
|
64
|
+
}
|
|
65
|
+
if (TIMEOUT_HINT.test(text)) {
|
|
66
|
+
return new StudyError("timeout", "Your tutor took too long to answer. Try again.");
|
|
67
|
+
}
|
|
68
|
+
if (TRANSIENT_HINT.test(raw)) {
|
|
69
|
+
return new StudyError("offline", "Could not reach Yantra. Check your connection, then try again.");
|
|
70
|
+
}
|
|
71
|
+
if (EMPTY_ANSWER_HINT.test(text)) {
|
|
72
|
+
return new StudyError("empty", "Your tutor didn't come back with an answer. Try again in a moment.");
|
|
73
|
+
}
|
|
74
|
+
if (GONE_HINT.test(text)) return new StudyError("gone", "This notebook is no longer available.");
|
|
75
|
+
if (UNREADABLE_PDF_HINT.test(text)) {
|
|
76
|
+
return new StudyError("unreadable", "Couldn't read the text in this PDF. If it's a scan, paste the text instead.");
|
|
77
|
+
}
|
|
78
|
+
if (UNREADABLE_DOCX_HINT.test(text)) {
|
|
79
|
+
return new StudyError("unreadable", "Couldn't read the text in this Word file. Save it as PDF, or paste the text.");
|
|
80
|
+
}
|
|
81
|
+
if (UNREADABLE_MEDIA_HINT.test(text)) {
|
|
82
|
+
return new StudyError("unreadable", "Couldn't transcribe this recording. Try a shorter clip, or paste a transcript.");
|
|
83
|
+
}
|
|
84
|
+
if (UNREADABLE_PAGE_HINT.test(text)) {
|
|
85
|
+
return new StudyError("unreadable", "Couldn't read that page. Some sites block readers: paste its text instead.");
|
|
86
|
+
}
|
|
87
|
+
const plain = text.replace(INTERNAL_NAME, "").replace(/\s{2,}/g, " ").trim();
|
|
88
|
+
return new StudyError("other", plain || "Something went wrong. Try again.");
|
|
89
|
+
}
|
|
90
|
+
function asRecord(value) {
|
|
91
|
+
return value && typeof value === "object" && !Array.isArray(value) ? value : null;
|
|
92
|
+
}
|
|
93
|
+
function layers(raw) {
|
|
94
|
+
var _a;
|
|
95
|
+
const out = [];
|
|
96
|
+
let current = asRecord(raw);
|
|
97
|
+
for (let depth = 0; current && depth < 6; depth += 1) {
|
|
98
|
+
out.push(current);
|
|
99
|
+
current = (_a = asRecord(current.data)) != null ? _a : asRecord(current.result);
|
|
100
|
+
}
|
|
101
|
+
return out;
|
|
102
|
+
}
|
|
103
|
+
function assertOk(raw) {
|
|
104
|
+
var _a;
|
|
105
|
+
const all = layers(raw);
|
|
106
|
+
for (const layer of all) {
|
|
107
|
+
if (layer.successful === false || layer.success === false || layer.ok === false) {
|
|
108
|
+
const reason = (_a = [layer.error, layer.message, layer.stderr].find((value) => typeof value === "string" && value.trim().length > 0)) != null ? _a : "The notebook action failed.";
|
|
109
|
+
throw new Error(reason);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
return all;
|
|
113
|
+
}
|
|
114
|
+
function find(all, pick) {
|
|
115
|
+
for (const layer of all) {
|
|
116
|
+
const hit = pick(layer);
|
|
117
|
+
if (hit !== void 0) return hit;
|
|
118
|
+
}
|
|
119
|
+
return void 0;
|
|
120
|
+
}
|
|
121
|
+
function notebookOf(all) {
|
|
122
|
+
const raw = find(all, (layer) => {
|
|
123
|
+
var _a;
|
|
124
|
+
return (_a = asRecord(layer.notebook)) != null ? _a : void 0;
|
|
125
|
+
});
|
|
126
|
+
const notebook = raw ? normalizeNotebook(raw) : null;
|
|
127
|
+
if (!notebook) throw new StudyError("other", "This notebook is no longer available.");
|
|
128
|
+
return notebook;
|
|
129
|
+
}
|
|
130
|
+
function cellOf(all) {
|
|
131
|
+
const raw = find(all, (layer) => {
|
|
132
|
+
var _a;
|
|
133
|
+
return (_a = asRecord(layer.cell)) != null ? _a : void 0;
|
|
134
|
+
});
|
|
135
|
+
const cell = raw ? normalizeCell(raw) : null;
|
|
136
|
+
if (!cell) throw new StudyError("other", "The notebook did not return the new cell.");
|
|
137
|
+
return cell;
|
|
138
|
+
}
|
|
139
|
+
const defaultSleep = (ms) => new Promise((resolve) => {
|
|
140
|
+
setTimeout(resolve, ms);
|
|
141
|
+
});
|
|
142
|
+
function createStudyClient(exec, options = {}) {
|
|
143
|
+
var _a;
|
|
144
|
+
const sleep = (_a = options.sleep) != null ? _a : defaultSleep;
|
|
145
|
+
const run = async (action, params, timeoutMs, retry = false) => {
|
|
146
|
+
let attempt = 0;
|
|
147
|
+
for (; ; ) {
|
|
148
|
+
try {
|
|
149
|
+
return assertOk(await exec(NOTEBOOK, action, params, {
|
|
150
|
+
timeoutMs
|
|
151
|
+
}));
|
|
152
|
+
} catch (err) {
|
|
153
|
+
const raw = err instanceof Error ? err.message : String(err != null ? err : "");
|
|
154
|
+
const again = retry && attempt < RETRY_DELAYS_MS.length && TRANSIENT_HINT.test(raw);
|
|
155
|
+
if (!again) throw toStudyError(err, action);
|
|
156
|
+
}
|
|
157
|
+
await sleep(RETRY_DELAYS_MS[attempt]);
|
|
158
|
+
attempt += 1;
|
|
159
|
+
}
|
|
160
|
+
};
|
|
161
|
+
return {
|
|
162
|
+
async list() {
|
|
163
|
+
var _a2;
|
|
164
|
+
const all = await run(NOTEBOOK_ACTIONS.list, {}, READ_TIMEOUT_MS, true);
|
|
165
|
+
const rows = (_a2 = find(all, (layer) => Array.isArray(layer.notebooks) ? layer.notebooks : void 0)) != null ? _a2 : [];
|
|
166
|
+
return rows.map(normalizeSummary).filter((row) => row !== null).sort((a, b) => b.updatedAt.localeCompare(a.updatedAt));
|
|
167
|
+
},
|
|
168
|
+
async get(notebookId) {
|
|
169
|
+
return notebookOf(await run(NOTEBOOK_ACTIONS.get, {
|
|
170
|
+
notebookId
|
|
171
|
+
}, READ_TIMEOUT_MS, true));
|
|
172
|
+
},
|
|
173
|
+
/** `seed` has the tutor open the notebook with an outline of the topic. */
|
|
174
|
+
async create(input) {
|
|
175
|
+
var _a2;
|
|
176
|
+
const params = {
|
|
177
|
+
title: input.title
|
|
178
|
+
};
|
|
179
|
+
if ((_a2 = input.topic) == null ? void 0 : _a2.trim()) params.topic = input.topic.trim();
|
|
180
|
+
if (input.seed) params.seed = true;
|
|
181
|
+
if (input.model) params.model = input.model;
|
|
182
|
+
return notebookOf(await run(NOTEBOOK_ACTIONS.create, params, input.seed ? AI_TIMEOUT_MS : WRITE_TIMEOUT_MS));
|
|
183
|
+
},
|
|
184
|
+
async remove(notebookId) {
|
|
185
|
+
await run(NOTEBOOK_ACTIONS.remove, {
|
|
186
|
+
notebookId
|
|
187
|
+
}, WRITE_TIMEOUT_MS);
|
|
188
|
+
},
|
|
189
|
+
/** A note in the person's own words. */
|
|
190
|
+
async addNote(notebookId, content) {
|
|
191
|
+
const all = await run(NOTEBOOK_ACTIONS.addCell, {
|
|
192
|
+
notebookId,
|
|
193
|
+
content
|
|
194
|
+
}, WRITE_TIMEOUT_MS);
|
|
195
|
+
return {
|
|
196
|
+
notebook: notebookOf(all),
|
|
197
|
+
cell: cellOf(all)
|
|
198
|
+
};
|
|
199
|
+
},
|
|
200
|
+
/** The tutor answers `prompt` from the notebook and its sources, as a new cell. */
|
|
201
|
+
async ask(notebookId, prompt, model) {
|
|
202
|
+
const params = {
|
|
203
|
+
notebookId,
|
|
204
|
+
prompt
|
|
205
|
+
};
|
|
206
|
+
if (model) params.model = model;
|
|
207
|
+
const all = await run(NOTEBOOK_ACTIONS.addCell, params, AI_TIMEOUT_MS);
|
|
208
|
+
return {
|
|
209
|
+
notebook: notebookOf(all),
|
|
210
|
+
cell: cellOf(all)
|
|
211
|
+
};
|
|
212
|
+
},
|
|
213
|
+
async updateCell(notebookId, cellId, content) {
|
|
214
|
+
return notebookOf(await run(NOTEBOOK_ACTIONS.updateCell, {
|
|
215
|
+
notebookId,
|
|
216
|
+
cellId,
|
|
217
|
+
content
|
|
218
|
+
}, WRITE_TIMEOUT_MS));
|
|
219
|
+
},
|
|
220
|
+
async deleteCell(notebookId, cellId) {
|
|
221
|
+
return notebookOf(await run(NOTEBOOK_ACTIONS.deleteCell, {
|
|
222
|
+
notebookId,
|
|
223
|
+
cellId
|
|
224
|
+
}, WRITE_TIMEOUT_MS));
|
|
225
|
+
},
|
|
226
|
+
async summarize(notebookId, model) {
|
|
227
|
+
const params = {
|
|
228
|
+
notebookId
|
|
229
|
+
};
|
|
230
|
+
if (model) params.model = model;
|
|
231
|
+
const all = await run(NOTEBOOK_ACTIONS.summarize, params, AI_TIMEOUT_MS);
|
|
232
|
+
return {
|
|
233
|
+
notebook: notebookOf(all),
|
|
234
|
+
cell: cellOf(all)
|
|
235
|
+
};
|
|
236
|
+
},
|
|
237
|
+
async exportHtml(notebookId) {
|
|
238
|
+
const all = await run(NOTEBOOK_ACTIONS.exportHtml, {
|
|
239
|
+
notebookId
|
|
240
|
+
}, READ_TIMEOUT_MS, true);
|
|
241
|
+
const html = find(all, (layer) => typeof layer.html === "string" && layer.html ? layer.html : void 0);
|
|
242
|
+
if (!html) throw new StudyError("other", "The export came back empty. Try again.");
|
|
243
|
+
const url = find(all, (layer) => typeof layer.url === "string" && layer.url ? layer.url : void 0);
|
|
244
|
+
const title = find(all, (layer) => typeof layer.title === "string" && layer.title ? layer.title : void 0);
|
|
245
|
+
return {
|
|
246
|
+
html,
|
|
247
|
+
url: url != null ? url : null,
|
|
248
|
+
title: title != null ? title : "Notebook"
|
|
249
|
+
};
|
|
250
|
+
},
|
|
251
|
+
/**
|
|
252
|
+
* Read a source into the notebook: a web page, a hosted file (PDF, DOCX,
|
|
253
|
+
* audio, video, text) by `url`, or pasted `text`.
|
|
254
|
+
*/
|
|
255
|
+
async addSource(notebookId, input) {
|
|
256
|
+
var _a2;
|
|
257
|
+
const params = __spreadValues({
|
|
258
|
+
notebookId
|
|
259
|
+
}, input);
|
|
260
|
+
if (!((_a2 = input.title) == null ? void 0 : _a2.trim())) delete params.title;
|
|
261
|
+
const all = await run(NOTEBOOK_ACTIONS.addSource, params, SOURCE_TIMEOUT_MS);
|
|
262
|
+
const rawSource = find(all, (layer) => {
|
|
263
|
+
var _a3;
|
|
264
|
+
return (_a3 = asRecord(layer.source)) != null ? _a3 : void 0;
|
|
265
|
+
});
|
|
266
|
+
return {
|
|
267
|
+
notebook: notebookOf(all),
|
|
268
|
+
source: rawSource ? normalizeSource(rawSource) : null
|
|
269
|
+
};
|
|
270
|
+
},
|
|
271
|
+
async deleteSource(notebookId, sourceId) {
|
|
272
|
+
return notebookOf(await run(NOTEBOOK_ACTIONS.deleteSource, {
|
|
273
|
+
notebookId,
|
|
274
|
+
sourceId
|
|
275
|
+
}, WRITE_TIMEOUT_MS));
|
|
276
|
+
}
|
|
277
|
+
};
|
|
278
|
+
}export{NOTEBOOK,NOTEBOOK_ACTIONS,StudyError,createStudyClient,toStudyError};//# sourceMappingURL=studyClient.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"studyClient.js","sources":["../../../src/features/study/studyClient.ts"],"sourcesContent":["/**\n * yantra-notebook actions for native Study, over the agent's exec stream.\n *\n * Same store as the web Study surface (yantra-surface notebooklm): notebooks\n * are per user, keyed by the session token, so nothing here names an org or a\n * credential. Sources go through the connector's own ingest (ADD_SOURCE), which\n * reads web pages, PDFs, Word files and transcribes audio/video server side, so\n * every later answer is grounded in them.\n */\nimport type { RemoteConnectorExec } from '../canvas/videoEditor/remoteMediaClient';\nimport { normalizeCell, normalizeNotebook, normalizeSource, normalizeSummary } from './studyNormalize';\nimport type { StudyCell, StudyExport, StudyNotebook, StudyNotebookSummary, StudySource } from './types';\n\nexport const NOTEBOOK = 'yantra-notebook';\n\nexport const NOTEBOOK_ACTIONS = {\n list: 'YANTRA_NOTEBOOK_LIST',\n get: 'YANTRA_NOTEBOOK_GET',\n create: 'YANTRA_NOTEBOOK_CREATE',\n remove: 'YANTRA_NOTEBOOK_DELETE',\n addCell: 'YANTRA_NOTEBOOK_ADD_CELL',\n updateCell: 'YANTRA_NOTEBOOK_UPDATE_CELL',\n deleteCell: 'YANTRA_NOTEBOOK_DELETE_CELL',\n summarize: 'YANTRA_NOTEBOOK_SUMMARIZE',\n exportHtml: 'YANTRA_NOTEBOOK_EXPORT',\n addSource: 'YANTRA_NOTEBOOK_ADD_SOURCE',\n deleteSource: 'YANTRA_NOTEBOOK_DELETE_SOURCE',\n} as const;\n\nconst READ_TIMEOUT_MS = 60_000;\nconst WRITE_TIMEOUT_MS = 60_000;\n/** A tutor answer, an outline or a summary is one model call over the notebook. */\nconst AI_TIMEOUT_MS = 180_000;\n/** A PDF goes through a parser and a lecture recording through transcription. */\nconst SOURCE_TIMEOUT_MS = 600_000;\n\n/** Backoff for a read the sandbox dropped while waking up (nothing ran server side). */\nconst RETRY_DELAYS_MS = [1_500, 4_000, 8_000];\n\nexport type StudyErrorKind = 'update' | 'timeout' | 'offline' | 'empty' | 'unreadable' | 'gone' | 'other';\n\n/** A failure the screen can explain in words a person can act on. */\nexport class StudyError extends Error {\n readonly kind: StudyErrorKind;\n\n constructor(kind: StudyErrorKind, message: string) {\n super(message);\n this.name = 'StudyError';\n this.kind = kind;\n }\n}\n\nconst UNKNOWN_ACTION_HINT = /unknown action|action not found|unsupported action|no handler|not a valid action/i;\nconst TIMEOUT_HINT = /timed out|timeout|ETIMEDOUT/i;\n/** The request never reached a running connector: safe to send a read again. */\nconst TRANSIENT_HINT = /network request failed|failed to fetch|HTTP 50[234]|ECONNRESET|socket hang up/i;\n/** The model answered with nothing (the connector's \"did not return …\" family). */\nconst EMPTY_ANSWER_HINT = /did not return (cell content|a summary|an outline)|empty response/i;\nconst GONE_HINT = /notebook not found|no longer (in|available)/i;\n/** A page or file the connector could not turn into text. */\nconst UNREADABLE_PAGE_HINT = /fetch failed \\(\\d+\\)|no readable text|not a valid url|only http\\(s\\) urls/i;\nconst UNREADABLE_PDF_HINT = /pdf-co|extractable text for this pdf|extracted pdf text/i;\nconst UNREADABLE_DOCX_HINT = /yantra-docx|no text for this document/i;\nconst UNREADABLE_MEDIA_HINT = /transcri/i;\n/** Internal names that must never reach the screen: action slugs and connector ids. */\nconst INTERNAL_NAME = /\\(?\\b[A-Z][A-Z0-9]*(?:_[A-Z0-9]+){2,}\\b\\)?|\\b(?:yantra|pdf|cdecli)-[a-z0-9-]+\\b/g;\n\n/**\n * The connector's reason without the transport's wrapping: the HTTP prefix,\n * cdecli's `Executing: …` banner and warnings, and its trailing 💡 hint, which\n * is written for operators.\n */\nfunction cleanFailure(raw: string, action: string): string {\n return raw\n .replace(new RegExp(`^${action} failed( \\\\(HTTP \\\\d+\\\\))?:\\\\s*`), '')\n .split('\\n')\n .map((line) => line.trim())\n .filter((line) => line && !/^(warning|executing):/i.test(line))\n .join(' ')\n .replace(/^Executing:.*?\\([A-Z0-9_]+\\)\\s*/, '')\n .split('💡')[0]\n .trim()\n .slice(0, 240);\n}\n\nexport function toStudyError(err: unknown, action: string): StudyError {\n if (err instanceof StudyError) return err;\n const raw = err instanceof Error ? err.message : String(err ?? '');\n const text = cleanFailure(raw, action);\n if (UNKNOWN_ACTION_HINT.test(text)) {\n return new StudyError('update', \"This part of Study isn't available yet. Try again later.\");\n }\n if (TIMEOUT_HINT.test(text)) {\n return new StudyError('timeout', 'Your tutor took too long to answer. Try again.');\n }\n if (TRANSIENT_HINT.test(raw)) {\n return new StudyError('offline', 'Could not reach Yantra. Check your connection, then try again.');\n }\n if (EMPTY_ANSWER_HINT.test(text)) {\n return new StudyError('empty', \"Your tutor didn't come back with an answer. Try again in a moment.\");\n }\n if (GONE_HINT.test(text)) return new StudyError('gone', 'This notebook is no longer available.');\n if (UNREADABLE_PDF_HINT.test(text)) {\n return new StudyError(\n 'unreadable',\n \"Couldn't read the text in this PDF. If it's a scan, paste the text instead.\",\n );\n }\n if (UNREADABLE_DOCX_HINT.test(text)) {\n return new StudyError(\n 'unreadable',\n \"Couldn't read the text in this Word file. Save it as PDF, or paste the text.\",\n );\n }\n if (UNREADABLE_MEDIA_HINT.test(text)) {\n return new StudyError(\n 'unreadable',\n \"Couldn't transcribe this recording. Try a shorter clip, or paste a transcript.\",\n );\n }\n if (UNREADABLE_PAGE_HINT.test(text)) {\n return new StudyError(\n 'unreadable',\n \"Couldn't read that page. Some sites block readers: paste its text instead.\",\n );\n }\n const plain = text\n .replace(INTERNAL_NAME, '')\n .replace(/\\s{2,}/g, ' ')\n .trim();\n return new StudyError('other', plain || 'Something went wrong. Try again.');\n}\n\ntype Json = Record<string, unknown>;\n\nfunction asRecord(value: unknown): Json | null {\n return value && typeof value === 'object' && !Array.isArray(value) ? (value as Json) : null;\n}\n\n/** The envelope's layers: exec result -> ApiResult -> `data` -> the action's own object. */\nfunction layers(raw: unknown): Json[] {\n const out: Json[] = [];\n let current = asRecord(raw);\n for (let depth = 0; current && depth < 6; depth += 1) {\n out.push(current);\n current = asRecord(current.data) ?? asRecord(current.result);\n }\n return out;\n}\n\nfunction assertOk(raw: unknown): Json[] {\n const all = layers(raw);\n for (const layer of all) {\n if (layer.successful === false || layer.success === false || layer.ok === false) {\n const reason =\n [layer.error, layer.message, layer.stderr].find(\n (value): value is string => typeof value === 'string' && value.trim().length > 0,\n ) ?? 'The notebook action failed.';\n throw new Error(reason);\n }\n }\n return all;\n}\n\nfunction find<T>(all: Json[], pick: (layer: Json) => T | undefined): T | undefined {\n for (const layer of all) {\n const hit = pick(layer);\n if (hit !== undefined) return hit;\n }\n return undefined;\n}\n\nfunction notebookOf(all: Json[]): StudyNotebook {\n const raw = find(all, (layer) => asRecord(layer.notebook) ?? undefined);\n const notebook = raw ? normalizeNotebook(raw) : null;\n if (!notebook) throw new StudyError('other', 'This notebook is no longer available.');\n return notebook;\n}\n\nfunction cellOf(all: Json[]): StudyCell {\n const raw = find(all, (layer) => asRecord(layer.cell) ?? undefined);\n const cell = raw ? normalizeCell(raw) : null;\n if (!cell) throw new StudyError('other', 'The notebook did not return the new cell.');\n return cell;\n}\n\nexport interface StudyClientOptions {\n /** Waits between read retries; tests pass a no-op. */\n sleep?: (ms: number) => Promise<void>;\n}\n\nconst defaultSleep = (ms: number) =>\n new Promise<void>((resolve) => {\n setTimeout(resolve, ms);\n });\n\nexport function createStudyClient(exec: RemoteConnectorExec, options: StudyClientOptions = {}) {\n const sleep = options.sleep ?? defaultSleep;\n\n const run = async (action: string, params: Json, timeoutMs: number, retry = false): Promise<Json[]> => {\n let attempt = 0;\n for (;;) {\n try {\n return assertOk(await exec(NOTEBOOK, action, params, { timeoutMs }));\n } catch (err) {\n const raw = err instanceof Error ? err.message : String(err ?? '');\n // Only reads go again: a retried write could add the same cell twice.\n const again = retry && attempt < RETRY_DELAYS_MS.length && TRANSIENT_HINT.test(raw);\n if (!again) throw toStudyError(err, action);\n }\n await sleep(RETRY_DELAYS_MS[attempt]);\n attempt += 1;\n }\n };\n\n return {\n async list(): Promise<StudyNotebookSummary[]> {\n const all = await run(NOTEBOOK_ACTIONS.list, {}, READ_TIMEOUT_MS, true);\n const rows = find(all, (layer) => (Array.isArray(layer.notebooks) ? layer.notebooks : undefined)) ?? [];\n return rows\n .map(normalizeSummary)\n .filter((row): row is StudyNotebookSummary => row !== null)\n .sort((a, b) => b.updatedAt.localeCompare(a.updatedAt));\n },\n\n async get(notebookId: string): Promise<StudyNotebook> {\n return notebookOf(await run(NOTEBOOK_ACTIONS.get, { notebookId }, READ_TIMEOUT_MS, true));\n },\n\n /** `seed` has the tutor open the notebook with an outline of the topic. */\n async create(input: { title: string; topic?: string; seed?: boolean; model?: string }): Promise<StudyNotebook> {\n const params: Json = { title: input.title };\n if (input.topic?.trim()) params.topic = input.topic.trim();\n if (input.seed) params.seed = true;\n if (input.model) params.model = input.model;\n return notebookOf(\n await run(NOTEBOOK_ACTIONS.create, params, input.seed ? AI_TIMEOUT_MS : WRITE_TIMEOUT_MS),\n );\n },\n\n async remove(notebookId: string): Promise<void> {\n await run(NOTEBOOK_ACTIONS.remove, { notebookId }, WRITE_TIMEOUT_MS);\n },\n\n /** A note in the person's own words. */\n async addNote(notebookId: string, content: string): Promise<{ notebook: StudyNotebook; cell: StudyCell }> {\n const all = await run(NOTEBOOK_ACTIONS.addCell, { notebookId, content }, WRITE_TIMEOUT_MS);\n return { notebook: notebookOf(all), cell: cellOf(all) };\n },\n\n /** The tutor answers `prompt` from the notebook and its sources, as a new cell. */\n async ask(\n notebookId: string,\n prompt: string,\n model?: string,\n ): Promise<{ notebook: StudyNotebook; cell: StudyCell }> {\n const params: Json = { notebookId, prompt };\n if (model) params.model = model;\n const all = await run(NOTEBOOK_ACTIONS.addCell, params, AI_TIMEOUT_MS);\n return { notebook: notebookOf(all), cell: cellOf(all) };\n },\n\n async updateCell(notebookId: string, cellId: string, content: string): Promise<StudyNotebook> {\n return notebookOf(\n await run(NOTEBOOK_ACTIONS.updateCell, { notebookId, cellId, content }, WRITE_TIMEOUT_MS),\n );\n },\n\n async deleteCell(notebookId: string, cellId: string): Promise<StudyNotebook> {\n return notebookOf(await run(NOTEBOOK_ACTIONS.deleteCell, { notebookId, cellId }, WRITE_TIMEOUT_MS));\n },\n\n async summarize(notebookId: string, model?: string): Promise<{ notebook: StudyNotebook; cell: StudyCell }> {\n const params: Json = { notebookId };\n if (model) params.model = model;\n const all = await run(NOTEBOOK_ACTIONS.summarize, params, AI_TIMEOUT_MS);\n return { notebook: notebookOf(all), cell: cellOf(all) };\n },\n\n async exportHtml(notebookId: string): Promise<StudyExport> {\n const all = await run(NOTEBOOK_ACTIONS.exportHtml, { notebookId }, READ_TIMEOUT_MS, true);\n const html = find(all, (layer) => (typeof layer.html === 'string' && layer.html ? layer.html : undefined));\n if (!html) throw new StudyError('other', 'The export came back empty. Try again.');\n const url = find(all, (layer) => (typeof layer.url === 'string' && layer.url ? layer.url : undefined));\n const title = find(all, (layer) =>\n typeof layer.title === 'string' && layer.title ? layer.title : undefined,\n );\n return { html, url: url ?? null, title: title ?? 'Notebook' };\n },\n\n /**\n * Read a source into the notebook: a web page, a hosted file (PDF, DOCX,\n * audio, video, text) by `url`, or pasted `text`.\n */\n async addSource(\n notebookId: string,\n input: { url: string; title?: string } | { text: string; title?: string },\n ): Promise<{ notebook: StudyNotebook; source: StudySource | null }> {\n const params: Json = { notebookId, ...input };\n if (!input.title?.trim()) delete params.title;\n const all = await run(NOTEBOOK_ACTIONS.addSource, params, SOURCE_TIMEOUT_MS);\n const rawSource = find(all, (layer) => asRecord(layer.source) ?? undefined);\n return { notebook: notebookOf(all), source: rawSource ? normalizeSource(rawSource) : null };\n },\n\n async deleteSource(notebookId: string, sourceId: string): Promise<StudyNotebook> {\n return notebookOf(await run(NOTEBOOK_ACTIONS.deleteSource, { notebookId, sourceId }, WRITE_TIMEOUT_MS));\n },\n };\n}\n\nexport type StudyClient = ReturnType<typeof createStudyClient>;\n"],"names":["_a"],"mappings":";;;;;;;;;;;;;;;;;AAYO,MAAM,QAAW,GAAA;AACjB,MAAM,gBAAmB,GAAA;AAAA,EAC9B,IAAM,EAAA,sBAAA;AAAA,EACN,GAAK,EAAA,qBAAA;AAAA,EACL,MAAQ,EAAA,wBAAA;AAAA,EACR,MAAQ,EAAA,wBAAA;AAAA,EACR,OAAS,EAA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U,WAAW,GAAG,CAAA;AAAA,QACxB,MAAQ,EAAA,SAAA,GAAY,eAAgB,CAAA,SAAS,CAAI,GAAA;AAAA,OACnD;AAAA,KACF;AAAA,IACA,MAAM,YAAa,CAAA,UAAA,EAAoB,QAA0C,EAAA;AAC/E,MAAA,OAAO,UAAW,CAAA,MAAM,GAAI,CAAA,gBAAA,CAAiB,YAAc,EAAA;AAAA,QACzD,UAAA;AAAA,QACA;AAAA,OACF,EAAG,gBAAgB,CAAC,CAAA;AAAA;AACtB,GACF;AACF"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
const HEADER_PREFIX = "[study context:";
|
|
2
|
+
function clean(value) {
|
|
3
|
+
return value.replace(/[;[\]\n\r]+/g, " ").replace(/\s+/g, " ").trim();
|
|
4
|
+
}
|
|
5
|
+
function studyContextHeader(notebook, orgName) {
|
|
6
|
+
const parts = ["surface=study", "connector=yantra-notebook"];
|
|
7
|
+
if (notebook) {
|
|
8
|
+
parts.push(`notebook=${clean(notebook.title) || "untitled"}`, `notebook_id=${notebook.id}`);
|
|
9
|
+
if (notebook.topic) parts.push(`topic=${clean(notebook.topic)}`);
|
|
10
|
+
parts.push(`sources=${notebook.sources.length}`, `cells=${notebook.cells.length}`);
|
|
11
|
+
} else {
|
|
12
|
+
parts.push("notebook=none (offer to start one from their notes, a link, or a file)");
|
|
13
|
+
}
|
|
14
|
+
if (orgName) parts.push(`org=${orgName}`);
|
|
15
|
+
return `${HEADER_PREFIX} ${parts.join("; ")}]`;
|
|
16
|
+
}
|
|
17
|
+
function withStudyContext(text, notebook, orgName) {
|
|
18
|
+
return `${studyContextHeader(notebook, orgName)}
|
|
19
|
+
${text}`;
|
|
20
|
+
}
|
|
21
|
+
function stripStudyContext(content) {
|
|
22
|
+
if (!content.startsWith(HEADER_PREFIX)) return content;
|
|
23
|
+
const end = content.indexOf("]");
|
|
24
|
+
return end < 0 ? content : content.slice(end + 1).replace(/^\s+/, "");
|
|
25
|
+
}export{stripStudyContext,studyContextHeader,withStudyContext};//# sourceMappingURL=studyContext.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"studyContext.js","sources":["../../../src/features/study/studyContext.ts"],"sourcesContent":["/**\n * The one-line context the Study agent gets on the first turn of a thread, so\n * \"quiz me on chapter 2\" means the notebook on screen: its id lets the agent\n * read it through yantra-notebook. Same shape as the Inbox's `[inbox context: …]`\n * line. It is for the agent only: the transcript shows the person's own words.\n */\nimport type { StudyNotebook } from './types';\n\nconst HEADER_PREFIX = '[study context:';\n\n/** Context values sit inside `key=value; …]`, so they must not carry the separators. */\nfunction clean(value: string): string {\n return value\n .replace(/[;[\\]\\n\\r]+/g, ' ')\n .replace(/\\s+/g, ' ')\n .trim();\n}\n\nexport function studyContextHeader(notebook: StudyNotebook | null, orgName?: string): string {\n const parts = ['surface=study', 'connector=yantra-notebook'];\n if (notebook) {\n parts.push(`notebook=${clean(notebook.title) || 'untitled'}`, `notebook_id=${notebook.id}`);\n if (notebook.topic) parts.push(`topic=${clean(notebook.topic)}`);\n parts.push(`sources=${notebook.sources.length}`, `cells=${notebook.cells.length}`);\n } else {\n parts.push('notebook=none (offer to start one from their notes, a link, or a file)');\n }\n if (orgName) parts.push(`org=${orgName}`);\n return `${HEADER_PREFIX} ${parts.join('; ')}]`;\n}\n\nexport function withStudyContext(text: string, notebook: StudyNotebook | null, orgName?: string): string {\n return `${studyContextHeader(notebook, orgName)}\\n${text}`;\n}\n\n/** The person's words without a leading context header. */\nexport function stripStudyContext(content: string): string {\n if (!content.startsWith(HEADER_PREFIX)) return content;\n const end = content.indexOf(']');\n return end < 0 ? content : content.slice(end + 1).replace(/^\\s+/, '');\n}\n"],"names":[],"mappings":"AAOA,MAAM,aAAgB,GAAA,iBAAA;AAGtB,SAAS,MAAM,KAAuB,EAAA;AACpC,EAAO,OAAA,KAAA,CAAM,QAAQ,cAAgB,EAAA,GAAG,EAAE,OAAQ,CAAA,MAAA,EAAQ,GAAG,CAAA,CAAE,IAAK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A;AAC/B,EAAO,OAAA,GAAA,GAAM,CAAI,GAAA,OAAA,GAAU,OAAQ,CAAA,KAAA,CAAM,MAAM,CAAC,CAAA,CAAE,OAAQ,CAAA,MAAA,EAAQ,EAAE,CAAA;AACtE"}
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import {deriveAgentEndpoint}from'../canvas/videoEditor/remoteMediaClient.js';const MAX_STUDY_FILE_BYTES = 1e8;
|
|
2
|
+
const MAX_TEXT_FILE_BYTES = 4e6;
|
|
3
|
+
const STUDY_FILE_TYPES_LABEL = "PDF, Word, text, audio or video";
|
|
4
|
+
const TEXT_EXT = /\.(txt|md|markdown|csv|json|tex|xml|ya?ml|rtf|[jt]sx?|py|java|c|cpp|h|rs|go|swift|kt|rb|sql)$/i;
|
|
5
|
+
const UPLOAD_EXT = /\.(pdf|docx|html?|mp3|wav|m4a|aac|ogg|opus|flac|wma|mp4|mov|mkv|webm|avi|m4v)$/i;
|
|
6
|
+
function planStudyFile(file) {
|
|
7
|
+
var _a, _b;
|
|
8
|
+
const name = file.name.trim();
|
|
9
|
+
const lower = name.toLowerCase();
|
|
10
|
+
if (typeof file.size === "number" && file.size > MAX_STUDY_FILE_BYTES) {
|
|
11
|
+
return {
|
|
12
|
+
kind: "reject",
|
|
13
|
+
reason: `${name} is over ${MAX_STUDY_FILE_BYTES / 1e6} MB.`
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
if (TEXT_EXT.test(lower)) {
|
|
17
|
+
if (typeof file.size === "number" && file.size > MAX_TEXT_FILE_BYTES) {
|
|
18
|
+
return {
|
|
19
|
+
kind: "reject",
|
|
20
|
+
reason: `${name} is too long to read as one source. Split it, then try again.`
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
return {
|
|
24
|
+
kind: "text"
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
if (UPLOAD_EXT.test(lower)) return {
|
|
28
|
+
kind: "upload"
|
|
29
|
+
};
|
|
30
|
+
if (/\.doc$/.test(lower)) return {
|
|
31
|
+
kind: "reject",
|
|
32
|
+
reason: `${name}: save it as .docx or PDF, then add it again.`
|
|
33
|
+
};
|
|
34
|
+
if (/\.(pages|key|numbers|pptx?|xlsx?)$/.test(lower)) {
|
|
35
|
+
return {
|
|
36
|
+
kind: "reject",
|
|
37
|
+
reason: `${name}: export it as PDF, then add it again.`
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
if (/^image\//.test((_a = file.mimeType) != null ? _a : "") || /\.(png|jpe?g|heic|gif|webp)$/.test(lower)) {
|
|
41
|
+
return {
|
|
42
|
+
kind: "reject",
|
|
43
|
+
reason: `${name}: photos can't be read as notes yet. Add a PDF or paste the text.`
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
if (/^text\//.test((_b = file.mimeType) != null ? _b : "")) return {
|
|
47
|
+
kind: "text"
|
|
48
|
+
};
|
|
49
|
+
return {
|
|
50
|
+
kind: "reject",
|
|
51
|
+
reason: `${name}: Study reads ${STUDY_FILE_TYPES_LABEL} files.`
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
function stripRtf(raw) {
|
|
55
|
+
if (!raw.startsWith("{\\rtf")) return raw;
|
|
56
|
+
return raw.replace(/\{\\\*?[^{}]*\}/g, " ").replace(/\\'[0-9a-fA-F]{2}/g, " ").replace(/\\[a-zA-Z]+-?\d* ?/g, " ").replace(/[{}]/g, " ").replace(/[ \t]+/g, " ").replace(/\n{3,}/g, "\n\n").trim();
|
|
57
|
+
}
|
|
58
|
+
const PICKER_MISSING = "The file picker is not in this app build. Paste the text or share a link instead.";
|
|
59
|
+
function loadDocumentPicker() {
|
|
60
|
+
var _a, _b;
|
|
61
|
+
try {
|
|
62
|
+
const core = require("expo-modules-core");
|
|
63
|
+
const native = (_a = core.requireOptionalNativeModule) == null ? void 0 : _a.call(core, "ExpoDocumentPicker");
|
|
64
|
+
const getDocument = (_b = native == null ? void 0 : native.getDocumentAsync) == null ? void 0 : _b.bind(native);
|
|
65
|
+
if (getDocument) {
|
|
66
|
+
return {
|
|
67
|
+
getDocumentAsync: (options) => {
|
|
68
|
+
var _a2, _b2, _c;
|
|
69
|
+
return getDocument({
|
|
70
|
+
type: Array.isArray(options.type) ? options.type : [(_a2 = options.type) != null ? _a2 : "*/*"],
|
|
71
|
+
multiple: (_b2 = options.multiple) != null ? _b2 : false,
|
|
72
|
+
copyToCacheDirectory: (_c = options.copyToCacheDirectory) != null ? _c : true
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
return require("expo-document-picker");
|
|
78
|
+
} catch (err) {
|
|
79
|
+
const msg = err instanceof Error ? err.message : String(err != null ? err : "");
|
|
80
|
+
if (/Cannot find native module|ExpoDocumentPicker|Cannot find module/i.test(msg)) throw new Error(PICKER_MISSING);
|
|
81
|
+
throw err;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
async function pickStudyFiles() {
|
|
85
|
+
var _a;
|
|
86
|
+
const picker = loadDocumentPicker();
|
|
87
|
+
const result = await picker.getDocumentAsync({
|
|
88
|
+
type: "*/*",
|
|
89
|
+
multiple: true,
|
|
90
|
+
copyToCacheDirectory: true
|
|
91
|
+
});
|
|
92
|
+
if (!result || result.canceled || result.type === "cancel") return [];
|
|
93
|
+
const assets = ((_a = result.assets) == null ? void 0 : _a.length) ? result.assets : [result];
|
|
94
|
+
return assets.map((asset) => {
|
|
95
|
+
var _a2, _b;
|
|
96
|
+
return {
|
|
97
|
+
uri: ((_a2 = asset.uri) != null ? _a2 : "").trim(),
|
|
98
|
+
name: ((_b = asset.name) != null ? _b : "").trim() || "file",
|
|
99
|
+
mimeType: asset.mimeType,
|
|
100
|
+
size: asset.size
|
|
101
|
+
};
|
|
102
|
+
}).filter((file) => file.uri);
|
|
103
|
+
}
|
|
104
|
+
async function readStudyTextFile(file) {
|
|
105
|
+
var _a, _b;
|
|
106
|
+
const fs = require("expo-file-system");
|
|
107
|
+
if (typeof fs.readAsStringAsync !== "function") {
|
|
108
|
+
throw new Error(`Could not read ${file.name} on this phone. Paste its text instead.`);
|
|
109
|
+
}
|
|
110
|
+
let raw;
|
|
111
|
+
try {
|
|
112
|
+
raw = await fs.readAsStringAsync(file.uri, {
|
|
113
|
+
encoding: (_b = (_a = fs.EncodingType) == null ? void 0 : _a.UTF8) != null ? _b : "utf8"
|
|
114
|
+
});
|
|
115
|
+
} catch (e) {
|
|
116
|
+
throw new Error(`Could not read ${file.name}. Paste its text instead.`);
|
|
117
|
+
}
|
|
118
|
+
const text = stripRtf(raw).replace(/\u00a0/g, " ").trim();
|
|
119
|
+
if (!text) throw new Error(`${file.name} is empty.`);
|
|
120
|
+
return text;
|
|
121
|
+
}
|
|
122
|
+
async function uploadStudyFile(token, indexUrl, file) {
|
|
123
|
+
const agent = deriveAgentEndpoint(indexUrl);
|
|
124
|
+
const blob = await (await fetch(file.uri)).blob();
|
|
125
|
+
const resp = await fetch(`${agent}/v1/files/upload?filename=${encodeURIComponent(file.name)}`, {
|
|
126
|
+
method: "POST",
|
|
127
|
+
headers: {
|
|
128
|
+
"content-type": file.mimeType || blob.type || "application/octet-stream",
|
|
129
|
+
authorization: `Bearer ${token}`
|
|
130
|
+
},
|
|
131
|
+
body: blob
|
|
132
|
+
});
|
|
133
|
+
if (!resp.ok) {
|
|
134
|
+
const detail = (await resp.text().catch(() => "")).slice(0, 160);
|
|
135
|
+
throw new Error(`Could not upload ${file.name} (HTTP ${resp.status})${detail ? `: ${detail}` : ""}`);
|
|
136
|
+
}
|
|
137
|
+
const result = await resp.json();
|
|
138
|
+
if (!result.url) throw new Error(`Could not upload ${file.name}: the store returned no link.`);
|
|
139
|
+
return result.url;
|
|
140
|
+
}export{MAX_STUDY_FILE_BYTES,STUDY_FILE_TYPES_LABEL,pickStudyFiles,planStudyFile,readStudyTextFile,uploadStudyFile};//# sourceMappingURL=studyFiles.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"studyFiles.js","sources":["../../../src/features/study/studyFiles.ts"],"sourcesContent":["/**\n * Files a person brings to Study, from the phone's file picker to a notebook\n * source. Text files are read on the phone and sent as text; documents and\n * recordings are uploaded to the agent's store and read there by the notebook\n * connector (a PDF through its parser, a Word file through yantra-docx, audio and\n * video through transcription). It picks the reader from the file extension,\n * so every upload keeps its own.\n */\nimport { deriveAgentEndpoint } from '../canvas/videoEditor/remoteMediaClient';\nimport type { StudyPickedFile } from './types';\n\n/** Upload ceiling per file: a long lecture recording fits, a whole course archive does not. */\nexport const MAX_STUDY_FILE_BYTES = 100_000_000;\n/** Text read on the phone; anything larger is too big to be one source. */\nconst MAX_TEXT_FILE_BYTES = 4_000_000;\n\nexport const STUDY_FILE_TYPES_LABEL = 'PDF, Word, text, audio or video';\n\nconst TEXT_EXT = /\\.(txt|md|markdown|csv|json|tex|xml|ya?ml|rtf|[jt]sx?|py|java|c|cpp|h|rs|go|swift|kt|rb|sql)$/i;\nconst UPLOAD_EXT = /\\.(pdf|docx|html?|mp3|wav|m4a|aac|ogg|opus|flac|wma|mp4|mov|mkv|webm|avi|m4v)$/i;\n\nexport type StudyFilePlan = { kind: 'text' } | { kind: 'upload' } | { kind: 'reject'; reason: string };\n\n/** How a file becomes a source, or why it cannot. */\nexport function planStudyFile(file: Pick<StudyPickedFile, 'name' | 'size' | 'mimeType'>): StudyFilePlan {\n const name = file.name.trim();\n const lower = name.toLowerCase();\n if (typeof file.size === 'number' && file.size > MAX_STUDY_FILE_BYTES) {\n return { kind: 'reject', reason: `${name} is over ${MAX_STUDY_FILE_BYTES / 1_000_000} MB.` };\n }\n if (TEXT_EXT.test(lower)) {\n if (typeof file.size === 'number' && file.size > MAX_TEXT_FILE_BYTES) {\n return { kind: 'reject', reason: `${name} is too long to read as one source. Split it, then try again.` };\n }\n return { kind: 'text' };\n }\n if (UPLOAD_EXT.test(lower)) return { kind: 'upload' };\n if (/\\.doc$/.test(lower)) return { kind: 'reject', reason: `${name}: save it as .docx or PDF, then add it again.` };\n if (/\\.(pages|key|numbers|pptx?|xlsx?)$/.test(lower)) {\n return { kind: 'reject', reason: `${name}: export it as PDF, then add it again.` };\n }\n if (/^image\\//.test(file.mimeType ?? '') || /\\.(png|jpe?g|heic|gif|webp)$/.test(lower)) {\n return { kind: 'reject', reason: `${name}: photos can't be read as notes yet. Add a PDF or paste the text.` };\n }\n if (/^text\\//.test(file.mimeType ?? '')) return { kind: 'text' };\n return { kind: 'reject', reason: `${name}: Study reads ${STUDY_FILE_TYPES_LABEL} files.` };\n}\n\n/** Rich-text files open with control words; keep the words, drop the markup. */\nfunction stripRtf(raw: string): string {\n if (!raw.startsWith('{\\\\rtf')) return raw;\n return raw\n .replace(/\\{\\\\\\*?[^{}]*\\}/g, ' ')\n .replace(/\\\\'[0-9a-fA-F]{2}/g, ' ')\n .replace(/\\\\[a-zA-Z]+-?\\d* ?/g, ' ')\n .replace(/[{}]/g, ' ')\n .replace(/[ \\t]+/g, ' ')\n .replace(/\\n{3,}/g, '\\n\\n')\n .trim();\n}\n\ntype PickerResult = {\n canceled?: boolean;\n type?: string;\n uri?: string;\n name?: string;\n mimeType?: string;\n size?: number;\n assets?: Array<{ uri?: string; name?: string; mimeType?: string; size?: number }> | null;\n};\n\ntype DocumentPicker = {\n getDocumentAsync: (options: {\n type?: string | string[];\n multiple?: boolean;\n copyToCacheDirectory?: boolean;\n }) => Promise<PickerResult>;\n};\n\nconst PICKER_MISSING = 'The file picker is not in this app build. Paste the text or share a link instead.';\n\nfunction loadDocumentPicker(): DocumentPicker {\n try {\n // Resolve the native module first: on binaries without it, requiring the\n // JS package throws at import time instead of telling us it is absent.\n // eslint-disable-next-line @typescript-eslint/no-var-requires, global-require\n const core = require('expo-modules-core') as {\n requireOptionalNativeModule?: (name: string) => {\n getDocumentAsync?: (options: Record<string, unknown>) => Promise<PickerResult>;\n } | null;\n };\n const native = core.requireOptionalNativeModule?.('ExpoDocumentPicker');\n const getDocument = native?.getDocumentAsync?.bind(native);\n if (getDocument) {\n return {\n getDocumentAsync: (options) =>\n getDocument({\n type: Array.isArray(options.type) ? options.type : [options.type ?? '*/*'],\n multiple: options.multiple ?? false,\n copyToCacheDirectory: options.copyToCacheDirectory ?? true,\n }),\n };\n }\n // eslint-disable-next-line @typescript-eslint/no-var-requires, global-require\n return require('expo-document-picker') as DocumentPicker;\n } catch (err) {\n const msg = err instanceof Error ? err.message : String(err ?? '');\n if (/Cannot find native module|ExpoDocumentPicker|Cannot find module/i.test(msg))\n throw new Error(PICKER_MISSING);\n throw err;\n }\n}\n\n/** The system file picker; an empty list when the person backs out. */\nexport async function pickStudyFiles(): Promise<StudyPickedFile[]> {\n const picker = loadDocumentPicker();\n const result = await picker.getDocumentAsync({ type: '*/*', multiple: true, copyToCacheDirectory: true });\n if (!result || result.canceled || result.type === 'cancel') return [];\n const assets = result.assets?.length ? result.assets : [result];\n return assets\n .map((asset) => ({\n uri: (asset.uri ?? '').trim(),\n name: (asset.name ?? '').trim() || 'file',\n mimeType: asset.mimeType,\n size: asset.size,\n }))\n .filter((file) => file.uri);\n}\n\ntype FileSystem = {\n readAsStringAsync?: (uri: string, options?: { encoding?: string }) => Promise<string>;\n EncodingType?: { UTF8?: string };\n};\n\n/** A text file's words, ready to be a source. */\nexport async function readStudyTextFile(file: StudyPickedFile): Promise<string> {\n // eslint-disable-next-line @typescript-eslint/no-var-requires, global-require\n const fs = require('expo-file-system') as FileSystem;\n if (typeof fs.readAsStringAsync !== 'function') {\n throw new Error(`Could not read ${file.name} on this phone. Paste its text instead.`);\n }\n let raw: string;\n try {\n raw = await fs.readAsStringAsync(file.uri, { encoding: fs.EncodingType?.UTF8 ?? 'utf8' });\n } catch {\n throw new Error(`Could not read ${file.name}. Paste its text instead.`);\n }\n const text = stripRtf(raw)\n .replace(/\\u00a0/g, ' ')\n .trim();\n if (!text) throw new Error(`${file.name} is empty.`);\n return text;\n}\n\n/**\n * Upload a picked file to the agent's store; returns a URL the notebook\n * connector can fetch. The store names the object from `filename`'s extension,\n * which is how the connector later picks the reader.\n */\nexport async function uploadStudyFile(token: string, indexUrl: string, file: StudyPickedFile): Promise<string> {\n const agent = deriveAgentEndpoint(indexUrl);\n const blob = await (await fetch(file.uri)).blob();\n const resp = await fetch(`${agent}/v1/files/upload?filename=${encodeURIComponent(file.name)}`, {\n method: 'POST',\n headers: {\n 'content-type': file.mimeType || blob.type || 'application/octet-stream',\n authorization: `Bearer ${token}`,\n },\n body: blob,\n });\n if (!resp.ok) {\n const detail = (await resp.text().catch(() => '')).slice(0, 160);\n throw new Error(`Could not upload ${file.name} (HTTP ${resp.status})${detail ? `: ${detail}` : ''}`);\n }\n const result = (await resp.json()) as { url?: string };\n if (!result.url) throw new Error(`Could not upload ${file.name}: the store returned no link.`);\n return result.url;\n}\n"],"names":["_a","_b"],"mappings":"6EAYO,MAAM,oBAAuB,GAAA;AAEpC,MAAM,mBAAsB,GAAA,GAAA;AACrB,MAAM,sBAAyB,GAAA;AACtC,MAAM,QAAW,GAAA,gGAAA;AACjB,MAAM,UAAa,GAAA,iFAAA;AAWZ,SAAS,cAAc,IAA0E,EAAA;AA5BxG,EAAA,IAAA,EAAA,EAAA,EAAA;AA6BE,EAAM,MAAA,IAAA,GAAO,IAAK,CAAA,IAAA,CAAK,IAAK,EAAA;AAC5B,EAAM,MAAA,KAAA,GAAQ,KAAK,WAAY,EAAA;AAC/B,EAAA,IAAI,OAAO,IAAK,CAAA,IAAA,KAAS,QAAY,IAAA,IAAA,CAAK,OAAO,oBAAsB,EAAA;AACrE,IAAO,OAAA;AAAA,MACL,IAAM,EAAA,QAAA;AAAA,MACN,MAAQ,EAAA,CAAA,EAAG,IAAI,CAAA,SAAA,EAAY,uBAAuB,GAAS,CAAA,IAAA;AAAA,KAC7D;AAAA;AAEF,EAAI,IAAA,QAAA,CAAS,IAAK,CAAA,KAAK,CAAG,EAAA;AACxB,IAAA,IAAI,OAAO,IAAK,CAAA,IAAA,KAAS,QAAY,IAAA,IAAA,CAAK,OAAO,mBAAqB,EAAA;AACpE,MAAO,OAA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;
|
|
2
|
+
var __defProps = Object.defineProperties;
|
|
3
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
4
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
7
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
8
|
+
var __spreadValues = (a, b) => {
|
|
9
|
+
for (var prop in b || (b = {}))
|
|
10
|
+
if (__hasOwnProp.call(b, prop))
|
|
11
|
+
__defNormalProp(a, prop, b[prop]);
|
|
12
|
+
if (__getOwnPropSymbols)
|
|
13
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
14
|
+
if (__propIsEnum.call(b, prop))
|
|
15
|
+
__defNormalProp(a, prop, b[prop]);
|
|
16
|
+
}
|
|
17
|
+
return a;
|
|
18
|
+
};
|
|
19
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
20
|
+
function record(value) {
|
|
21
|
+
return value && typeof value === "object" && !Array.isArray(value) ? value : null;
|
|
22
|
+
}
|
|
23
|
+
function str(value) {
|
|
24
|
+
return typeof value === "string" ? value : "";
|
|
25
|
+
}
|
|
26
|
+
function num(value) {
|
|
27
|
+
return typeof value === "number" && Number.isFinite(value) ? value : 0;
|
|
28
|
+
}
|
|
29
|
+
const SOURCE_KINDS = ["text", "url", "document", "media"];
|
|
30
|
+
function normalizeCell(raw) {
|
|
31
|
+
const row = record(raw);
|
|
32
|
+
const id = str(row == null ? void 0 : row.id).trim();
|
|
33
|
+
if (!row || !id) return null;
|
|
34
|
+
const type = row.type === "ai" ? "ai" : "markdown";
|
|
35
|
+
const prompt = str(row.prompt).trim();
|
|
36
|
+
const createdAt = str(row.createdAt);
|
|
37
|
+
return __spreadProps(__spreadValues({
|
|
38
|
+
id,
|
|
39
|
+
type,
|
|
40
|
+
content: str(row.content)
|
|
41
|
+
}, prompt ? {
|
|
42
|
+
prompt
|
|
43
|
+
} : {}), {
|
|
44
|
+
createdAt,
|
|
45
|
+
updatedAt: str(row.updatedAt) || createdAt
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
function normalizeSource(raw) {
|
|
49
|
+
const row = record(raw);
|
|
50
|
+
const id = str(row == null ? void 0 : row.id).trim();
|
|
51
|
+
if (!row || !id) return null;
|
|
52
|
+
const kind = SOURCE_KINDS.includes(row.kind) ? row.kind : "text";
|
|
53
|
+
const origin = str(row.origin).trim();
|
|
54
|
+
return __spreadProps(__spreadValues({
|
|
55
|
+
id,
|
|
56
|
+
kind,
|
|
57
|
+
title: str(row.title).trim() || origin || "Untitled source"
|
|
58
|
+
}, origin ? {
|
|
59
|
+
origin
|
|
60
|
+
} : {}), {
|
|
61
|
+
charCount: num(row.charCount),
|
|
62
|
+
truncated: row.truncated === true,
|
|
63
|
+
addedAt: str(row.addedAt)
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
function normalizeNotebook(raw) {
|
|
67
|
+
const row = record(raw);
|
|
68
|
+
const id = str(row == null ? void 0 : row.id).trim();
|
|
69
|
+
if (!row || !id) return null;
|
|
70
|
+
const cells = Array.isArray(row.cells) ? row.cells : [];
|
|
71
|
+
const sources = Array.isArray(row.sources) ? row.sources : [];
|
|
72
|
+
const topic = str(row.topic).trim();
|
|
73
|
+
const createdAt = str(row.createdAt);
|
|
74
|
+
return __spreadProps(__spreadValues({
|
|
75
|
+
id,
|
|
76
|
+
title: str(row.title).trim() || "Untitled notebook"
|
|
77
|
+
}, topic ? {
|
|
78
|
+
topic
|
|
79
|
+
} : {}), {
|
|
80
|
+
cells: cells.map(normalizeCell).filter((cell) => cell !== null),
|
|
81
|
+
sources: sources.map(normalizeSource).filter((source) => source !== null),
|
|
82
|
+
createdAt,
|
|
83
|
+
updatedAt: str(row.updatedAt) || createdAt
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
function normalizeSummary(raw) {
|
|
87
|
+
const row = record(raw);
|
|
88
|
+
const id = str(row == null ? void 0 : row.id).trim();
|
|
89
|
+
if (!row || !id) return null;
|
|
90
|
+
const topic = str(row.topic).trim();
|
|
91
|
+
const createdAt = str(row.createdAt);
|
|
92
|
+
return __spreadProps(__spreadValues({
|
|
93
|
+
id,
|
|
94
|
+
title: str(row.title).trim() || "Untitled notebook"
|
|
95
|
+
}, topic ? {
|
|
96
|
+
topic
|
|
97
|
+
} : {}), {
|
|
98
|
+
cellCount: num(row.cellCount),
|
|
99
|
+
sourceCount: num(row.sourceCount),
|
|
100
|
+
createdAt,
|
|
101
|
+
updatedAt: str(row.updatedAt) || createdAt
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
function summaryOf(notebook) {
|
|
105
|
+
return __spreadProps(__spreadValues({
|
|
106
|
+
id: notebook.id,
|
|
107
|
+
title: notebook.title
|
|
108
|
+
}, notebook.topic ? {
|
|
109
|
+
topic: notebook.topic
|
|
110
|
+
} : {}), {
|
|
111
|
+
cellCount: notebook.cells.length,
|
|
112
|
+
sourceCount: notebook.sources.length,
|
|
113
|
+
createdAt: notebook.createdAt,
|
|
114
|
+
updatedAt: notebook.updatedAt
|
|
115
|
+
});
|
|
116
|
+
}export{normalizeCell,normalizeNotebook,normalizeSource,normalizeSummary,summaryOf};//# sourceMappingURL=studyNormalize.js.map
|