@jitsusama/agentic-harness.core 0.3.0 → 0.3.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.
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * Google Calendar API client.
3
3
  */
4
- import { google } from "googleapis";
4
+ import { google } from "./client.js";
5
5
  /**
6
6
  * List calendar events in a date range.
7
7
  */
@@ -0,0 +1,10 @@
1
+ /**
2
+ * The googleapis client, loaded on first use.
3
+ *
4
+ * googleapis bundles a client for every Google API, about 1,800
5
+ * modules, and every extension that imports this package would load
6
+ * all of them at startup. This stands in for its `google` export and
7
+ * loads the real one the first time any API is asked for.
8
+ */
9
+ import type { GoogleApis } from "googleapis";
10
+ export declare const google: GoogleApis;
@@ -0,0 +1,23 @@
1
+ /**
2
+ * The googleapis client, loaded on first use.
3
+ *
4
+ * googleapis bundles a client for every Google API, about 1,800
5
+ * modules, and every extension that imports this package would load
6
+ * all of them at startup. This stands in for its `google` export and
7
+ * loads the real one the first time any API is asked for.
8
+ */
9
+ import { createRequire } from "node:module";
10
+ const require = createRequire(import.meta.url);
11
+ let loaded;
12
+ function load() {
13
+ loaded ??= require("googleapis").google;
14
+ return loaded;
15
+ }
16
+ export const google = new Proxy({}, {
17
+ get(_, property) {
18
+ const real = load();
19
+ const value = Reflect.get(real, property);
20
+ // The API factories read shared options off `this`.
21
+ return typeof value === "function" ? value.bind(real) : value;
22
+ },
23
+ });
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * Google Docs API client.
3
3
  */
4
- import { google } from "googleapis";
4
+ import { google } from "./client.js";
5
5
  /**
6
6
  * Get document content, including all tabs.
7
7
  */
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * Google Drive API client.
3
3
  */
4
- import { google } from "googleapis";
4
+ import { google } from "./client.js";
5
5
  /**
6
6
  * List Drive files with optional filtering.
7
7
  */
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * Gmail API client.
3
3
  */
4
- import { google } from "googleapis";
4
+ import { google } from "./client.js";
5
5
  /**
6
6
  * Search emails using Gmail query syntax.
7
7
  */
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * Google Sheets API client.
3
3
  */
4
- import { google } from "googleapis";
4
+ import { google } from "./client.js";
5
5
  /**
6
6
  * Get spreadsheet content.
7
7
  */
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * Google Slides API client.
3
3
  */
4
- import { google } from "googleapis";
4
+ import { google } from "./client.js";
5
5
  /**
6
6
  * Get presentation content.
7
7
  */
@@ -11,7 +11,6 @@
11
11
  * with web-search-integration.
12
12
  */
13
13
  import * as fs from "node:fs";
14
- import puppeteer from "puppeteer-core";
15
14
  /**
16
15
  * Default Slack URL to navigate to: the dedicated sign-in entry
17
16
  * point, not the marketing homepage. app.slack.com used to be here
@@ -76,6 +75,9 @@ function findChrome() {
76
75
  */
