sideora 0.0.1-alpha.0 → 0.1.0-alpha.2
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/LICENSE.md +9 -0
- package/README.md +57 -6
- package/assets/sounds/freesound_community-mail-40275.mp3 +0 -0
- package/assets/sounds/mixkit-clear-announce-tones-2861.wav +0 -0
- package/assets/sounds/mixkit-happy-bells-notification-937.wav +0 -0
- package/assets/sounds/mixkit-musical-alert-notification-2309.wav +0 -0
- package/assets/sounds/nice-chime.mp3 +0 -0
- package/bin/sideora.js +2430 -12
- package/extension/dist/assets/background.ts-NW8YqAlO.js +1 -0
- package/extension/dist/assets/fillCode-Ci8IkBvY.js +1 -0
- package/extension/dist/assets/index.html-DrrPha1M.js +2 -0
- package/extension/dist/assets/modulepreload-polyfill-DcjICKwh.js +1 -0
- package/extension/dist/assets/shell-82MNMljp.css +1 -0
- package/extension/dist/assets/shell-QYBN1bx1.js +1 -0
- package/extension/dist/icons/icon-128.png +0 -0
- package/extension/dist/icons/icon-16.png +0 -0
- package/extension/dist/icons/icon-32.png +0 -0
- package/extension/dist/icons/icon-48.png +0 -0
- package/extension/dist/manifest.json +40 -0
- package/extension/dist/service-worker-loader.js +1 -0
- package/extension/dist/src/newtab/index.html +14 -0
- package/extension/dist/src/panel/index.html +15 -0
- package/extension/dist-web/assets/abnfDiagram-WEYOIA3C-CoXOc872.js +1 -0
- package/extension/dist-web/assets/apple-touch-icon-DSgRQASq.png +0 -0
- package/extension/dist-web/assets/architecture-WOLXFQ4H-BkJ4AerO.js +1 -0
- package/extension/dist-web/assets/architectureDiagram-ZHVYKT53-aPkSDlxA.js +36 -0
- package/extension/dist-web/assets/blockDiagram-RJAE7QA3-CH1G4NBZ.js +140 -0
- package/extension/dist-web/assets/c4Diagram-XDPPPE54-Baum1zDu.js +38 -0
- package/extension/dist-web/assets/channel-PsQg-mnK.js +1 -0
- package/extension/dist-web/assets/chunk-2E7WHVMD-CKvLrWRa.js +88 -0
- package/extension/dist-web/assets/chunk-2Q5K7J3B-C1jixKkw.js +1 -0
- package/extension/dist-web/assets/chunk-4EMNKR2T-6fjnroCZ.js +1 -0
- package/extension/dist-web/assets/chunk-55XCU76K-Ygs3sNpi.js +1 -0
- package/extension/dist-web/assets/chunk-5VM5RSS4-ZNzvKenW.js +15 -0
- package/extension/dist-web/assets/chunk-7S6XSTFO-iX5xYzfP.js +2 -0
- package/extension/dist-web/assets/chunk-AQDTSKZB-D9zwhFI8.js +72 -0
- package/extension/dist-web/assets/chunk-DSNLSHJZ-siGS-4qu.js +129 -0
- package/extension/dist-web/assets/chunk-DUW6YSOI-Dgx8z5s3.js +1 -0
- package/extension/dist-web/assets/chunk-HAGFOTED-_3dtnWXn.js +62 -0
- package/extension/dist-web/assets/chunk-HNE4Q36P-BPzRHi72.js +1 -0
- package/extension/dist-web/assets/chunk-J5ZVWO5B-oDCd-gWO.js +1 -0
- package/extension/dist-web/assets/chunk-JWPE2WC7-DVXcaiue.js +1 -0
- package/extension/dist-web/assets/chunk-NGNAAXSQ-DI_UYJZ4.js +136 -0
- package/extension/dist-web/assets/chunk-NQOKRVIF-AXbmOBjs.js +213 -0
- package/extension/dist-web/assets/chunk-UHW7PFBP-B3xrZ8sD.js +1 -0
- package/extension/dist-web/assets/chunk-VQ5W62QI-D_k7Pa6b.js +1 -0
- package/extension/dist-web/assets/chunk-WQQL4CDK-BBIrWwoZ.js +10 -0
- package/extension/dist-web/assets/chunk-XXDRQBXY-i7MKP1NY.js +1 -0
- package/extension/dist-web/assets/chunk-Y2CYZVJY-DsF7k-Jl.js +1 -0
- package/extension/dist-web/assets/chunk-YZO67HFG-Z7qp5QAI.js +1 -0
- package/extension/dist-web/assets/chunk-ZAUX2LTX-CSt3c0Rb.js +1 -0
- package/extension/dist-web/assets/chunk-ZCHMQSOR-g8XRABGK.js +2 -0
- package/extension/dist-web/assets/classDiagram-v2-4MYWR3UA-BL706wzc.js +217 -0
- package/extension/dist-web/assets/cose-bilkent-JH36ORCC-C6J2IoHg.js +1 -0
- package/extension/dist-web/assets/cynefin-EF2NZ3EQ-DLhQOiAy.js +1 -0
- package/extension/dist-web/assets/cynefinDiagram-WF24UDRP-Cv9Lx6_l.js +62 -0
- package/extension/dist-web/assets/cytoscape.esm-nTrd5EVq.js +321 -0
- package/extension/dist-web/assets/d3-scale-CElPUUud.js +1 -0
- package/extension/dist-web/assets/d3-selection-COWvaQNI.js +1 -0
- package/extension/dist-web/assets/dagre-NK4GIZVX-ngM-w2EC.js +4 -0
- package/extension/dist-web/assets/diagram-CBK3MWTC-kp8sayNG.js +24 -0
- package/extension/dist-web/assets/diagram-I5XIIV2D-BZ_Dgs6K.js +24 -0
- package/extension/dist-web/assets/diagram-ODIL2UCW-DWhUyArG.js +30 -0
- package/extension/dist-web/assets/diagram-PFBEJUXE-CBAdEK7l.js +3 -0
- package/extension/dist-web/assets/diagram-RJA3I4VV-kOdIr_3K.js +41 -0
- package/extension/dist-web/assets/diagram-TYUNFSNR-BrWGa0x5.js +200 -0
- package/extension/dist-web/assets/dist-DdXDFcej.js +1 -0
- package/extension/dist-web/assets/docx-preview-D1zbEiLy.js +20 -0
- package/extension/dist-web/assets/earth-Ce3xs8Cb.webp +0 -0
- package/extension/dist-web/assets/ebnfDiagram-V4P3TTPT-0r3weWmj.js +1 -0
- package/extension/dist-web/assets/elk-QONTBCTQ-D3oElRZ3.js +27 -0
- package/extension/dist-web/assets/erDiagram-KYQIGQAA-B9oU7_j_.js +99 -0
- package/extension/dist-web/assets/eventmodeling-K75KTNOO-CMKgc1nP.js +1 -0
- package/extension/dist-web/assets/favicon-D_X6tUVf.svg +5 -0
- package/extension/dist-web/assets/flowDiagram-IUGLLWBU-yRwks0Mw.js +1 -0
- package/extension/dist-web/assets/ganttDiagram-R7GPNTJY-cJqD1qwQ.js +292 -0
- package/extension/dist-web/assets/gitGraph-VSP46ZUC-CuBQqkbr.js +1 -0
- package/extension/dist-web/assets/gitGraphDiagram-PDYL7XHY-D7bHnQXC.js +106 -0
- package/extension/dist-web/assets/graphlib-DS17s2tU.js +1 -0
- package/extension/dist-web/assets/home-CV7-8Trs.js +1 -0
- package/extension/dist-web/assets/index-CQvw7Wy_.js +7 -0
- package/extension/dist-web/assets/index-CVKnZ21i.css +1 -0
- package/extension/dist-web/assets/info-OHQRW6UA-B8kyzV4O.js +1 -0
- package/extension/dist-web/assets/infoDiagram-MVDRKAX5-CEm6lezX.js +2 -0
- package/extension/dist-web/assets/ishikawaDiagram-HPEHV2GE-Ce3uv2wr.js +70 -0
- package/extension/dist-web/assets/journeyDiagram-BOSHW7O7-QgdahHCP.js +139 -0
- package/extension/dist-web/assets/jszip.min-3XXygzvy.js +2 -0
- package/extension/dist-web/assets/kanban-definition-FNSA4HC5-DPuTtWgR.js +89 -0
- package/extension/dist-web/assets/katex-MEuSR36T.js +257 -0
- package/extension/dist-web/assets/mermaid-parser.core-h7U7YGn_.js +7 -0
- package/extension/dist-web/assets/mermaid.core-DkGhophj.js +44 -0
- package/extension/dist-web/assets/mindmap-definition-6OY57UG3-D7VQxbda.js +98 -0
- package/extension/dist-web/assets/mount-CBzzf6KQ.js +195 -0
- package/extension/dist-web/assets/mount-DtvYnQXt.css +1 -0
- package/extension/dist-web/assets/officeparser.browser.slim-kEjhTrQ1.js +1989 -0
- package/extension/dist-web/assets/packet-JDAUHWVQ-oafHgw6X.js +1 -0
- package/extension/dist-web/assets/pegDiagram-ECIUJNBX-C3zo1naj.js +1 -0
- package/extension/dist-web/assets/peoria-B5TBlKDG.jpg +0 -0
- package/extension/dist-web/assets/peoria-thumb-CN8upAdZ.jpg +0 -0
- package/extension/dist-web/assets/pie-XZMESJXO-DXzeBQqF.js +1 -0
- package/extension/dist-web/assets/pieDiagram-GNMPY74T-S5NzPthl.js +39 -0
- package/extension/dist-web/assets/quadrantDiagram-D57K4MC3-C9glHQmk.js +7 -0
- package/extension/dist-web/assets/radar-ABXABTNO-CWTNqtbu.js +1 -0
- package/extension/dist-web/assets/railroad-I3PHUGI6-BTpD5_Bu.js +1 -0
- package/extension/dist-web/assets/railroad-abnf-LNEFI6M7-bWyxoXQG.js +1 -0
- package/extension/dist-web/assets/railroad-ebnf-DWYD2UWJ-ri5733DQ.js +1 -0
- package/extension/dist-web/assets/railroad-peg-JR7BVNR7-CmGfTubP.js +1 -0
- package/extension/dist-web/assets/railroadDiagram-Y72NRBL7-DTfe6Dh1.js +1 -0
- package/extension/dist-web/assets/requirementDiagram-EQYSW5RA-DQDzcS3L.js +84 -0
- package/extension/dist-web/assets/rolldown-runtime-COiEfhsA.js +1 -0
- package/extension/dist-web/assets/rough.esm-Dy-Kn_BL.js +1 -0
- package/extension/dist-web/assets/sankeyDiagram-SY24JHO5-DyMKWxdB.js +40 -0
- package/extension/dist-web/assets/sequenceDiagram-BLEHNHQU-dIkB1mCn.js +169 -0
- package/extension/dist-web/assets/sizeCapture-INFHLROL-3uHXrFqA.js +1 -0
- package/extension/dist-web/assets/stateDiagram-v2-A6IESKWZ-Bj_vxEVF.js +291 -0
- package/extension/dist-web/assets/swimlanes-B3ENRKFQ-BSkWEwHR.js +1 -0
- package/extension/dist-web/assets/swimlanesDiagram-AYQRV4AK-BTzSDlSM.js +8 -0
- package/extension/dist-web/assets/timeline-definition-JXYKGLGB-TwfWS0pw.js +120 -0
- package/extension/dist-web/assets/treeView-D4JQ5SDB-BzA_8YYb.js +1 -0
- package/extension/dist-web/assets/treemap-SAJKECNS-BI9d6--2.js +1 -0
- package/extension/dist-web/assets/usecaseDiagram-WPOLBNNX-BOVbAUPk.js +328 -0
- package/extension/dist-web/assets/vennDiagram-Q3Y3IDCW-X2kYAWaj.js +34 -0
- package/extension/dist-web/assets/wardley-7MLQ67FV-CItxqJ8G.js +1 -0
- package/extension/dist-web/assets/wardleyDiagram-IVAIDKWA-BnUXvKD_.js +78 -0
- package/extension/dist-web/assets/xychartDiagram-4URNHDU4-ysvBXvyE.js +7 -0
- package/extension/dist-web/icon-192.png +0 -0
- package/extension/dist-web/icon-512.png +0 -0
- package/extension/dist-web/index.html +25 -0
- package/extension/dist-web/manifest.webmanifest +14 -0
- package/package.json +64 -12
- package/plugin/.claude-plugin/icon.png +0 -0
- package/plugin/.claude-plugin/plugin.json +6 -0
- package/plugin/.mcp.json +8 -0
- package/plugin/README.md +72 -0
- package/plugin/mcp-launcher.mjs +48 -0
- package/src/account-probe.js +45 -0
- package/src/accounts.js +687 -0
- package/src/ai.js +269 -0
- package/src/assistant-runs.js +32 -0
- package/src/attached-mail.js +76 -0
- package/src/auth-gate.js +70 -0
- package/src/backup-cli.js +158 -0
- package/src/backup.js +329 -0
- package/src/bimi.js +233 -0
- package/src/bridge.js +101 -0
- package/src/calendar-alerts.js +56 -0
- package/src/chats.js +27 -0
- package/src/compose-editor.js +58 -0
- package/src/config.js +420 -0
- package/src/connections.d.ts +24 -0
- package/src/connections.js +37 -0
- package/src/core/agent.js +92 -0
- package/src/core/assistant.d.ts +13 -0
- package/src/core/assistant.js +790 -0
- package/src/core/chats.js +323 -0
- package/src/core/markdown.d.ts +8 -0
- package/src/core/markdown.js +239 -0
- package/src/core/notes.js +445 -0
- package/src/core/otp.js +152 -0
- package/src/core/rules.js +196 -0
- package/src/core/runs.d.ts +9 -0
- package/src/core/runs.js +211 -0
- package/src/core/thread.js +526 -0
- package/src/core/write.js +247 -0
- package/src/core-db.js +131 -0
- package/src/core.js +174 -0
- package/src/credentials.js +320 -0
- package/src/daemon.js +564 -0
- package/src/events.js +213 -0
- package/src/extension-id.d.ts +2 -0
- package/src/extension-id.js +5 -0
- package/src/file-lock.js +27 -0
- package/src/files-index.js +154 -0
- package/src/google-contacts.js +315 -0
- package/src/google-signin.js +306 -0
- package/src/host/assistant-html.js +44 -0
- package/src/host/chats-files.js +137 -0
- package/src/host/file-prep.js +122 -0
- package/src/host/notes-files.js +158 -0
- package/src/host/office-text.js +224 -0
- package/src/host/office-worker.js +8 -0
- package/src/host/rules-file.js +20 -0
- package/src/host/secrets-file.js +91 -0
- package/src/host/systemd.js +90 -0
- package/src/hub.js +245 -0
- package/src/identity.js +316 -0
- package/src/labels.js +5 -0
- package/src/mail-port.d.ts +79 -0
- package/src/mail-port.js +148 -0
- package/src/mcp-server.js +747 -0
- package/src/microsoft-app.js +20 -0
- package/src/microsoft-signin.js +194 -0
- package/src/migrate.js +327 -0
- package/src/notes-html.js +450 -0
- package/src/notes.js +19 -0
- package/src/notify.js +105 -0
- package/src/onepassword.js +223 -0
- package/src/op-registry.d.ts +14 -0
- package/src/op-registry.js +150 -0
- package/src/ops.js +1251 -0
- package/src/otp.js +6 -0
- package/src/panel-ops.js +273 -0
- package/src/pictures.js +735 -0
- package/src/postinstall.js +25 -0
- package/src/relay-passkey.js +122 -0
- package/src/relay-request.js +155 -0
- package/src/relay-seal.js +56 -0
- package/src/relay-settings.js +139 -0
- package/src/relay.js +876 -0
- package/src/render.js +82 -0
- package/src/rules-store.js +8 -0
- package/src/safe-fetch.js +215 -0
- package/src/sender-auth.js +270 -0
- package/src/site-match.js +77 -0
- package/src/tui-agenda.js +266 -0
- package/src/tui.js +670 -0
- package/src/vmc.js +376 -0
- package/src/wake.js +96 -0
- package/src/web-access.js +185 -0
- package/src/web-server.js +241 -0
- package/src/web-service.js +152 -0
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
// The connections' contract (src/connections.js): what the panel's ops ask of the accounts a person adds.
|
|
2
|
+
|
|
3
|
+
type OnePasswordLink = { vaultId: string; itemId: string } | undefined;
|
|
4
|
+
type Spec = Record<string, any> | undefined;
|
|
5
|
+
|
|
6
|
+
export interface Connections {
|
|
7
|
+
/** What the panel shows of each account: never a password, nor anything read from 1Password. */
|
|
8
|
+
doc(): Record<string, any>;
|
|
9
|
+
test(a: { spec: Spec; password?: string; onePassword: OnePasswordLink }): Promise<Record<string, any>>;
|
|
10
|
+
add(a: { name?: string; label?: string; spec: Spec; password?: string; onePassword: OnePasswordLink }): Promise<Record<string, any>>;
|
|
11
|
+
edit(a: { name?: string; label?: string; spec: Spec; password?: string; onePassword: OnePasswordLink; was?: unknown }): Promise<Record<string, any>>;
|
|
12
|
+
remove(a: { name?: string }): Record<string, any>;
|
|
13
|
+
setDefault(a: { name?: string }): Record<string, any>;
|
|
14
|
+
/** Items whose websites match the account's servers or address: titles, vaults, websites, IDs (never a secret). */
|
|
15
|
+
onePasswordItems(a: { server?: string; email?: string; smtp?: string }): Promise<{ items: Array<Record<string, any>>; addressOnly?: number; reason?: string; message?: string }>;
|
|
16
|
+
googleSignIn: {
|
|
17
|
+
start(a: { account?: string; connect: boolean }): Promise<Record<string, any>>;
|
|
18
|
+
status(a: { account?: string }): Record<string, any>;
|
|
19
|
+
cancel(a: { account?: string }): Record<string, any>;
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function makeConnections(lib: { accounts: Record<string, any>; google: Record<string, any> }): Connections;
|
|
24
|
+
export const connections: Connections;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
// The connections: the accounts a person adds, each one a connection of a connector (mail's today; Google's sign-in
|
|
2
|
+
// shared by the mail, calendar and contacts connections that use it). The panel's ops (src/panel-ops.js) reach them
|
|
3
|
+
// only through this contract, never accounts.js or google-signin.js: a host without them gives its own of the same
|
|
4
|
+
// shape (src/connections.d.ts).
|
|
5
|
+
//
|
|
6
|
+
// Nothing here decides anything: each method is the call the panel's op made, with the arguments it gave. What the
|
|
7
|
+
// panel may name and what is refused stays where it was (src/accounts.js, src/google-signin.js).
|
|
8
|
+
//
|
|
9
|
+
// doc, test, add, edit, remove, setDefault the connections, as the panel shows and changes them
|
|
10
|
+
// onePasswordItems 1Password items that may sign one in (never a secret)
|
|
11
|
+
// googleSignIn a Google sign-in, started, asked about, cancelled
|
|
12
|
+
|
|
13
|
+
import * as accounts from './accounts.js';
|
|
14
|
+
import * as google from './google-signin.js';
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* The contract over `lib` ({ accounts, google }: those modules' names). Tests give a stand-in.
|
|
18
|
+
* @returns {import('./connections').Connections}
|
|
19
|
+
*/
|
|
20
|
+
export function makeConnections(lib) {
|
|
21
|
+
return {
|
|
22
|
+
doc: () => lib.accounts.accountsDoc(),
|
|
23
|
+
test: (a) => lib.accounts.testAccount(a),
|
|
24
|
+
add: (a) => lib.accounts.addAccount(a),
|
|
25
|
+
edit: (a) => lib.accounts.editAccount(a),
|
|
26
|
+
remove: (a) => lib.accounts.removeAccount(a),
|
|
27
|
+
setDefault: (a) => lib.accounts.setDefaultAccount(a),
|
|
28
|
+
onePasswordItems: (a) => lib.accounts.onePasswordItems(a),
|
|
29
|
+
googleSignIn: {
|
|
30
|
+
start: (a) => lib.google.startSignIn(a),
|
|
31
|
+
status: (a) => lib.google.signInStatus(a),
|
|
32
|
+
cancel: (a) => lib.google.cancelSignIn(a)
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export const connections = makeConnections({ accounts, google });
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
// The loop that lets a model work with tools: it asks for a tool, the tool runs and its answer is told to the model,
|
|
2
|
+
// until the model is done. The core's, wherever it runs: one model turn is asked of whoever holds the connections
|
|
3
|
+
// (`turn`, given by the host: src/ai.js's aiChat on the Mac), the tools are the core's own (src/core/assistant.js).
|
|
4
|
+
//
|
|
5
|
+
// runAgent({ system, prompt, tools, history?, onStep?, maxTurns?, asked?, turn, signal? }) → { text, steps, exhausted? }
|
|
6
|
+
//
|
|
7
|
+
// A tool: { name, description, inputSchema, run(args) → string | content parts, effect? }. `effect`: it only
|
|
8
|
+
// changes something and has nothing to report: when a turn calls only such tools, the work is done and the model is
|
|
9
|
+
// not asked again. `signal` aborted: the run throws 'cancelled' between and during turns; what a tool already did
|
|
10
|
+
// stays done.
|
|
11
|
+
|
|
12
|
+
const MAX_TURNS = 6;
|
|
13
|
+
|
|
14
|
+
/** A refusal of the request's form (not of the key, the quota or the network): what a model that reads no files answers to one. */
|
|
15
|
+
export function refusedFiles(error) {
|
|
16
|
+
const e = String(error ?? '');
|
|
17
|
+
// (too long, too big, too many pages, a limit: a model that reads files, told of one it could not take; not to be said as "this model reads none")
|
|
18
|
+
if (/\b(401|403|429|5\d\d)\b|cancel|network|timed? ?out|quota|\brate\b|too long|too large|too many|context|token|exceed|maximum|limit/i.test(e)) return false;
|
|
19
|
+
return /invalid message format|image|document|\bfile|pdf|multimodal|vision|unsupported (content|part|type)|not support/i.test(e);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/** A file's place, said in words: the model is told it was there, and that it cannot read it. */
|
|
23
|
+
function noteOf(part) {
|
|
24
|
+
const named = typeof part?.name === 'string' && part.name ? ` "${part.name}"` : '';
|
|
25
|
+
const what = part?.type === 'image' ? `A picture${named}` : `A file${named}`;
|
|
26
|
+
return { type: 'text', text: `[${what} was here, but this model cannot read pictures or PDFs. Do not guess what it says: tell the person you could not open it, and that a model that reads files (Claude or ChatGPT, for one) can.]` };
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export const textOnly = (content) => content.map((p) => (p.type === 'text' ? p : noteOf(p)));
|
|
30
|
+
|
|
31
|
+
/** Each picture or document in the conversation, as a note of it, in place. Whether there was one. */
|
|
32
|
+
function withoutFiles(messages) {
|
|
33
|
+
let found = false;
|
|
34
|
+
messages.forEach((m, i) => {
|
|
35
|
+
if (!Array.isArray(m.content) || !m.content.some((p) => p.type !== 'text')) return;
|
|
36
|
+
found = true;
|
|
37
|
+
messages[i] = { ...m, content: textOnly(m.content) }; // (a copy: the history's own messages stay as they are)
|
|
38
|
+
});
|
|
39
|
+
return found;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const cancelled = () => new Error('cancelled');
|
|
43
|
+
|
|
44
|
+
export async function runAgent(request) {
|
|
45
|
+
const { turn, signal } = request;
|
|
46
|
+
if (typeof turn !== 'function') throw new Error('runAgent needs a turn');
|
|
47
|
+
const specs = request.tools.map(({ name, description, inputSchema }) => ({ name, description, inputSchema }));
|
|
48
|
+
const messages = [...(request.history ?? []), { role: 'user', content: request.prompt }];
|
|
49
|
+
const steps = [];
|
|
50
|
+
let plain = false; // the files were taken out: what is read from now on goes as text only
|
|
51
|
+
for (let n = 0; n < (request.maxTurns ?? MAX_TURNS); n++) {
|
|
52
|
+
if (signal?.aborted) throw cancelled();
|
|
53
|
+
const r = await turn({ system: request.system, messages, tools: specs, ...request.asked }, { signal });
|
|
54
|
+
if (signal?.aborted) throw cancelled();
|
|
55
|
+
if (!r?.ok) {
|
|
56
|
+
// (a model that takes no PDFs or pictures refuses the whole request: asked once more with each file as a note of it)
|
|
57
|
+
if (!plain && refusedFiles(r?.error) && withoutFiles(messages)) { plain = true; n--; continue; }
|
|
58
|
+
// `acted`: a tool had already run when it failed, so the request is not one to simply try again
|
|
59
|
+
throw Object.assign(new Error(r?.error ?? 'The model did not answer.'), { acted: steps.length > 0 });
|
|
60
|
+
}
|
|
61
|
+
// (a long turn the provider paused, its searches under way: given back as it is, and taken up again)
|
|
62
|
+
if (r.stopReason === 'pause' && !r.toolCalls?.length) {
|
|
63
|
+
messages.push({ role: 'assistant', content: r.text, providerState: r.providerState });
|
|
64
|
+
continue;
|
|
65
|
+
}
|
|
66
|
+
if (!r.toolCalls?.length) return { text: r.text?.trim() ?? '', steps };
|
|
67
|
+
messages.push({ role: 'assistant', content: r.text, toolCalls: r.toolCalls, providerState: r.providerState });
|
|
68
|
+
let reports = false;
|
|
69
|
+
for (const call of r.toolCalls) {
|
|
70
|
+
const tool = request.tools.find((t) => t.name === call.name);
|
|
71
|
+
let content;
|
|
72
|
+
let isError = false;
|
|
73
|
+
try {
|
|
74
|
+
if (!tool) throw new Error(`there is no tool named ${call.name}`);
|
|
75
|
+
if (call.argsError) throw new Error(`invalid arguments: ${call.argsError.message}`);
|
|
76
|
+
request.onStep?.({ name: call.name, args: call.args ?? {} });
|
|
77
|
+
content = (await tool.run(call.args ?? {})) || 'Done.';
|
|
78
|
+
} catch (e) {
|
|
79
|
+
isError = true;
|
|
80
|
+
content = e instanceof Error ? e.message : String(e);
|
|
81
|
+
}
|
|
82
|
+
if (signal?.aborted) throw cancelled();
|
|
83
|
+
if (plain && typeof content !== 'string') content = textOnly(content);
|
|
84
|
+
steps.push({ name: call.name, ok: !isError });
|
|
85
|
+
request.onStep?.({ name: call.name, args: call.args ?? {}, ok: !isError });
|
|
86
|
+
if (isError || !tool?.effect) reports = true;
|
|
87
|
+
messages.push({ role: 'tool', toolCallId: call.id, name: call.name, content, isError });
|
|
88
|
+
}
|
|
89
|
+
if (!reports) return { text: r.text?.trim() ?? '', steps }; // only changes, all made: nothing for the model to read
|
|
90
|
+
}
|
|
91
|
+
return { text: '', steps, exhausted: true };
|
|
92
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// Types of src/core/assistant.js, for the page's harness (extension/harness/boot.ts), which runs it in a browser.
|
|
2
|
+
export interface AssistantDeps {
|
|
3
|
+
ops: (name: string, args?: unknown) => Promise<any>;
|
|
4
|
+
turn: (request: any, ctx: { signal?: AbortSignal }) => Promise<any>;
|
|
5
|
+
html: { draft: (html: string) => string; text: (html: string) => string };
|
|
6
|
+
prepareFile: (base64: string, name: string, contentType: string) => Promise<{ kind: 'image' | 'pdf' | 'text'; data: string; mediaType: string }>;
|
|
7
|
+
}
|
|
8
|
+
export interface Assistant {
|
|
9
|
+
answer(q: { turns: unknown[]; text: string; files: unknown[]; asked?: object; model: string }, io: { emit?: (e: object) => void; ask?: (query: string) => Promise<boolean>; signal?: AbortSignal }): Promise<any>;
|
|
10
|
+
}
|
|
11
|
+
export function makeAssistant(deps: AssistantDeps): Assistant;
|
|
12
|
+
export const MAX_FILES: number;
|
|
13
|
+
export const MAX_FILES_BYTES: number;
|