@gencode/agents 0.9.2 → 0.9.3-preview.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/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # @gencode/agents
2
2
 
3
+ ## 0.9.3
4
+
5
+ ### Patch Changes
6
+
7
+ - 4a2a4f7: 修复使用 `apiFormat: "anthropic-messages"` 连接 Anthropic Messages API 或兼容网关时,部分网关只在完整 assistant 消息中返回最终文本、或返回格式正常但没有文本和工具调用的空响应,导致 agent 可能丢失最终回复或静默结束的问题。修复后系统会从完整 assistant 消息中补齐最终文本,并将真正的空响应识别为可重试错误交给既有重试逻辑处理,无需调整 API 配置。
8
+ - 833f2dc: 为 agent 运行的收尾阶段增加超时保护与降级策略,避免因单个步骤阻塞导致整个流程挂起:
9
+
10
+ - **Session 标题生成**:增加 5 秒超时上限,超时或生成失败时自动降级为基于首条消息的本地标题,不再阻塞 session 结算流程。
11
+ - **Agent 运行超时**:启用 agent run 的 10 分钟默认超时(可通过 `timeoutMs` 参数配置),超时后优雅中止并记录诊断日志,而非无限挂起。
12
+ - **HTTP Callback 回调**:为 callback 事件投递增加 5 秒超时,超时或网络错误时仅记录日志,不再抛出异常导致进程崩溃。
13
+ - **WebSocket 连接与关闭**:为 WebSocket 建连和关闭分别增加 5 秒超时保护,防止连接异常时事件发送流程阻塞。
14
+
3
15
  ## 0.9.2
4
16
 
5
17
  ### Patch Changes
package/dist/index.d.ts CHANGED
@@ -511,6 +511,7 @@ type LlmApiFormat = "openai-completions" | "anthropic-messages";
511
511
  //#region src/history/topic-segmentation.d.ts