77
76
  export async function extractFromBrowser(slackUrl = DEFAULT_SLACK_URL, timeoutMs = DEFAULT_TIMEOUT_MS, onStep) {
78
77
  const chromePath = findChrome();
78
+ // Loaded here rather than at import, since this runs once per
79
+ // Slack setup and the module is imported on every start.
80
+ const { default: puppeteer } = await import("puppeteer-core");
79
81
  const browser = await puppeteer.launch({
80
82
  executablePath: chromePath,
81
83
  headless: false,
@@ -11,7 +11,7 @@
11
11
  * plus a shared in-flight launch promise, means one browser and
12
12
  * one profile no matter how many extensions reach for it.
13
13
  */
14
- import { type Browser, type BrowserContext, type Page } from "puppeteer-core";
14
+ import type { Browser, BrowserContext, Page } from "puppeteer-core";
15
15
  /** Diagnostic detail teased out of a failed Chrome launch. */
16
16
  export interface LaunchFailureInfo {
17
17
  exitCode?: number;
@@ -17,8 +17,15 @@ import * as fs from "node:fs";
17
17
  import * as os from "node:os";
18
18
  import * as path from "node:path";
19
19
  import { clearTimeout, setTimeout } from "node:timers";
20
- import puppeteer from "puppeteer-core";
21
20
  import { processGlobal } from "../internal/process-global.js";
21
+ /**
22
+ * puppeteer, loaded when a browser is first launched or joined rather
23
+ * than whenever this module is imported, since most sessions never
24
+ * open one.
25
+ */
26
+ async function puppeteer() {
27
+ return (await import("puppeteer-core")).default;
28
+ }
22
29
  /** How many times to try launching Chrome before giving up. */
23
30
  const LAUNCH_ATTEMPTS = 3;
24
31
  /** Backoff before each retry, in milliseconds. The array length is
@@ -507,7 +514,7 @@ async function launchOnce(executablePath) {
507
514
  // prior attempt cannot poison this one.
508
515
  fs.rmSync(profileDir, { recursive: true, force: true });
509
516
  fs.mkdirSync(profileDir, { recursive: true });
510
- const browser = await puppeteer.launch({
517
+ const browser = await (await puppeteer()).launch({
511
518
  executablePath,
512
519
  headless: true,
513
520
  userDataDir: profileDir,
@@ -594,7 +601,7 @@ export async function connectShared() {
594
601
  if (!owner?.browserWSEndpoint || !isPidAlive(owner.ownerPid))
595
602
  continue;
596
603
  try {
597
- return await puppeteer.connect({
604
+ return await (await puppeteer()).connect({
598
605
  browserWSEndpoint: owner.browserWSEndpoint,
599
606
  });
600
607
  }
@@ -13,8 +13,6 @@
13
13
  */
14
14
  import * as fs from "node:fs";
15
15
  import * as path from "node:path";
16
- import { Defuddle } from "defuddle/node";
17
- import { JSDOM, VirtualConsole } from "jsdom";
18
16
  import { isPidAlive, newPage } from "./browser.js";
19
17
  import { injectCookies, isSetUp } from "./cookies/index.js";
20
18
  import { BUNDLE_ROOT, diskSink, LEGACY_BUNDLE_ROOTS, sessionDir, } from "./envelope/sink.js";
@@ -145,8 +143,8 @@ function cleanText(text) {
145
143
  * Create a jsdom VirtualConsole that suppresses CSS parse warnings
146
144
  * without affecting process.stderr globally.
147
145
  */
148
- function quietVirtualConsole() {
149
- const vc = new VirtualConsole();
146
+ function quietVirtualConsole(Console) {
147
+ const vc = new Console();
150
148
  vc.on("error", (msg) => {
151
149
  if (!msg.includes("Could not parse CSS stylesheet")) {
152
150
  console.error(msg);
@@ -163,7 +161,14 @@ function quietVirtualConsole() {
163
161
  */
164
162
  async function extractArticle(html, url) {
165
163
  try {
166
- const dom = new JSDOM(html, { url, virtualConsole: quietVirtualConsole() });
164
+ // jsdom and defuddle load on the first page read rather than at
165
+ // import: jsdom alone is a full browser DOM, over 100 MB.
166
+ const { JSDOM, VirtualConsole } = await import("jsdom");
167
+ const { Defuddle } = await import("defuddle/node");
168
+ const dom = new JSDOM(html, {
169
+ url,
170
+ virtualConsole: quietVirtualConsole(VirtualConsole),
171
+ });
167
172
  const result = await Defuddle(dom.window.document, url, {
168
173
  markdown: true,
169
174
  useAsync: false,
@@ -7,7 +7,9 @@
7
7
  * Applying, observing and diverging all live here so the one
8
8
  * piece of state has one keeper.
9
9
  */
10
- import { KnownDevices } from "puppeteer-core";
10
+ // The catalogue's own module, rather than puppeteer's root, which
11
+ // would load all of puppeteer to read one table.
12
+ import { KnownDevices } from "puppeteer-core/internal/common/Device.js";
11
13
  import { deviceEmulation, noSuchDevice } from "../environment/devices.js";
12
14
  import { divergences, ENVIRONMENT_PROBE, mediaFeaturesOf, mergeEmulation, refusedFeature, unsupportedFields, withoutFeature, } from "../environment/index.js";
13
15
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jitsusama/agentic-harness.core",
3
- "version": "0.3.0",
3
+ "version": "0.3.1",
4
4
  "description": "Pi-agnostic business logic for agentic-harness: state machines, guardian decisions, quest/TDD domain model.",
5
5
  "license": "MIT",
6
6
  "type": "module",