@cortask/core 0.2.23 → 0.2.25

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/dist/index.d.ts CHANGED
@@ -388,6 +388,8 @@ declare function createArtifactTool(artifactStore: ArtifactStore): ToolHandler;
388
388
 
389
389
  declare function createBrowserTool(artifactStore: ArtifactStore): ToolHandler;
390
390
 
391
+ declare function ensureInstalled(): Promise<void>;
392
+
391
393
  /**
392
394
  * Set the AgentRunner reference for subagent spawning.
393
395
  * Must be called after AgentRunner instantiation.
@@ -1215,4 +1217,4 @@ declare class Logger {
1215
1217
  }
1216
1218
  declare const logger: Logger;
1217
1219
 
1218
- export { AVAILABLE_PROVIDERS, type AgentRunParams, type AgentRunResult, AgentRunner, type AgentRunnerConfig, type AgentRunnerDeps, type AgentStreamEvent, AnthropicProvider, type Artifact, ArtifactStore, type Attachment, type ChannelType, type ContentPart, type CortaskConfig, type CredentialDefinition, type CredentialSchema, type CredentialStore, type CronDelivery, type CronEvent, type CronJob, type CronJobCreate, type CronJobState, type CronSchedule, CronService, type EmbedParams, type EmbedResult, type EnabledModel, EncryptedCredentialStore, type GenerateTextParams, type GenerateTextResult, GoogleProvider, GrokProvider, type LLMProvider, type LogLevel, MODEL_DEFINITIONS, type Message, MiniMaxProvider, type ModelInfo, ModelStore, MoonshotProvider, OllamaProvider, type OnboardingData, type OnboardingStatus, OpenAICompatibleProvider, OpenAIProvider, OpenRouterProvider, type PermissionRequest, type PromptTemplate, type ProviderId, type ProviderInfo, type ProviderValidationResult, type QuestionnaireQuestion, type QuestionnaireRequest, type QuestionnaireResponse, SUBAGENT_DEFAULTS, type Session, SessionStore, type SessionWithMessages, type SkillCodeTool, type SkillEntry, type SkillManifest, type SkillSource, type SkillToolTemplate, type StreamChunk, type SubagentRunRecord, TemplateStore, type ToolCall, type ToolDefinition, type ToolExecutionContext, type ToolHandler, type ToolResult, type UsageRecord, UsageStore, type UsageSummary, type Workspace, WorkspaceManager, buildSkillOAuth2AuthUrl, buildSkillTools, buildSystemPrompt, builtinTools, cancelChildrenOfSession, cancelSubagentRun, cleanupSubagentRecords, clearSkillCache, completeSubagentRun, computeNextRunAtMs, cortaskConfigSchema, countActiveChildren, createArtifactTool, createBrowserTool, createCronTool, createProvider, createSkill, createSkillTool, createSubagentTool, createSwitchWorkspaceTool, credentialKey, estimateCost, exchangeSkillOAuth2Code, getCredentialStorageKey, getDataDir, getDepthForSession, getEligibleSkills, getModelDefinitions, getOAuth2StorageKeys, getOrCreateSecret, getProviderInfo, getSubagentRun, installSkillFromGit, loadConfig, loadSkills, logger, migrateAllWorkspaces, migrateSessionDatabase, readSkillFile, registerSubagentRun, removeSkill, revokeSkillOAuth2, saveConfig, setSubagentRunner, updateSkill, validateCronExpr, validateProvider, validateSkillName };
1220
+ export { AVAILABLE_PROVIDERS, type AgentRunParams, type AgentRunResult, AgentRunner, type AgentRunnerConfig, type AgentRunnerDeps, type AgentStreamEvent, AnthropicProvider, type Artifact, ArtifactStore, type Attachment, type ChannelType, type ContentPart, type CortaskConfig, type CredentialDefinition, type CredentialSchema, type CredentialStore, type CronDelivery, type CronEvent, type CronJob, type CronJobCreate, type CronJobState, type CronSchedule, CronService, type EmbedParams, type EmbedResult, type EnabledModel, EncryptedCredentialStore, type GenerateTextParams, type GenerateTextResult, GoogleProvider, GrokProvider, type LLMProvider, type LogLevel, MODEL_DEFINITIONS, type Message, MiniMaxProvider, type ModelInfo, ModelStore, MoonshotProvider, OllamaProvider, type OnboardingData, type OnboardingStatus, OpenAICompatibleProvider, OpenAIProvider, OpenRouterProvider, type PermissionRequest, type PromptTemplate, type ProviderId, type ProviderInfo, type ProviderValidationResult, type QuestionnaireQuestion, type QuestionnaireRequest, type QuestionnaireResponse, SUBAGENT_DEFAULTS, type Session, SessionStore, type SessionWithMessages, type SkillCodeTool, type SkillEntry, type SkillManifest, type SkillSource, type SkillToolTemplate, type StreamChunk, type SubagentRunRecord, TemplateStore, type ToolCall, type ToolDefinition, type ToolExecutionContext, type ToolHandler, type ToolResult, type UsageRecord, UsageStore, type UsageSummary, type Workspace, WorkspaceManager, buildSkillOAuth2AuthUrl, buildSkillTools, buildSystemPrompt, builtinTools, cancelChildrenOfSession, cancelSubagentRun, cleanupSubagentRecords, clearSkillCache, completeSubagentRun, computeNextRunAtMs, cortaskConfigSchema, countActiveChildren, createArtifactTool, createBrowserTool, createCronTool, createProvider, createSkill, createSkillTool, createSubagentTool, createSwitchWorkspaceTool, credentialKey, ensureInstalled as ensureBrowserInstalled, estimateCost, exchangeSkillOAuth2Code, getCredentialStorageKey, getDataDir, getDepthForSession, getEligibleSkills, getModelDefinitions, getOAuth2StorageKeys, getOrCreateSecret, getProviderInfo, getSubagentRun, installSkillFromGit, loadConfig, loadSkills, logger, migrateAllWorkspaces, migrateSessionDatabase, readSkillFile, registerSubagentRun, removeSkill, revokeSkillOAuth2, saveConfig, setSubagentRunner, updateSkill, validateCronExpr, validateProvider, validateSkillName };
package/dist/index.js CHANGED
@@ -2972,6 +2972,9 @@ function createArtifactTool(artifactStore) {
2972
2972
 
2973
2973
  // src/agent/tools/browser-manager.ts
2974
2974
  import { execFile } from "child_process";
2975
+ import { existsSync, mkdirSync } from "fs";
2976
+ import { join } from "path";
2977
+ import { homedir } from "os";
2975
2978
  import { createRequire } from "module";
2976
2979
  var DEFAULT_TIMEOUT = 3e4;
2977
2980
  function getNativeBinName() {
@@ -2985,9 +2988,14 @@ function getNativeBinName() {
2985
2988
  return null;
2986
2989
  }
2987
2990
  function resolveCmd() {
2991
+ const nativeBin = getNativeBinName();
2992
+ const resourcesPath = process.resourcesPath;
2993
+ if (resourcesPath && nativeBin) {
2994
+ const candidate = join(resourcesPath, "agent-browser", nativeBin);
2995
+ if (existsSync(candidate)) return candidate;
2996
+ }
2988
2997
  try {
2989
2998
  const require2 = createRequire(import.meta.url);
2990
- const nativeBin = getNativeBinName();
2991
2999
  if (nativeBin) {
2992
3000
  try {
2993
3001
  return require2.resolve(`agent-browser/bin/${nativeBin}`);
@@ -3001,12 +3009,22 @@ function resolveCmd() {
3001
3009
  }
3002
3010
  var CMD = resolveCmd();
3003
3011
  var instance = null;
3012
+ function resetBrowserInstance() {
3013
+ instance = null;
3014
+ }
3015
+ function getAgentBrowserHome() {
3016
+ if (process.env.AGENT_BROWSER_HOME) return process.env.AGENT_BROWSER_HOME;
3017
+ const dir = join(homedir(), ".agent-browser");
3018
+ if (!existsSync(dir)) mkdirSync(dir, { recursive: true });
3019
+ return dir;
3020
+ }
3004
3021
  function exec2(args, timeout = DEFAULT_TIMEOUT) {
3005
3022
  return new Promise((resolve, reject) => {
3006
3023
  const isScript = CMD.endsWith(".js");
3007
3024
  const cmd = isScript ? process.env.NODE_PATH_BIN || process.execPath : CMD;
3008
3025
  const finalArgs = isScript ? [CMD, ...args] : args;
3009
- execFile(cmd, finalArgs, { timeout, maxBuffer: 5 * 1024 * 1024 }, (err, stdout, stderr) => {
3026
+ const env = { ...process.env, AGENT_BROWSER_HOME: getAgentBrowserHome() };
3027
+ execFile(cmd, finalArgs, { timeout, maxBuffer: 5 * 1024 * 1024, env }, (err, stdout, stderr) => {
3010
3028
  if (err) {
3011
3029
  const msg = stderr?.trim() || stdout?.trim() || err.message;
3012
3030
  reject(new Error(msg));
@@ -3033,6 +3051,8 @@ async function ensureInstalled() {
3033
3051
  async function ensureBrowser() {
3034
3052
  if (instance) return instance;
3035
3053
  await ensureInstalled();
3054
+ await exec2(["close"], 5e3).catch(() => {
3055
+ });
3036
3056
  const inst = {
3037
3057
  async run(args) {
3038
3058
  return exec2(args);
@@ -3187,7 +3207,7 @@ function createBrowserTool(artifactStore) {
3187
3207
  await closeBrowser();
3188
3208
  return { toolCallId: "", content: "Browser closed." };
3189
3209
  }
3190
- try {
3210
+ const executeAction = async () => {
3191
3211
  const browser = await ensureBrowser();
3192
3212
  switch (action) {
3193
3213
  case "navigate": {
@@ -3377,10 +3397,28 @@ ${result.content}`,
3377
3397
  isError: true
3378
3398
  };
3379
3399
  }
3400
+ };
3401
+ try {
3402
+ return await executeAction();
3380
3403
  } catch (err) {
3404
+ const msg = err instanceof Error ? err.message : String(err);
3405
+ if (msg.includes("has been closed") || msg.includes("Target page")) {
3406
+ await closeBrowser().catch(() => {
3407
+ });
3408
+ resetBrowserInstance();
3409
+ try {
3410
+ return await executeAction();
3411
+ } catch (retryErr) {
3412
+ return {
3413
+ toolCallId: "",
3414
+ content: `Browser error (after retry): ${retryErr instanceof Error ? retryErr.message : String(retryErr)}`,
3415
+ isError: true
3416
+ };
3417
+ }
3418
+ }
3381
3419
  return {
3382
3420
  toolCallId: "",
3383
- content: `Browser error: ${err instanceof Error ? err.message : String(err)}`,
3421
+ content: `Browser error: ${msg}`,
3384
3422
  isError: true
3385
3423
  };
3386
3424
  }
@@ -5789,6 +5827,7 @@ export {
5789
5827
  createSubagentTool,
5790
5828
  createSwitchWorkspaceTool,
5791
5829
  credentialKey,
5830
+ ensureInstalled as ensureBrowserInstalled,
5792
5831
  estimateCost,
5793
5832
  exchangeSkillOAuth2Code,
5794
5833
  getCredentialStorageKey,