@schlenkr/ragents 0.1.6 → 0.1.8
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/apps/server/src/chat-handler.ts +2 -0
- package/apps/server/src/config.ts +6 -0
- package/apps/server/src/host-api.json +1 -0
- package/apps/server/src/layout.ts +0 -15
- package/apps/server/src/plugin-support/agent-tool.ts +2 -3
- package/apps/server/src/plugin-support/plugin-folder.ts +2 -1
- package/apps/server/src/provider.ts +34 -11
- package/apps/server/src/ragents/actor-chat-history.ts +1 -0
- package/apps/server/src/ragents/engine.ts +23 -24
- package/apps/server/src/ragents/journal-chat-events.ts +2 -0
- package/apps/server/src/ragents/run-owner.ts +3 -2
- package/apps/server/src/ragents/session.ts +3 -3
- package/apps/server/src/run-preparation.ts +14 -18
- package/apps/server/src/run-transfer.ts +65 -4
- package/apps/server/src/settings.ts +2 -4
- package/apps/web/dist/assets/{highlighted-body-KPVGNVTW-B9qYBARS.js → highlighted-body-KPVGNVTW-xXXhTDbh.js} +1 -1
- package/apps/web/dist/assets/{main-BCjvD2Hh.js → main-C7JeZFjs.js} +1 -1
- package/apps/web/dist/assets/{mermaid-HWGCJPDP-CvYYFK_n.js → mermaid-HWGCJPDP-DfsU5ofC.js} +69 -69
- package/apps/web/dist/assets/{runPanel-CG7kRMJh.js → runPanel-ZT6TPDLM.js} +1 -1
- package/apps/web/dist/help/guide-clients.html +13 -4
- package/apps/web/dist/help/guide-clients.md +14 -4
- package/apps/web/dist/help/guide-distributed.html +8 -3
- package/apps/web/dist/help/guide-distributed.md +8 -3
- package/apps/web/dist/help/guide-runtime.html +18 -12
- package/apps/web/dist/help/guide-runtime.md +19 -12
- package/apps/web/dist/help/mini-app.css +23 -3
- package/apps/web/dist/host-web.json +4 -4
- package/apps/web/dist/index.html +2 -2
- package/apps/web/dist/run-panel.html +2 -2
- package/apps/web/src/SessionList.tsx +16 -8
- package/apps/web/src/StartTiles.tsx +1 -1
- package/apps/web/src/api.ts +2 -0
- package/apps/web/src/panel/PanelPage.tsx +1 -1
- package/apps/web/src/panel/RunLine.tsx +4 -2
- package/apps/web/src/panel/contract.ts +2 -0
- package/bundles/ragents.activity/ragents-bundle.json +1 -1
- package/bundles/ragents.actor-programs/ragents-bundle.json +1 -1
- package/bundles/ragents.ask/ragents-bundle.json +1 -1
- package/bundles/ragents.browser/ragents-bundle.json +1 -1
- package/bundles/ragents.documents/ragents-bundle.json +1 -1
- package/bundles/ragents.lsp-fsharp/ragents-bundle.json +1 -1
- package/bundles/ragents.lsp-roslyn/ragents-bundle.json +1 -1
- package/bundles/ragents.lsp-typescript/ragents-bundle.json +1 -1
- package/bundles/ragents.model-relay/ragents-bundle.json +1 -1
- package/bundles/ragents.orchestration/ragents-bundle.json +1 -1
- package/bundles/ragents.overseer/ragents-bundle.json +1 -1
- package/bundles/ragents.processes/ragents-bundle.json +1 -1
- package/bundles/ragents.product/ragents-bundle.json +1 -1
- package/bundles/ragents.profile-distribution/ragents-bundle.json +1 -1
- package/bundles/ragents.reference/ragents-bundle.json +2 -2
- package/bundles/ragents.reference/run-scripts/learning-afternoon/tests/program.test.ts +1 -1
- package/bundles/ragents.reference/run-scripts/word-game/tests/program.test.ts +3 -3
- package/bundles/ragents.todo/ragents-bundle.json +1 -1
- package/bundles/ragents.transcript/ragents-bundle.json +1 -1
- package/bundles/ragents.watch/ragents-bundle.json +1 -1
- package/bundles/ragents.workspace/ragents-bundle.json +1 -1
- package/package.json +2 -2
- package/packages/agent/dist/core/agent-settings.d.ts +2 -2
- package/packages/agent/dist/core/compaction/compaction.d.ts +16 -50
- package/packages/agent/dist/core/context-log.d.ts +25 -0
- package/packages/agent/dist/core/messages.d.ts +3 -10
- package/packages/agent/dist/core/tool-definition.d.ts +17 -0
- package/packages/agent/dist/core/tools/bash.d.ts +2 -7
- package/packages/agent/dist/core/tools/edit.d.ts +1 -1
- package/packages/agent/dist/core/tools/read.d.ts +1 -1
- package/packages/agent/dist/core/tools/write.d.ts +1 -1
- package/packages/agent/dist/index.d.ts +7 -8
- package/packages/agent/dist/loop/agent.d.ts +2 -6
- package/packages/agent/package.json +1 -1
- package/packages/agent/src/core/agent-settings.ts +2 -2
- package/packages/agent/src/core/compaction/compaction.ts +49 -175
- package/packages/agent/src/core/context-log.ts +49 -0
- package/packages/agent/src/core/messages.ts +5 -11
- package/packages/agent/src/core/tool-definition.ts +29 -0
- package/packages/agent/src/core/tools/bash.ts +2 -9
- package/packages/agent/src/core/tools/edit.ts +2 -11
- package/packages/agent/src/core/tools/read.ts +3 -18
- package/packages/agent/src/core/tools/write.ts +1 -5
- package/packages/agent/src/index.ts +28 -14
- package/packages/agent/src/loop/agent-loop.ts +1 -2
- package/packages/agent/src/loop/agent.ts +8 -2
- package/packages/ai/dist/api/ai-sdk.d.ts +2 -0
- package/packages/ai/dist/types.d.ts +2 -0
- package/packages/ai/src/api/ai-sdk-messages.ts +15 -10
- package/packages/ai/src/api/ai-sdk.ts +11 -0
- package/packages/ai/src/api/transform-messages.ts +1 -1
- package/packages/ai/src/types.ts +2 -0
- package/packages/ai/src/utils/retry.ts +14 -0
- package/packages/ragents/src/agents/actor-input.ts +15 -0
- package/packages/ragents/src/agents/model-context.ts +360 -0
- package/packages/ragents/src/agents/plugins.ts +5 -0
- package/packages/ragents/src/agents/scheduler.ts +3 -7
- package/packages/ragents/src/agents/tools.ts +2 -2
- package/packages/ragents/src/agents/toolset.ts +47 -20
- package/packages/ragents/src/agents/workspaces.ts +0 -6
- package/packages/ragents/src/domain/event-semantics.ts +51 -0
- package/packages/ragents/src/domain/event-validation.ts +166 -0
- package/packages/ragents/src/domain/events.ts +72 -0
- package/packages/ragents/src/domain/model.ts +4 -2
- package/packages/ragents/src/domain/projection.ts +9 -0
- package/packages/ragents/src/domain/tool-result-text.ts +9 -0
- package/packages/ragents/src/drivers/agent-hooks.ts +25 -38
- package/packages/ragents/src/drivers/agent-runtime.ts +118 -933
- package/packages/ragents/src/drivers/agent-turn.ts +735 -0
- package/packages/ragents/src/drivers/agent.ts +9 -7
- package/packages/ragents/src/drivers/skill-preload.ts +53 -63
- package/packages/ragents/src/drivers/types.ts +21 -5
- package/packages/ragents/src/index.ts +8 -6
- package/packages/ragents/src/plugin-host.ts +60 -13
- package/packages/ragents/src/plugin-types.ts +7 -2
- package/packages/ragents/src/runtime/decisions/actors.ts +10 -0
- package/packages/ragents/src/runtime/decisions/turns.ts +66 -7
- package/packages/ragents/src/runtime/journal-storage.ts +7 -4
- package/packages/ragents/src/runtime/journal.ts +35 -0
- package/packages/ragents/src/runtime/orchestration.ts +140 -9
- package/packages/workspace-executor/src/sandbox-tools.ts +10 -11
- package/plugins/ragents.reference/run-scripts/learning-afternoon/tests/program.test.ts +1 -1
- package/plugins/ragents.reference/run-scripts/word-game/tests/program.test.ts +3 -3
- package/scripts/agent/journal.ts +5 -3
- package/scripts/package/publish-package.ts +4 -3
- package/packages/agent/dist/core/agent-session-runtime.d.ts +0 -33
- package/packages/agent/dist/core/agent-session-services.d.ts +0 -35
- package/packages/agent/dist/core/agent-session.d.ts +0 -234
- package/packages/agent/dist/core/auth-guidance.d.ts +0 -4
- package/packages/agent/dist/core/defaults.d.ts +0 -3
- package/packages/agent/dist/core/extensions/index.d.ts +0 -11
- package/packages/agent/dist/core/extensions/loader.d.ts +0 -12
- package/packages/agent/dist/core/extensions/runner.d.ts +0 -39
- package/packages/agent/dist/core/extensions/types.d.ts +0 -156
- package/packages/agent/dist/core/extensions/wrapper.d.ts +0 -12
- package/packages/agent/dist/core/resource-loader.d.ts +0 -39
- package/packages/agent/dist/core/sdk.d.ts +0 -38
- package/packages/agent/dist/core/session-manager.d.ts +0 -189
- package/packages/agent/dist/core/source-info.d.ts +0 -16
- package/packages/agent/dist/core/system-prompt.d.ts +0 -21
- package/packages/agent/src/core/agent-session-runtime.ts +0 -94
- package/packages/agent/src/core/agent-session-services.ts +0 -74
- package/packages/agent/src/core/agent-session.ts +0 -1108
- package/packages/agent/src/core/auth-guidance.ts +0 -14
- package/packages/agent/src/core/defaults.ts +0 -3
- package/packages/agent/src/core/extensions/index.ts +0 -38
- package/packages/agent/src/core/extensions/loader.ts +0 -125
- package/packages/agent/src/core/extensions/runner.ts +0 -211
- package/packages/agent/src/core/extensions/types.ts +0 -197
- package/packages/agent/src/core/extensions/wrapper.ts +0 -24
- package/packages/agent/src/core/resource-loader.ts +0 -142
- package/packages/agent/src/core/sdk.ts +0 -123
- package/packages/agent/src/core/session-manager.ts +0 -743
- package/packages/agent/src/core/source-info.ts +0 -28
- package/packages/agent/src/core/system-prompt.ts +0 -108
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Extension system for agent hooks and custom tools.
|
|
3
|
-
*/
|
|
4
|
-
export type { SourceInfo } from "../source-info.ts";
|
|
5
|
-
export { createExtensionRuntime, loadExtensionFromFactory } from "./loader.ts";
|
|
6
|
-
export type { ExtensionContextSource, ExtensionErrorListener } from "./runner.ts";
|
|
7
|
-
export { ExtensionRunner, STALE_EXTENSION_MESSAGE } from "./runner.ts";
|
|
8
|
-
export type { AgentToolResult, AgentToolUpdateCallback, BeforeAgentStartEvent, BeforeAgentStartEventResult, BuildSystemPromptOptions, ContextEvent, ContextEventResult, Extension, ExtensionActions, ExtensionAPI, ExtensionContext, ExtensionError, ExtensionEvent, ExtensionFactory, ExtensionFactoryContext, ExtensionFactorySettlementObserver, ExtensionHandler, ExtensionRuntime, InlineExtension, LoadExtensionsResult, RegisteredTool, ToolDefinition, ToolExecutionMode, ToolInfo, ToolResultEvent, ToolResultEventResult, } from "./types.ts";
|
|
9
|
-
export { defineTool } from "./types.ts";
|
|
10
|
-
export { wrapRegisteredTools } from "./wrapper.ts";
|
|
11
|
-
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Extension loader - creates extensions from inline factories.
|
|
3
|
-
*/
|
|
4
|
-
import type { Extension, ExtensionFactory, ExtensionFactorySettlementObserver, ExtensionRuntime } from "./types.ts";
|
|
5
|
-
/**
|
|
6
|
-
* Create a runtime with throwing stubs for action methods.
|
|
7
|
-
* Runner.bindCore() replaces these with real implementations.
|
|
8
|
-
*/
|
|
9
|
-
export declare function createExtensionRuntime(): ExtensionRuntime;
|
|
10
|
-
/** Create an Extension from an inline factory function. */
|
|
11
|
-
export declare function loadExtensionFromFactory(factory: ExtensionFactory, runtime: ExtensionRuntime, extensionPath: string, signal?: AbortSignal, onFactorySettlement?: ExtensionFactorySettlementObserver): Promise<Extension>;
|
|
12
|
-
//# sourceMappingURL=loader.d.ts.map
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Extension runner - executes extension handlers against one agent session.
|
|
3
|
-
*/
|
|
4
|
-
import type { AgentMessage } from "../../loop/index.ts";
|
|
5
|
-
import type { Model, UserAttachment } from "@ragents/ai";
|
|
6
|
-
import type { SessionManager } from "../session-manager.ts";
|
|
7
|
-
import type { BuildSystemPromptOptions } from "../system-prompt.ts";
|
|
8
|
-
import type { Extension, ExtensionActions, ExtensionContext, ExtensionError, ExtensionRuntime, RegisteredTool, ToolResultEvent, ToolResultEventResult } from "./types.ts";
|
|
9
|
-
export type ExtensionErrorListener = (error: ExtensionError) => void;
|
|
10
|
-
/** What the runner reads from its session when it builds a handler context. */
|
|
11
|
-
export interface ExtensionContextSource {
|
|
12
|
-
getModel: () => Model<any> | undefined;
|
|
13
|
-
getSignal: () => AbortSignal | undefined;
|
|
14
|
-
}
|
|
15
|
-
export declare const STALE_EXTENSION_MESSAGE = "This extension is stale: its agent session was disposed.";
|
|
16
|
-
export declare class ExtensionRunner {
|
|
17
|
-
private readonly extensions;
|
|
18
|
-
private readonly runtime;
|
|
19
|
-
private readonly sessionManager;
|
|
20
|
-
private readonly errorListeners;
|
|
21
|
-
private contextSource;
|
|
22
|
-
private staleMessage;
|
|
23
|
-
constructor(extensions: Extension[], runtime: ExtensionRuntime, sessionManager: SessionManager);
|
|
24
|
-
bindCore(actions: ExtensionActions, contextSource: ExtensionContextSource): void;
|
|
25
|
-
/** Get all registered tools from all extensions (first registration per name wins). */
|
|
26
|
-
getAllRegisteredTools(): RegisteredTool[];
|
|
27
|
-
invalidate(message?: string): void;
|
|
28
|
-
private assertActive;
|
|
29
|
-
onError(listener: ExtensionErrorListener): () => void;
|
|
30
|
-
private emitError;
|
|
31
|
-
hasHandlers(eventType: string): boolean;
|
|
32
|
-
/** Context values are resolved at call time, so a disposed session is detected on every access. */
|
|
33
|
-
createContext(): ExtensionContext;
|
|
34
|
-
emitToolResult(event: ToolResultEvent): Promise<ToolResultEventResult | undefined>;
|
|
35
|
-
emitContext(messages: AgentMessage[]): Promise<AgentMessage[]>;
|
|
36
|
-
/** Chains the system prompt through all before_agent_start handlers; undefined when none changed it. */
|
|
37
|
-
emitBeforeAgentStart(prompt: string, systemPrompt: string, systemPromptOptions: BuildSystemPromptOptions, attachments?: UserAttachment[]): Promise<string | undefined>;
|
|
38
|
-
}
|
|
39
|
-
//# sourceMappingURL=runner.d.ts.map
|
|
@@ -1,156 +0,0 @@
|
|
|
1
|
-
/** Extensions are inline factories: they adjust the system prompt, the messages of a model call and tool results, and register tools. */
|
|
2
|
-
import type { AgentMessage, AgentToolResult, AgentToolUpdateCallback, ToolExecutionMode } from "../../loop/index.ts";
|
|
3
|
-
import type { ImageContent, Model, TextContent, UserAttachment } from "@ragents/ai";
|
|
4
|
-
import type { Static, TSchema } from "typebox";
|
|
5
|
-
import type { ReadonlySessionManager } from "../session-manager.ts";
|
|
6
|
-
import type { SourceInfo } from "../source-info.ts";
|
|
7
|
-
import type { BuildSystemPromptOptions } from "../system-prompt.ts";
|
|
8
|
-
export type { BuildSystemPromptOptions } from "../system-prompt.ts";
|
|
9
|
-
export type { AgentToolResult, AgentToolUpdateCallback, ToolExecutionMode };
|
|
10
|
-
/** Context passed to extension event handlers and tools. */
|
|
11
|
-
export interface ExtensionContext {
|
|
12
|
-
/** Session manager (read-only) */
|
|
13
|
-
sessionManager: ReadonlySessionManager;
|
|
14
|
-
/** Current model (may be undefined) */
|
|
15
|
-
model: Model<any> | undefined;
|
|
16
|
-
/** The current abort signal, or undefined when the agent is not streaming. */
|
|
17
|
-
signal: AbortSignal | undefined;
|
|
18
|
-
}
|
|
19
|
-
/** Tool definition for registerTool(). */
|
|
20
|
-
export interface ToolDefinition<TParams extends TSchema = TSchema, TDetails = unknown, TState = any> {
|
|
21
|
-
/** Tool name (used in LLM tool calls) */
|
|
22
|
-
name: string;
|
|
23
|
-
/** Human-readable label */
|
|
24
|
-
label: string;
|
|
25
|
-
/** Description for LLM */
|
|
26
|
-
description: string;
|
|
27
|
-
/** Optional one-line snippet for the Available tools section in the default system prompt. */
|
|
28
|
-
promptSnippet?: string;
|
|
29
|
-
/** Optional guideline bullets appended to the default system prompt Guidelines section when this tool is active. */
|
|
30
|
-
promptGuidelines?: string[];
|
|
31
|
-
/** Parameter schema (TypeBox) */
|
|
32
|
-
parameters: TParams;
|
|
33
|
-
/** Optional compatibility shim to prepare raw tool call arguments before schema validation. */
|
|
34
|
-
prepareArguments?: (args: unknown) => Static<TParams>;
|
|
35
|
-
/** Per-tool execution mode override; if omitted, the default execution mode applies. */
|
|
36
|
-
executionMode?: ToolExecutionMode;
|
|
37
|
-
/** Execute the tool. */
|
|
38
|
-
execute(toolCallId: string, params: Static<TParams>, signal: AbortSignal | undefined, onUpdate: AgentToolUpdateCallback<TDetails> | undefined, ctx: ExtensionContext): Promise<AgentToolResult<TDetails>>;
|
|
39
|
-
}
|
|
40
|
-
type AnyToolDefinition = ToolDefinition<any, any, any>;
|
|
41
|
-
/** Preserve parameter inference for standalone tool definitions. */
|
|
42
|
-
export declare function defineTool<TParams extends TSchema, TDetails = unknown, TState = any>(tool: ToolDefinition<TParams, TDetails, TState>): ToolDefinition<TParams, TDetails, TState> & AnyToolDefinition;
|
|
43
|
-
/** Fired before each LLM call. Can modify messages. */
|
|
44
|
-
export interface ContextEvent {
|
|
45
|
-
type: "context";
|
|
46
|
-
messages: AgentMessage[];
|
|
47
|
-
}
|
|
48
|
-
/** Fired after the user submits a prompt but before the agent loop. */
|
|
49
|
-
export interface BeforeAgentStartEvent {
|
|
50
|
-
type: "before_agent_start";
|
|
51
|
-
/** The raw user prompt text. */
|
|
52
|
-
prompt: string;
|
|
53
|
-
attachments?: UserAttachment[];
|
|
54
|
-
/** The fully assembled system prompt string. */
|
|
55
|
-
systemPrompt: string;
|
|
56
|
-
/** Structured options used to build the system prompt. */
|
|
57
|
-
systemPromptOptions: BuildSystemPromptOptions;
|
|
58
|
-
}
|
|
59
|
-
/** Fired after a tool executes. Can modify the result. */
|
|
60
|
-
export interface ToolResultEvent {
|
|
61
|
-
type: "tool_result";
|
|
62
|
-
toolCallId: string;
|
|
63
|
-
toolName: string;
|
|
64
|
-
input: Record<string, unknown>;
|
|
65
|
-
content: (TextContent | ImageContent)[];
|
|
66
|
-
details: unknown;
|
|
67
|
-
isError: boolean;
|
|
68
|
-
}
|
|
69
|
-
export type ExtensionEvent = ContextEvent | BeforeAgentStartEvent | ToolResultEvent;
|
|
70
|
-
export interface ContextEventResult {
|
|
71
|
-
messages?: AgentMessage[];
|
|
72
|
-
}
|
|
73
|
-
export interface ToolResultEventResult {
|
|
74
|
-
content?: (TextContent | ImageContent)[];
|
|
75
|
-
details?: unknown;
|
|
76
|
-
isError?: boolean;
|
|
77
|
-
}
|
|
78
|
-
export interface BeforeAgentStartEventResult {
|
|
79
|
-
/** Replace the system prompt for this turn. If multiple extensions return this, they are chained. */
|
|
80
|
-
systemPrompt?: string;
|
|
81
|
-
}
|
|
82
|
-
/** Handler function type for events */
|
|
83
|
-
export type ExtensionHandler<E, R = undefined> = (event: E, ctx: ExtensionContext) => Promise<R | void> | R | void;
|
|
84
|
-
/** ExtensionAPI passed to extension factory functions. */
|
|
85
|
-
export interface ExtensionAPI {
|
|
86
|
-
on(event: "before_agent_start", handler: ExtensionHandler<BeforeAgentStartEvent, BeforeAgentStartEventResult>): void;
|
|
87
|
-
on(event: "context", handler: ExtensionHandler<ContextEvent, ContextEventResult>): void;
|
|
88
|
-
on(event: "tool_result", handler: ExtensionHandler<ToolResultEvent, ToolResultEventResult>): void;
|
|
89
|
-
/** Register a tool that the LLM can call. */
|
|
90
|
-
registerTool<TParams extends TSchema = TSchema, TDetails = unknown, TState = any>(tool: ToolDefinition<TParams, TDetails, TState>): void;
|
|
91
|
-
/** Append a custom entry to the session for state persistence (not sent to LLM). */
|
|
92
|
-
appendEntry<T = unknown>(customType: string, data?: T): void;
|
|
93
|
-
/** Get all configured tools with parameter schema, prompt guidelines, and source metadata. */
|
|
94
|
-
getAllTools(): ToolInfo[];
|
|
95
|
-
/** Set the active tools by name. */
|
|
96
|
-
setActiveTools(toolNames: string[]): void;
|
|
97
|
-
}
|
|
98
|
-
export interface ExtensionFactoryContext {
|
|
99
|
-
readonly signal: AbortSignal;
|
|
100
|
-
}
|
|
101
|
-
/** Extension factory function type. Supports both sync and async initialization. */
|
|
102
|
-
export type ExtensionFactory = (agent: ExtensionAPI, context: ExtensionFactoryContext) => void | Promise<void>;
|
|
103
|
-
/** Observes the actual lifetime of an async extension factory, independently of an aborted loader wait. */
|
|
104
|
-
export type ExtensionFactorySettlementObserver = (settlement: Promise<void>) => void;
|
|
105
|
-
export type InlineExtension = ExtensionFactory | {
|
|
106
|
-
/** Display name shown as `<inline:name>`. */
|
|
107
|
-
name: string;
|
|
108
|
-
factory: ExtensionFactory;
|
|
109
|
-
};
|
|
110
|
-
export interface RegisteredTool {
|
|
111
|
-
definition: ToolDefinition;
|
|
112
|
-
sourceInfo: SourceInfo;
|
|
113
|
-
}
|
|
114
|
-
type HandlerFn = (...args: unknown[]) => Promise<unknown>;
|
|
115
|
-
/** Tool info with name, description, parameter schema, prompt guidelines, and source metadata. */
|
|
116
|
-
export type ToolInfo = Pick<ToolDefinition, "name" | "description" | "parameters" | "promptGuidelines"> & {
|
|
117
|
-
sourceInfo: SourceInfo;
|
|
118
|
-
};
|
|
119
|
-
/** Action implementations behind the ExtensionAPI, provided by the session. */
|
|
120
|
-
export interface ExtensionActions {
|
|
121
|
-
appendEntry: <T = unknown>(customType: string, data?: T) => void;
|
|
122
|
-
getAllTools: () => ToolInfo[];
|
|
123
|
-
setActiveTools: (toolNames: string[]) => void;
|
|
124
|
-
refreshTools: () => void;
|
|
125
|
-
}
|
|
126
|
-
/** Shared state created by the loader; actions are throwing stubs until the runner binds the session. */
|
|
127
|
-
export interface ExtensionRuntime extends ExtensionActions {
|
|
128
|
-
/** Throws when this extension instance is stale. */
|
|
129
|
-
assertActive: () => void;
|
|
130
|
-
/** Marks this extension instance as stale. */
|
|
131
|
-
invalidate: (message?: string) => void;
|
|
132
|
-
}
|
|
133
|
-
/** Loaded extension with all registered items. */
|
|
134
|
-
export interface Extension {
|
|
135
|
-
path: string;
|
|
136
|
-
sourceInfo: SourceInfo;
|
|
137
|
-
handlers: Map<string, HandlerFn[]>;
|
|
138
|
-
tools: Map<string, RegisteredTool>;
|
|
139
|
-
}
|
|
140
|
-
/** Result of loading extensions. */
|
|
141
|
-
export interface LoadExtensionsResult {
|
|
142
|
-
extensions: Extension[];
|
|
143
|
-
errors: Array<{
|
|
144
|
-
path: string;
|
|
145
|
-
error: string;
|
|
146
|
-
}>;
|
|
147
|
-
/** Shared runtime - actions are throwing stubs until the runner binds the session */
|
|
148
|
-
runtime: ExtensionRuntime;
|
|
149
|
-
}
|
|
150
|
-
export interface ExtensionError {
|
|
151
|
-
extensionPath: string;
|
|
152
|
-
event: string;
|
|
153
|
-
error: string;
|
|
154
|
-
stack?: string;
|
|
155
|
-
}
|
|
156
|
-
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Tool wrappers for extension-registered tools.
|
|
3
|
-
*
|
|
4
|
-
* These wrappers only adapt tool execution so extension tools receive the runner context.
|
|
5
|
-
* Tool result interception is handled by AgentSession via the hooks of the agent loop.
|
|
6
|
-
*/
|
|
7
|
-
import type { AgentTool } from "../../loop/index.ts";
|
|
8
|
-
import type { ExtensionRunner } from "./runner.ts";
|
|
9
|
-
import type { RegisteredTool } from "./types.ts";
|
|
10
|
-
/** Wrap registered tools into AgentTools that receive the runner context on every call. */
|
|
11
|
-
export declare function wrapRegisteredTools(registeredTools: RegisteredTool[], runner: ExtensionRunner): AgentTool[];
|
|
12
|
-
//# sourceMappingURL=wrapper.d.ts.map
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import type { ExtensionFactorySettlementObserver, InlineExtension, LoadExtensionsResult } from "./extensions/types.ts";
|
|
2
|
-
import type { Skill } from "./skills.ts";
|
|
3
|
-
export interface ResourceLoaderReloadOptions {
|
|
4
|
-
signal?: AbortSignal;
|
|
5
|
-
}
|
|
6
|
-
export interface ResourceLoader {
|
|
7
|
-
getExtensions(): LoadExtensionsResult;
|
|
8
|
-
getSkills(): readonly Skill[];
|
|
9
|
-
getSystemPrompt(): string | undefined;
|
|
10
|
-
setSystemPrompt(value: string): void;
|
|
11
|
-
reload(options?: ResourceLoaderReloadOptions): Promise<void>;
|
|
12
|
-
waitForSettlement?(): Promise<void> | undefined;
|
|
13
|
-
}
|
|
14
|
-
export interface DefaultResourceLoaderOptions {
|
|
15
|
-
skills?: readonly Skill[];
|
|
16
|
-
extensionFactories?: InlineExtension[];
|
|
17
|
-
systemPrompt?: string;
|
|
18
|
-
onExtensionFactorySettlement?: ExtensionFactorySettlementObserver;
|
|
19
|
-
}
|
|
20
|
-
/** Extensions come only as inline factories and skills as given by the caller; nothing is discovered or installed. */
|
|
21
|
-
export declare class DefaultResourceLoader implements ResourceLoader {
|
|
22
|
-
private readonly skills;
|
|
23
|
-
private readonly extensionFactories;
|
|
24
|
-
private readonly onExtensionFactorySettlement?;
|
|
25
|
-
private readonly extensionFactorySettlements;
|
|
26
|
-
private extensionsResult;
|
|
27
|
-
private systemPrompt?;
|
|
28
|
-
constructor(options: DefaultResourceLoaderOptions);
|
|
29
|
-
getExtensions(): LoadExtensionsResult;
|
|
30
|
-
waitForSettlement(): Promise<void> | undefined;
|
|
31
|
-
private readonly trackExtensionFactorySettlement;
|
|
32
|
-
getSkills(): readonly Skill[];
|
|
33
|
-
getSystemPrompt(): string | undefined;
|
|
34
|
-
setSystemPrompt(value: string): void;
|
|
35
|
-
reload(options?: ResourceLoaderReloadOptions): Promise<void>;
|
|
36
|
-
private loadExtensionFactories;
|
|
37
|
-
private detectToolConflicts;
|
|
38
|
-
}
|
|
39
|
-
//# sourceMappingURL=resource-loader.d.ts.map
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import { type ThinkingLevel } from "../loop/index.ts";
|
|
2
|
-
import { type Model } from "@ragents/ai";
|
|
3
|
-
import { AgentSession } from "./agent-session.ts";
|
|
4
|
-
import type { LoadExtensionsResult, ToolDefinition } from "./extensions/index.ts";
|
|
5
|
-
import type { ModelRuntime } from "./model-runtime.ts";
|
|
6
|
-
import type { ResourceLoader } from "./resource-loader.ts";
|
|
7
|
-
import type { SessionManager } from "./session-manager.ts";
|
|
8
|
-
import { type AgentSettingsInput } from "./agent-settings.ts";
|
|
9
|
-
export interface CreateAgentSessionOptions {
|
|
10
|
-
/** Working directory of the session. Default: the working directory of the session manager */
|
|
11
|
-
cwd?: string;
|
|
12
|
-
modelRuntime: ModelRuntime;
|
|
13
|
-
/** The model of the session; a session without one is an error. */
|
|
14
|
-
model: Model<any>;
|
|
15
|
-
/** Thinking level. Default: from the session, else settings, else 'medium' (clamped to model capabilities) */
|
|
16
|
-
thinkingLevel?: ThinkingLevel;
|
|
17
|
-
/** Optional allowlist of tool names; without it every registered tool is enabled. */
|
|
18
|
-
tools?: string[];
|
|
19
|
-
/** Custom tools to register besides the tools of extensions. */
|
|
20
|
-
customTools?: ToolDefinition[];
|
|
21
|
-
/** Loaded resources: extensions, skills and the system prompt. */
|
|
22
|
-
resourceLoader: ResourceLoader;
|
|
23
|
-
sessionManager: SessionManager;
|
|
24
|
-
settings?: AgentSettingsInput;
|
|
25
|
-
}
|
|
26
|
-
/** Result from createAgentSession */
|
|
27
|
-
export interface CreateAgentSessionResult {
|
|
28
|
-
/** The created session */
|
|
29
|
-
session: AgentSession;
|
|
30
|
-
/** Extensions of the session, with the errors of their factories */
|
|
31
|
-
extensionsResult: LoadExtensionsResult;
|
|
32
|
-
}
|
|
33
|
-
export * from "./agent-session-runtime.ts";
|
|
34
|
-
export type { ExtensionAPI, ExtensionContext, ExtensionFactory, InlineExtension, ToolDefinition } from "./extensions/index.ts";
|
|
35
|
-
export type { Skill } from "./skills.ts";
|
|
36
|
-
/** Create an AgentSession for the given model. */
|
|
37
|
-
export declare function createAgentSession(options: CreateAgentSessionOptions): Promise<CreateAgentSessionResult>;
|
|
38
|
-
//# sourceMappingURL=sdk.d.ts.map
|
|
@@ -1,189 +0,0 @@
|
|
|
1
|
-
import { type AgentMessage } from "../loop/index.ts";
|
|
2
|
-
import type { Message } from "@ragents/ai";
|
|
3
|
-
import { type CustomMessage } from "./messages.ts";
|
|
4
|
-
export declare const CURRENT_SESSION_VERSION = 3;
|
|
5
|
-
export interface SessionHeader {
|
|
6
|
-
type: "session";
|
|
7
|
-
version?: number;
|
|
8
|
-
id: string;
|
|
9
|
-
timestamp: string;
|
|
10
|
-
cwd: string;
|
|
11
|
-
parentSession?: string;
|
|
12
|
-
}
|
|
13
|
-
export interface NewSessionOptions {
|
|
14
|
-
id?: string;
|
|
15
|
-
parentSession?: string;
|
|
16
|
-
}
|
|
17
|
-
export interface SessionEntryBase {
|
|
18
|
-
type: string;
|
|
19
|
-
id: string;
|
|
20
|
-
parentId: string | null;
|
|
21
|
-
timestamp: string;
|
|
22
|
-
}
|
|
23
|
-
export interface SessionMessageEntry extends SessionEntryBase {
|
|
24
|
-
type: "message";
|
|
25
|
-
message: AgentMessage;
|
|
26
|
-
}
|
|
27
|
-
export interface ThinkingLevelChangeEntry extends SessionEntryBase {
|
|
28
|
-
type: "thinking_level_change";
|
|
29
|
-
thinkingLevel: string;
|
|
30
|
-
}
|
|
31
|
-
export interface ModelChangeEntry extends SessionEntryBase {
|
|
32
|
-
type: "model_change";
|
|
33
|
-
provider: string;
|
|
34
|
-
modelId: string;
|
|
35
|
-
}
|
|
36
|
-
export interface CompactionEntry<T = unknown> extends SessionEntryBase {
|
|
37
|
-
type: "compaction";
|
|
38
|
-
summary: string;
|
|
39
|
-
firstKeptEntryId: string;
|
|
40
|
-
tokensBefore: number;
|
|
41
|
-
/** Extension-specific data (e.g., ArtifactIndex, version markers for structured compaction) */
|
|
42
|
-
details?: T;
|
|
43
|
-
/** True if generated by an extension, undefined/false if agent-generated (backward compatible) */
|
|
44
|
-
fromHook?: boolean;
|
|
45
|
-
}
|
|
46
|
-
/**
|
|
47
|
-
* Custom entry for extensions to store extension-specific data in the session.
|
|
48
|
-
* Use customType to identify your extension's entries.
|
|
49
|
-
*
|
|
50
|
-
* Purpose: Persist extension state across session reloads. On reload, extensions can
|
|
51
|
-
* scan entries for their customType and reconstruct internal state.
|
|
52
|
-
*
|
|
53
|
-
* Does NOT participate in LLM context (ignored by buildSessionContext).
|
|
54
|
-
* For injecting content into context, see CustomMessageEntry.
|
|
55
|
-
*/
|
|
56
|
-
export interface CustomEntry<T = unknown> extends SessionEntryBase {
|
|
57
|
-
type: "custom";
|
|
58
|
-
customType: string;
|
|
59
|
-
data?: T;
|
|
60
|
-
}
|
|
61
|
-
/** Session entry - has id/parentId for tree structure (returned by "read" methods in SessionManager) */
|
|
62
|
-
export type SessionEntry = SessionMessageEntry | ThinkingLevelChangeEntry | ModelChangeEntry | CompactionEntry | CustomEntry;
|
|
63
|
-
/** Raw file entry (includes header) */
|
|
64
|
-
export type FileEntry = SessionHeader | SessionEntry;
|
|
65
|
-
export interface SessionContext {
|
|
66
|
-
messages: AgentMessage[];
|
|
67
|
-
thinkingLevel: string;
|
|
68
|
-
model: {
|
|
69
|
-
provider: string;
|
|
70
|
-
modelId: string;
|
|
71
|
-
} | null;
|
|
72
|
-
}
|
|
73
|
-
export type ReadonlySessionManager = Pick<SessionManager, "getBranch">;
|
|
74
|
-
export declare function assertValidSessionId(id: string): void;
|
|
75
|
-
export declare function getLatestCompactionEntry(entries: SessionEntry[]): CompactionEntry | null;
|
|
76
|
-
/**
|
|
77
|
-
* Project one selected session entry into LLM/runtime messages.
|
|
78
|
-
* Plain custom entries are display/state entries and do not participate in context.
|
|
79
|
-
*/
|
|
80
|
-
export declare function sessionEntryToContextMessages(entry: SessionEntry): AgentMessage[];
|
|
81
|
-
/**
|
|
82
|
-
* Build the active, compaction-aware session entry list.
|
|
83
|
-
*
|
|
84
|
-
* This follows the current leaf path. If the path contains compaction entries,
|
|
85
|
-
* the latest compaction is represented by the compaction entry itself, followed
|
|
86
|
-
* by the kept entries starting at firstKeptEntryId and all entries after the
|
|
87
|
-
* compaction entry. Older summarized entries are omitted.
|
|
88
|
-
*/
|
|
89
|
-
export declare function buildContextEntries(entries: SessionEntry[], leafId?: string | null, byId?: Map<string, SessionEntry>): SessionEntry[];
|
|
90
|
-
/**
|
|
91
|
-
* Build the session context from entries using tree traversal.
|
|
92
|
-
* If leafId is provided, walks from that entry to root.
|
|
93
|
-
* Handles compaction and branch summaries along the path.
|
|
94
|
-
*/
|
|
95
|
-
export declare function buildSessionContext(entries: SessionEntry[], leafId?: string | null, byId?: Map<string, SessionEntry>): SessionContext;
|
|
96
|
-
/** Exported for testing */
|
|
97
|
-
export declare function loadEntriesFromFile(filePath: string): FileEntry[];
|
|
98
|
-
/**
|
|
99
|
-
* Manages conversation sessions as append-only trees stored in JSONL files.
|
|
100
|
-
*
|
|
101
|
-
* Each session entry has an id and parentId forming a tree structure. The "leaf"
|
|
102
|
-
* pointer tracks the current position. Appending creates a child of the current leaf.
|
|
103
|
-
* Branching moves the leaf to an earlier entry, allowing new branches without
|
|
104
|
-
* modifying history.
|
|
105
|
-
*
|
|
106
|
-
* Use buildSessionContext() to get the resolved message list for the LLM, which
|
|
107
|
-
* handles compaction summaries and follows the path from root to current leaf.
|
|
108
|
-
*/
|
|
109
|
-
export declare class SessionManager {
|
|
110
|
-
private sessionId;
|
|
111
|
-
private sessionFile;
|
|
112
|
-
private sessionDir;
|
|
113
|
-
private cwd;
|
|
114
|
-
private persist;
|
|
115
|
-
private flushed;
|
|
116
|
-
private fileEntries;
|
|
117
|
-
private byId;
|
|
118
|
-
private leafId;
|
|
119
|
-
private constructor();
|
|
120
|
-
/** Switch to a different session file (used for resume and branching) */
|
|
121
|
-
setSessionFile(sessionFile: string): void;
|
|
122
|
-
newSession(options?: NewSessionOptions): string | undefined;
|
|
123
|
-
private _buildIndex;
|
|
124
|
-
private _rewriteFile;
|
|
125
|
-
isPersisted(): boolean;
|
|
126
|
-
getCwd(): string;
|
|
127
|
-
getSessionDir(): string;
|
|
128
|
-
getSessionId(): string;
|
|
129
|
-
getSessionFile(): string | undefined;
|
|
130
|
-
_persist(entry: SessionEntry): void;
|
|
131
|
-
private _appendEntry;
|
|
132
|
-
/** Append a message as child of current leaf, then advance leaf. Returns entry id.
|
|
133
|
-
* Compaction summaries are top-level entries appended via appendCompaction(), not message entries.
|
|
134
|
-
*/
|
|
135
|
-
appendMessage(message: Message | CustomMessage): string;
|
|
136
|
-
/** Append a thinking level change as child of current leaf, then advance leaf. Returns entry id. */
|
|
137
|
-
appendThinkingLevelChange(thinkingLevel: string): string;
|
|
138
|
-
/** Append a model change as child of current leaf, then advance leaf. Returns entry id. */
|
|
139
|
-
appendModelChange(provider: string, modelId: string): string;
|
|
140
|
-
/** Append a compaction summary as child of current leaf, then advance leaf. Returns entry id. */
|
|
141
|
-
appendCompaction<T = unknown>(summary: string, firstKeptEntryId: string, tokensBefore: number, details?: T, fromHook?: boolean): string;
|
|
142
|
-
/** Append a custom entry (for extensions) as child of current leaf, then advance leaf. Returns entry id. */
|
|
143
|
-
appendCustomEntry(customType: string, data?: unknown): string;
|
|
144
|
-
getLeafId(): string | null;
|
|
145
|
-
getLeafEntry(): SessionEntry | undefined;
|
|
146
|
-
getEntry(id: string): SessionEntry | undefined;
|
|
147
|
-
/**
|
|
148
|
-
* Walk from entry to root, returning all entries in path order.
|
|
149
|
-
* Includes all entry types (messages, compaction, model changes, etc.).
|
|
150
|
-
* Use buildSessionContext() to get the resolved messages for the LLM.
|
|
151
|
-
*/
|
|
152
|
-
getBranch(fromId?: string): SessionEntry[];
|
|
153
|
-
/**
|
|
154
|
-
* Build the active, compaction-aware entry list for context/rendering.
|
|
155
|
-
* Uses tree traversal from current leaf.
|
|
156
|
-
*/
|
|
157
|
-
buildContextEntries(): SessionEntry[];
|
|
158
|
-
/**
|
|
159
|
-
* Build the session context (what gets sent to the LLM).
|
|
160
|
-
* Uses tree traversal from current leaf.
|
|
161
|
-
*/
|
|
162
|
-
buildSessionContext(): SessionContext;
|
|
163
|
-
/**
|
|
164
|
-
* Get session header.
|
|
165
|
-
*/
|
|
166
|
-
getHeader(): SessionHeader | null;
|
|
167
|
-
/**
|
|
168
|
-
* Get all session entries (excludes header). Returns a shallow copy.
|
|
169
|
-
* The session is append-only: use appendXXX() to add entries, branch() to
|
|
170
|
-
* change the leaf pointer. Entries cannot be modified or deleted.
|
|
171
|
-
*/
|
|
172
|
-
getEntries(): SessionEntry[];
|
|
173
|
-
/**
|
|
174
|
-
* Create a new session.
|
|
175
|
-
* @param cwd Working directory (stored in session header)
|
|
176
|
-
* @param sessionDir Session directory
|
|
177
|
-
*/
|
|
178
|
-
static create(cwd: string, sessionDir: string, options?: NewSessionOptions): SessionManager;
|
|
179
|
-
/**
|
|
180
|
-
* Open a specific session file.
|
|
181
|
-
* @param path Path to session file
|
|
182
|
-
* @param sessionDir Optional session directory for /new or /branch. If omitted, derives from file's parent.
|
|
183
|
-
* @param cwdOverride Optional cwd override instead of the session header cwd.
|
|
184
|
-
*/
|
|
185
|
-
static open(path: string, sessionDir?: string, cwdOverride?: string): SessionManager;
|
|
186
|
-
/** Create an in-memory session (no file persistence) */
|
|
187
|
-
static inMemory(cwd?: string, options?: NewSessionOptions): SessionManager;
|
|
188
|
-
}
|
|
189
|
-
//# sourceMappingURL=session-manager.d.ts.map
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
export type SourceScope = "user" | "project" | "temporary";
|
|
2
|
-
export type SourceOrigin = "package" | "top-level";
|
|
3
|
-
export interface SourceInfo {
|
|
4
|
-
path: string;
|
|
5
|
-
source: string;
|
|
6
|
-
scope: SourceScope;
|
|
7
|
-
origin: SourceOrigin;
|
|
8
|
-
baseDir?: string;
|
|
9
|
-
}
|
|
10
|
-
export declare function createSyntheticSourceInfo(path: string, options: {
|
|
11
|
-
source: string;
|
|
12
|
-
scope?: SourceScope;
|
|
13
|
-
origin?: SourceOrigin;
|
|
14
|
-
baseDir?: string;
|
|
15
|
-
}): SourceInfo;
|
|
16
|
-
//# sourceMappingURL=source-info.d.ts.map
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* System prompt construction and project context loading
|
|
3
|
-
*/
|
|
4
|
-
import { type Skill } from "./skills.ts";
|
|
5
|
-
export interface BuildSystemPromptOptions {
|
|
6
|
-
/** Custom system prompt (replaces default). */
|
|
7
|
-
customPrompt?: string;
|
|
8
|
-
/** Tools to include in prompt. Default: [read, bash, edit, write] */
|
|
9
|
-
selectedTools?: string[];
|
|
10
|
-
/** Optional one-line tool snippets keyed by tool name. */
|
|
11
|
-
toolSnippets?: Record<string, string>;
|
|
12
|
-
/** Additional guideline bullets appended to the default system prompt guidelines. */
|
|
13
|
-
promptGuidelines?: string[];
|
|
14
|
-
/** Working directory; only the default prompt names it, a custom prompt stays as the caller wrote it. */
|
|
15
|
-
cwd: string;
|
|
16
|
-
/** Pre-loaded skills. */
|
|
17
|
-
skills?: readonly Skill[];
|
|
18
|
-
}
|
|
19
|
-
/** Build the system prompt with tools, guidelines, and context */
|
|
20
|
-
export declare function buildSystemPrompt(options: BuildSystemPromptOptions): string;
|
|
21
|
-
//# sourceMappingURL=system-prompt.d.ts.map
|
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
import type { AgentSession } from "./agent-session.ts";
|
|
2
|
-
import type { AgentSessionServices } from "./agent-session-services.ts";
|
|
3
|
-
import type { ExtensionFactorySettlementObserver } from "./extensions/index.ts";
|
|
4
|
-
import type { CreateAgentSessionResult } from "./sdk.ts";
|
|
5
|
-
import type { SessionManager } from "./session-manager.ts";
|
|
6
|
-
|
|
7
|
-
/** Result returned by runtime creation: the created session and its cwd-bound services. */
|
|
8
|
-
export interface CreateAgentSessionRuntimeResult extends CreateAgentSessionResult {
|
|
9
|
-
services: AgentSessionServices;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
/** Creates the services and the AgentSession for a target cwd and session manager. */
|
|
13
|
-
export type CreateAgentSessionRuntimeFactory = (options: {
|
|
14
|
-
cwd: string;
|
|
15
|
-
sessionManager: SessionManager;
|
|
16
|
-
signal: AbortSignal;
|
|
17
|
-
onExtensionFactorySettlement?: ExtensionFactorySettlementObserver;
|
|
18
|
-
}) => Promise<CreateAgentSessionRuntimeResult>;
|
|
19
|
-
|
|
20
|
-
function abortReason(signal: AbortSignal): Error {
|
|
21
|
-
return signal.reason instanceof Error ? signal.reason : new Error("Agent session runtime creation was aborted.");
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
function awaitWithSignal<T>(operation: Promise<T>, signal: AbortSignal): Promise<T> {
|
|
25
|
-
if (signal.aborted) {
|
|
26
|
-
return Promise.reject(abortReason(signal));
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
return new Promise<T>((resolve, reject) => {
|
|
30
|
-
const abort = () => reject(abortReason(signal));
|
|
31
|
-
signal.addEventListener("abort", abort, { once: true });
|
|
32
|
-
operation.then(resolve, reject).finally(() => signal.removeEventListener("abort", abort));
|
|
33
|
-
});
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
/** Owns one AgentSession plus its cwd-bound services. */
|
|
37
|
-
export class AgentSessionRuntime {
|
|
38
|
-
readonly session: AgentSession;
|
|
39
|
-
readonly services: AgentSessionServices;
|
|
40
|
-
|
|
41
|
-
constructor(session: AgentSession, services: AgentSessionServices) {
|
|
42
|
-
this.session = session;
|
|
43
|
-
this.services = services;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
waitForSettlement(): Promise<void> {
|
|
47
|
-
return this.session.waitForSettlement();
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
async dispose(): Promise<void> {
|
|
51
|
-
this.session.dispose();
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
/** Create the runtime from a runtime factory; an abort during creation disposes the late session. */
|
|
56
|
-
export async function createAgentSessionRuntime(
|
|
57
|
-
createRuntime: CreateAgentSessionRuntimeFactory,
|
|
58
|
-
options: {
|
|
59
|
-
cwd: string;
|
|
60
|
-
sessionManager: SessionManager;
|
|
61
|
-
signal?: AbortSignal;
|
|
62
|
-
onExtensionFactorySettlement?: ExtensionFactorySettlementObserver;
|
|
63
|
-
},
|
|
64
|
-
): Promise<AgentSessionRuntime> {
|
|
65
|
-
const signal = options.signal ?? new AbortController().signal;
|
|
66
|
-
signal.throwIfAborted();
|
|
67
|
-
const creation = Promise.resolve().then(() => createRuntime({
|
|
68
|
-
cwd: options.cwd,
|
|
69
|
-
sessionManager: options.sessionManager,
|
|
70
|
-
signal,
|
|
71
|
-
...(options.onExtensionFactorySettlement
|
|
72
|
-
? { onExtensionFactorySettlement: options.onExtensionFactorySettlement }
|
|
73
|
-
: {}),
|
|
74
|
-
}));
|
|
75
|
-
let result: CreateAgentSessionRuntimeResult;
|
|
76
|
-
|
|
77
|
-
try {
|
|
78
|
-
result = await awaitWithSignal(creation, signal);
|
|
79
|
-
} catch (error) {
|
|
80
|
-
if (signal.aborted) {
|
|
81
|
-
void creation.then((lateResult) => lateResult.session.dispose(), () => undefined);
|
|
82
|
-
}
|
|
83
|
-
throw error;
|
|
84
|
-
}
|
|
85
|
-
return new AgentSessionRuntime(result.session, result.services);
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
export {
|
|
89
|
-
type AgentSessionServices,
|
|
90
|
-
type CreateAgentSessionFromServicesOptions,
|
|
91
|
-
type CreateAgentSessionServicesOptions,
|
|
92
|
-
createAgentSessionFromServices,
|
|
93
|
-
createAgentSessionServices,
|
|
94
|
-
} from "./agent-session-services.ts";
|