512
512
  type TopicSegmentationConfig = {
513
513
  enabled?: boolean;
514
+ embeddingModelDir?: string;
514
515
  minUserTurns?: number;
515
516
  minEstimatedTokens?: number;
516
517
  recentProtectedTurnCount?: number;
@@ -732,7 +733,20 @@ type AgentRunParamsBase = {
732
733
  * Older turns are dropped before the history is sent to the LLM.
733
734
  * 0 or undefined means no limit.
734
735
  */
735
- historyLimit?: number; /** Optional IM-style topic segmentation prefilter. Enabled by default unless enabled=false. */
736
+ historyLimit?: number;
737
+ /**
738
+ * Optional session-scoped environment variables to inject into child processes
739
+ * spawned by the `exec` / `process` tools and exposed to plugin scripts via
740
+ * the plugin runtime context.
741
+ *
742
+ * Merge order (later entries win):
743
+ * process.env < run-level `env` < per-call `exec.env` params
744
+ *
745
+ * The values are kept in memory only for the duration of the run; they are
746
+ * never written to disk and never cross a session boundary. Subagent runs
747
+ * inherit this map via the standard `subagent_spawn` plumbing.
748
+ */
749
+ env?: Record<string, string>; /** Optional IM-style topic segmentation prefilter. Enabled by default unless enabled=false. */
736
750
  topicSegmentation?: TopicSegmentationConfig;
737
751
  /**
738
752
  * Goal to create when this run establishes a new session (CLI `run --goal` without --session-id).
@@ -1064,6 +1078,7 @@ type GenerateTitleParams = {
1064
1078
  signal?: AbortSignal;
1065
1079
  hooks?: PluginHookRegistry;
1066
1080
  hookCtx?: PluginHookAgentContext;
1081
+ onFallback?: (reason: "timeout" | "error") => void;
1067
1082
  };
1068
1083
  declare function generateSessionTitle(params: GenerateTitleParams): Promise<string>;
1069
1084
  //#endregion
@@ -1888,6 +1903,12 @@ type ProcessStartParams = {
1888
1903
  command: string;
1889
1904
  cwd: string;
1890
1905
  env?: Record<string, string>;
1906
+ /**
1907
+ * Run-level baseline env, applied after `process.env` but before `env`.
1908
+ * Used to carry session-scoped env from the AgentRunParams through to
1909
+ * the spawned child process.
1910
+ */
1911
+ baseEnv?: Record<string, string>;
1891
1912
  timeoutSec: number;
1892
1913
  scopeKey?: string;
1893
1914
  };
@@ -1922,6 +1943,12 @@ type ExecToolOptions = {
1922
1943
  scopeKey?: string;
1923
1944
  contextManager?: ContextManager;
1924
1945
  hitlResume?: AgentRunParams["hitlResume"];
1946
+ /**
1947
+ * Run-level baseline environment variables, applied after `process.env`
1948
+ * but before any per-call `params.env`. Used to carry session-scoped
1949
+ * env from `AgentRunParams.env` to the spawned child process.
1950
+ */
1951
+ baseEnv?: Record<string, string>;
1925
1952
  };
1926
1953
  declare function createExecTool(options: ExecToolOptions): AgentTool<typeof execSchema, Record<string, unknown>>;
1927
1954
  //#endregion
@@ -2152,7 +2179,7 @@ type BatchSpawnResult = {
2152
2179
  status: "done" | "partial_error" | "error";
2153
2180
  results: BatchSpawnItemResult[];
2154
2181
  };
2155
- type InheritedRunParams = Pick<AgentRunParams, "plugins" | "skillsLoadPaths" | "memory" | "messaging" | "historyLimit" | "topicSegmentation" | "onProgress" | "messageId" | "sessionStoreName" | "autoSkills" | "agentPolicy">;
2182
+ type InheritedRunParams = Pick<AgentRunParams, "plugins" | "skillsLoadPaths" | "memory" | "messaging" | "historyLimit" | "topicSegmentation" | "onProgress" | "messageId" | "sessionStoreName" | "autoSkills" | "agentPolicy" | "projectDir" | "env">;
2156
2183
  /** Formats the announce message injected into the parent session when a subagent completes. */
2157
2184
  declare function buildSubagentAnnounceMessage(params: {
2158
2185
  task: string;
@@ -2299,7 +2326,7 @@ type SubagentToolsContext = {
2299
2326
  depth: number;
2300
2327
  channel: AgentRunParams["channel"];
2301
2328
  llm: AgentRunParams["llm"];
2302
- inheritedRunParams?: Pick<AgentRunParams, "plugins" | "skillsLoadPaths" | "memory" | "messaging" | "historyLimit" | "topicSegmentation" | "onProgress" | "messageId" | "sessionStoreName" | "autoSkills" | "agentPolicy">;
2329
+ inheritedRunParams?: Pick<AgentRunParams, "plugins" | "skillsLoadPaths" | "memory" | "messaging" | "historyLimit" | "topicSegmentation" | "onProgress" | "messageId" | "sessionStoreName" | "autoSkills" | "agentPolicy" | "projectDir" | "env">;
2303
2330
  loopDetection?: ToolLoopDetectionConfig;
2304
2331
  autoSkillsLoadEnabled?: boolean;
2305
2332
  memoryOptions?: MemoryToolOptions;
@@ -2312,6 +2339,11 @@ type SubagentToolsContext = {
2312
2339
  hitlResume?: AgentRunParams["hitlResume"];
2313
2340
  eventDispatcher?: RunEventDispatcher; /** Callback that runs a child agent; injected to avoid circular imports */
2314
2341
  spawnFn: (params: AgentRunParams) => Promise<AgentRunResult>;
2342
+ /**
2343
+ * Run-level baseline env applied to every spawned child process. Sourced
2344
+ * from `AgentRunParams.env` and inherited by subagent runs.
2345
+ */
2346
+ baseEnv?: Record<string, string>;
2315
2347
  };
2316
2348
  /**
2317
2349
  * Creates the full set of agent tools for a given data directory.
@@ -2447,9 +2479,22 @@ type PluginRuntime = {
2447
2479
  error: (message: string) => void;
2448
2480
  };
2449
2481
  };
2482
+ /**
2483
+ * Read-only view of session-scoped state. Exposed to plugins so they can
2484
+ * discover per-run configuration (e.g. environment variables passed via
2485
+ * `AgentRunParams.env`) without re-plumbing the data through config.
2486
+ */
2487
+ session: {
2488
+ env: Record<string, string>;
2489
+ };
2450
2490
  };
2451
2491
  type CreatePluginRuntimeOptions = {
2452
2492
  pluginId: string;
2493
+ /**
2494
+ * Session-scoped env map mirrored from the current run. Frozen to
2495
+ * prevent plugins from mutating shared state.
2496
+ */
2497
+ env?: Record<string, string>;
2453
2498
  };
2454
2499
  declare function createPluginRuntime(options: CreatePluginRuntimeOptions): PluginRuntime;
2455
2500
  //#endregion
@@ -2500,6 +2545,16 @@ type PluginRuntimeContext = {
2500
2545
  };
2501
2546
  hookCtx?: PluginHookAgentContext;
2502
2547
  llmAllowlist?: string[];
2548
+ /**
2549
+ * Session-scoped environment variables supplied via `AgentRunParams.env`.
2550
+ * Plugins that spawn child processes (e.g. via the `exec` tool) should
2551
+ * merge this map into the child process environment. Plugins may also
2552
+ * read values from this map to discover session-scoped configuration.
2553
+ *
2554
+ * The map is held in memory only for the duration of the run and is
2555
+ * never written to disk; it does not cross session boundaries.
2556
+ */
2557
+ env?: Record<string, string>;
2503
2558
  };
2504
2559
  //#endregion
2505
2560
  //#region src/plugins/loader.d.ts