background-agents 0.1.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.
- package/README.md +402 -0
- package/dist/debug.d.ts +7 -0
- package/dist/debug.d.ts.map +1 -0
- package/dist/debug.js +19 -0
- package/dist/debug.js.map +1 -0
- package/dist/factory.d.ts +31 -0
- package/dist/factory.d.ts.map +1 -0
- package/dist/factory.js +47 -0
- package/dist/factory.js.map +1 -0
- package/dist/index.d.ts +30 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +35 -0
- package/dist/index.js.map +1 -0
- package/dist/providers/base.d.ts +160 -0
- package/dist/providers/base.d.ts.map +1 -0
- package/dist/providers/base.js +656 -0
- package/dist/providers/base.js.map +1 -0
- package/dist/providers/claude.d.ts +14 -0
- package/dist/providers/claude.d.ts.map +1 -0
- package/dist/providers/claude.js +122 -0
- package/dist/providers/claude.js.map +1 -0
- package/dist/providers/codex.d.ts +14 -0
- package/dist/providers/codex.d.ts.map +1 -0
- package/dist/providers/codex.js +160 -0
- package/dist/providers/codex.js.map +1 -0
- package/dist/providers/gemini.d.ts +16 -0
- package/dist/providers/gemini.d.ts.map +1 -0
- package/dist/providers/gemini.js +91 -0
- package/dist/providers/gemini.js.map +1 -0
- package/dist/providers/index.d.ts +6 -0
- package/dist/providers/index.d.ts.map +1 -0
- package/dist/providers/index.js +6 -0
- package/dist/providers/index.js.map +1 -0
- package/dist/providers/opencode.d.ts +14 -0
- package/dist/providers/opencode.d.ts.map +1 -0
- package/dist/providers/opencode.js +100 -0
- package/dist/providers/opencode.js.map +1 -0
- package/dist/sandbox/daytona-ssh.d.ts +9 -0
- package/dist/sandbox/daytona-ssh.d.ts.map +1 -0
- package/dist/sandbox/daytona-ssh.js +113 -0
- package/dist/sandbox/daytona-ssh.js.map +1 -0
- package/dist/sandbox/daytona.d.ts +4 -0
- package/dist/sandbox/daytona.d.ts.map +1 -0
- package/dist/sandbox/daytona.js +238 -0
- package/dist/sandbox/daytona.js.map +1 -0
- package/dist/sandbox/index.d.ts +14 -0
- package/dist/sandbox/index.d.ts.map +1 -0
- package/dist/sandbox/index.js +15 -0
- package/dist/sandbox/index.js.map +1 -0
- package/dist/session.d.ts +64 -0
- package/dist/session.d.ts.map +1 -0
- package/dist/session.js +113 -0
- package/dist/session.js.map +1 -0
- package/dist/types/events.d.ts +114 -0
- package/dist/types/events.d.ts.map +1 -0
- package/dist/types/events.js +50 -0
- package/dist/types/events.js.map +1 -0
- package/dist/types/index.d.ts +3 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +3 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/provider.d.ts +124 -0
- package/dist/types/provider.d.ts.map +1 -0
- package/dist/types/provider.js +2 -0
- package/dist/types/provider.js.map +1 -0
- package/dist/utils/index.d.ts +4 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +4 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/install.d.ts +27 -0
- package/dist/utils/install.d.ts.map +1 -0
- package/dist/utils/install.js +86 -0
- package/dist/utils/install.js.map +1 -0
- package/dist/utils/json.d.ts +8 -0
- package/dist/utils/json.d.ts.map +1 -0
- package/dist/utils/json.js +15 -0
- package/dist/utils/json.js.map +1 -0
- package/dist/utils/session.d.ts +17 -0
- package/dist/utils/session.d.ts.map +1 -0
- package/dist/utils/session.js +59 -0
- package/dist/utils/session.js.map +1 -0
- package/next.config.codeagentsdk.cjs +22 -0
- package/package.json +57 -0
package/dist/session.js
ADDED
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import { randomUUID } from "node:crypto";
|
|
2
|
+
import { debugLog } from "./debug.js";
|
|
3
|
+
import { createProvider } from "./factory.js";
|
|
4
|
+
import { adaptSandbox } from "./sandbox/index.js";
|
|
5
|
+
const CODEAGENT_SESSION_DIR_PREFIX = "/tmp/codeagent-";
|
|
6
|
+
/** Cache reattached background sessions by id so status/getEvents polls don't recreate the provider every time. */
|
|
7
|
+
const backgroundSessionCache = new Map();
|
|
8
|
+
async function readProviderFromMeta(sandbox, sessionDir) {
|
|
9
|
+
const adapted = adaptSandbox(sandbox);
|
|
10
|
+
if (!adapted.executeCommand)
|
|
11
|
+
return null;
|
|
12
|
+
const result = await adapted.executeCommand(`cat "${sessionDir}/meta.json" 2>/dev/null || true`, 10);
|
|
13
|
+
const raw = (result.output ?? "").trim();
|
|
14
|
+
if (!raw)
|
|
15
|
+
return null;
|
|
16
|
+
try {
|
|
17
|
+
const o = JSON.parse(raw);
|
|
18
|
+
return {
|
|
19
|
+
provider: o.provider ?? null,
|
|
20
|
+
sessionId: o.sessionId ?? null,
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
catch {
|
|
24
|
+
return { provider: null, sessionId: null };
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Create a session: a provider with run defaults (model, timeout, env) set at creation.
|
|
29
|
+
* Returns the provider; call session.run(prompt) with just the prompt string.
|
|
30
|
+
*/
|
|
31
|
+
export async function createSession(name, options) {
|
|
32
|
+
debugLog("createSession", options.sessionId, name);
|
|
33
|
+
const { model, sessionId, timeout, systemPrompt, skipInstall, env, ...providerOptions } = options;
|
|
34
|
+
const runDefaults = { model, sessionId, timeout, systemPrompt, skipInstall, env };
|
|
35
|
+
const provider = createProvider(name, { ...providerOptions, skipInstall, env, runDefaults });
|
|
36
|
+
await provider.ready;
|
|
37
|
+
debugLog("createSession ready", options.sessionId, name);
|
|
38
|
+
return provider;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Create a background session: a provider configured for sandboxed background
|
|
42
|
+
* execution with one log file per turn and meta/cursor in the sandbox.
|
|
43
|
+
* Use start() to begin a turn and getEvents() to consume events (no cursor argument).
|
|
44
|
+
*/
|
|
45
|
+
export async function createBackgroundSession(name, options) {
|
|
46
|
+
const { backgroundSessionId, ...sessionOptions } = options;
|
|
47
|
+
const id = backgroundSessionId ?? randomUUID();
|
|
48
|
+
debugLog("createBackgroundSession", options.sessionId, name, "id=" + id);
|
|
49
|
+
return createBackgroundSessionWithId(name, { ...sessionOptions, backgroundSessionId: id }, id);
|
|
50
|
+
}
|
|
51
|
+
/** Reattach to an existing background session by id (e.g. after restart). Provider is read from sandbox meta (written at session creation). Cached per id so repeated polls don't recreate the provider. */
|
|
52
|
+
export async function getBackgroundSession(options) {
|
|
53
|
+
const { backgroundSessionId, sandbox } = options;
|
|
54
|
+
const cached = backgroundSessionCache.get(backgroundSessionId);
|
|
55
|
+
if (cached) {
|
|
56
|
+
debugLog("getBackgroundSession", cached.provider.sessionId, "id=" + backgroundSessionId, "cached");
|
|
57
|
+
return cached;
|
|
58
|
+
}
|
|
59
|
+
const sessionDir = `${CODEAGENT_SESSION_DIR_PREFIX}${backgroundSessionId}`;
|
|
60
|
+
debugLog("getBackgroundSession", undefined, "id=" + backgroundSessionId, "sessionDir=" + sessionDir);
|
|
61
|
+
const meta = await readProviderFromMeta(sandbox, sessionDir);
|
|
62
|
+
if (!meta?.provider) {
|
|
63
|
+
debugLog("getBackgroundSession meta missing or no provider", meta?.sessionId ?? undefined, backgroundSessionId);
|
|
64
|
+
throw new Error("Cannot get background session: meta not found (start a turn first) or meta has no provider");
|
|
65
|
+
}
|
|
66
|
+
debugLog("getBackgroundSession reattach provider=" + meta.provider, meta.sessionId);
|
|
67
|
+
return createBackgroundSessionWithId(meta.provider, {
|
|
68
|
+
...options,
|
|
69
|
+
// Seed sessionId so providers that support resume (e.g. Claude) can continue the same session.
|
|
70
|
+
sessionId: meta.sessionId ?? options.sessionId,
|
|
71
|
+
}, backgroundSessionId, { skipWriteInitialMeta: true });
|
|
72
|
+
}
|
|
73
|
+
async function createBackgroundSessionWithId(name, options, id, opts) {
|
|
74
|
+
const provider = await createSession(name, options);
|
|
75
|
+
const sessionDir = `${CODEAGENT_SESSION_DIR_PREFIX}${id}`;
|
|
76
|
+
if (!opts?.skipWriteInitialMeta) {
|
|
77
|
+
await provider.writeInitialSessionMeta(sessionDir);
|
|
78
|
+
}
|
|
79
|
+
const session = {
|
|
80
|
+
id,
|
|
81
|
+
provider,
|
|
82
|
+
async start(prompt, extraOptions) {
|
|
83
|
+
debugLog("BackgroundSession.start", provider.sessionId, "id=" + id, "sessionDir=" + sessionDir, "promptLength=" + prompt.length);
|
|
84
|
+
const result = await provider.startSandboxBackgroundTurn(sessionDir, {
|
|
85
|
+
// Re-apply core run defaults (model, timeout, env, systemPrompt) for each turn.
|
|
86
|
+
model: options.model,
|
|
87
|
+
timeout: options.timeout,
|
|
88
|
+
env: options.env,
|
|
89
|
+
systemPrompt: options.systemPrompt,
|
|
90
|
+
sessionId: options.sessionId,
|
|
91
|
+
...(extraOptions ?? {}),
|
|
92
|
+
prompt,
|
|
93
|
+
});
|
|
94
|
+
debugLog("BackgroundSession.start returned", provider.sessionId, "id=" + id, "pid=" + result.pid, "outputFile=" + result.outputFile);
|
|
95
|
+
return result;
|
|
96
|
+
},
|
|
97
|
+
async getEvents() {
|
|
98
|
+
return provider.getEventsSandboxBackgroundFromMeta(sessionDir);
|
|
99
|
+
},
|
|
100
|
+
async isRunning() {
|
|
101
|
+
return provider.isSandboxBackgroundProcessRunning(sessionDir);
|
|
102
|
+
},
|
|
103
|
+
async getPid() {
|
|
104
|
+
return provider.getSandboxBackgroundPid(sessionDir);
|
|
105
|
+
},
|
|
106
|
+
async cancel() {
|
|
107
|
+
return provider.cancelSandboxBackground(sessionDir);
|
|
108
|
+
},
|
|
109
|
+
};
|
|
110
|
+
backgroundSessionCache.set(id, session);
|
|
111
|
+
return session;
|
|
112
|
+
}
|
|
113
|
+
//# sourceMappingURL=session.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"session.js","sourceRoot":"","sources":["../src/session.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AAExC,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAA;AACrC,OAAO,EAAE,cAAc,EAA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GAAG,MAAM,CAAC,MAAM,CAAC,CAAA;YAChI,MAAM,MAAM,GAAG,MAAM,QAAQ,CAAC,0BAA0B,CAAC,UAAU,EAAE;gBACnE,gFAAgF;gBAChF,KAAK,EAAE,OAAO,CAAC,KAAK;gBACpB,OAAO,EAAE,OAAO,CAAC,OAAO;gBACxB,GAAG,EAAE,OAAO,CAAC,GAAG;gBAChB,YAAY,EAAE,OAAO,CAAC,YAAY;gBAClC,SAAS,EAAE,OAAO,CAAC,SAAS;gBAC5B,GAAG,CAAC,YAAY,IAAI,EAAE,CAAC;gBACvB,MAAM;aACP,CAAC,CAAA;YACF,QAAQ,CAAC,kCAAkC,EAAE,QAAQ,CAAC,SAAS,EAAE,KAAK,GAAG,EAAE,EAAE,MAAM,GAAG,MAAM,CAAC,GAAG,EAAE,aAAa,GAAG,MAAM,CAAC,UAAU,CAAC,CAAA;YACpI,OAAO,MAAM,CAAA;QACf,CAAC;QACD,KAAK,CAAC,SAAS;YACb,OAAO,QAAQ,CAAC,kCAAkC,CAAC,UAAU,CAAC,CAAA;QAChE,CAAC;QACD,KAAK,CAAC,SAAS;YACb,OAAO,QAAQ,CAAC,iCAAiC,CAAC,UAAU,CAAC,CAAA;QAC/D,CAAC;QACD,KAAK,CAAC,MAAM;YACV,OAAO,QAAQ,CAAC,uBAAuB,CAAC,UAAU,CAAC,CAAA;QACrD,CAAC;QACD,KAAK,CAAC,MAAM;YACV,OAAO,QAAQ,CAAC,uBAAuB,CAAC,UAAU,CAAC,CAAA;QACrD,CAAC;KACF,CAAA;IACD,sBAAsB,CAAC,GAAG,CAAC,EAAE,EAAE,OAAO,CAAC,CAAA;IACvC,OAAO,OAAO,CAAA;AAChB,CAAC"}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Event types emitted by AI coding agents
|
|
3
|
+
*/
|
|
4
|
+
/** Session started event - contains the session ID for resumption */
|
|
5
|
+
export interface SessionEvent {
|
|
6
|
+
type: "session";
|
|
7
|
+
id: string;
|
|
8
|
+
}
|
|
9
|
+
/** Token event - a text token from the assistant's response */
|
|
10
|
+
export interface TokenEvent {
|
|
11
|
+
type: "token";
|
|
12
|
+
text: string;
|
|
13
|
+
}
|
|
14
|
+
/** Normalized tool names (same across Claude, Codex, etc.) */
|
|
15
|
+
export type ToolName = "write" | "read" | "edit" | "glob" | "grep" | "shell";
|
|
16
|
+
/** Input for the write tool (create/overwrite file). Canonical: always include kind + content (nullable). */
|
|
17
|
+
export interface WriteToolInput {
|
|
18
|
+
file_path: string;
|
|
19
|
+
content: string | null;
|
|
20
|
+
kind: "add" | "update";
|
|
21
|
+
}
|
|
22
|
+
/** Input for the read tool (path to file). Canonical: always file_path. */
|
|
23
|
+
export interface ReadToolInput {
|
|
24
|
+
file_path: string;
|
|
25
|
+
}
|
|
26
|
+
/** Input for the edit tool (patch/edit file). Canonical: file_path + optional rest. */
|
|
27
|
+
export interface EditToolInput {
|
|
28
|
+
file_path: string;
|
|
29
|
+
[key: string]: unknown;
|
|
30
|
+
}
|
|
31
|
+
/** Input for the glob tool (file search by pattern). */
|
|
32
|
+
export interface GlobToolInput {
|
|
33
|
+
pattern: string;
|
|
34
|
+
}
|
|
35
|
+
/** Input for the grep tool (content search). */
|
|
36
|
+
export interface GrepToolInput {
|
|
37
|
+
pattern: string;
|
|
38
|
+
path?: string;
|
|
39
|
+
}
|
|
40
|
+
/** Input for the shell tool (run a command). */
|
|
41
|
+
export interface ShellToolInput {
|
|
42
|
+
command: string;
|
|
43
|
+
description?: string;
|
|
44
|
+
}
|
|
45
|
+
/** Tool input map for narrowing by tool name */
|
|
46
|
+
export interface ToolInputMap {
|
|
47
|
+
write: WriteToolInput;
|
|
48
|
+
read: ReadToolInput;
|
|
49
|
+
edit: EditToolInput;
|
|
50
|
+
glob: GlobToolInput;
|
|
51
|
+
grep: GrepToolInput;
|
|
52
|
+
shell: ShellToolInput;
|
|
53
|
+
}
|
|
54
|
+
/** Tool start event – discriminated by name for typed input */
|
|
55
|
+
export type ToolStartEvent = {
|
|
56
|
+
type: "tool_start";
|
|
57
|
+
name: "write";
|
|
58
|
+
input?: WriteToolInput;
|
|
59
|
+
} | {
|
|
60
|
+
type: "tool_start";
|
|
61
|
+
name: "read";
|
|
62
|
+
input?: ReadToolInput;
|
|
63
|
+
} | {
|
|
64
|
+
type: "tool_start";
|
|
65
|
+
name: "edit";
|
|
66
|
+
input?: EditToolInput;
|
|
67
|
+
} | {
|
|
68
|
+
type: "tool_start";
|
|
69
|
+
name: "glob";
|
|
70
|
+
input?: GlobToolInput;
|
|
71
|
+
} | {
|
|
72
|
+
type: "tool_start";
|
|
73
|
+
name: "grep";
|
|
74
|
+
input?: GrepToolInput;
|
|
75
|
+
} | {
|
|
76
|
+
type: "tool_start";
|
|
77
|
+
name: "shell";
|
|
78
|
+
input?: ShellToolInput;
|
|
79
|
+
} | {
|
|
80
|
+
type: "tool_start";
|
|
81
|
+
name: string;
|
|
82
|
+
input?: unknown;
|
|
83
|
+
};
|
|
84
|
+
/** Normalize raw provider payload into typed tool input and return a typed ToolStartEvent */
|
|
85
|
+
export declare function createToolStartEvent(name: ToolName | string, rawInput?: unknown): ToolStartEvent;
|
|
86
|
+
/** Tool delta event - partial input being streamed to a tool */
|
|
87
|
+
export interface ToolDeltaEvent {
|
|
88
|
+
type: "tool_delta";
|
|
89
|
+
text: string;
|
|
90
|
+
}
|
|
91
|
+
/** Tool end event - indicates tool invocation is complete */
|
|
92
|
+
export interface ToolEndEvent {
|
|
93
|
+
type: "tool_end";
|
|
94
|
+
/** Tool result/output when provided by the CLI */
|
|
95
|
+
output?: string;
|
|
96
|
+
}
|
|
97
|
+
/** End event - indicates the message/turn is complete */
|
|
98
|
+
export interface EndEvent {
|
|
99
|
+
type: "end";
|
|
100
|
+
/** When the CLI failed (e.g. error_during_execution), the error message if available */
|
|
101
|
+
error?: string;
|
|
102
|
+
}
|
|
103
|
+
/** Agent crashed event - process exited without emitting end (e.g. crash or kill) */
|
|
104
|
+
export interface AgentCrashedEvent {
|
|
105
|
+
type: "agent_crashed";
|
|
106
|
+
message?: string;
|
|
107
|
+
/** Raw tail of stdout/stderr before exit (often not valid JSONL; use for debugging only) */
|
|
108
|
+
output?: string;
|
|
109
|
+
}
|
|
110
|
+
/** Union type of all possible events */
|
|
111
|
+
export type Event = SessionEvent | TokenEvent | ToolStartEvent | ToolDeltaEvent | ToolEndEvent | EndEvent | AgentCrashedEvent;
|
|
112
|
+
/** Event type discriminator */
|
|
113
|
+
export type EventType = Event["type"];
|
|
114
|
+
//# sourceMappingURL=events.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"events.d.ts","sourceRoot":"","sources":["../../src/types/events.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,qEAAqE;AACrE,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,SAAS,CAAA;IACf,EAAE,EAAE,MAAM,CAAA;CACX;AAED,+DAA+D;AAC/D,MAAM,WAAW,UAAU;IACzB,IAAI,EAAE,OAAO,CAAA;IACb,IAAI,EAAE,MAAM,CAAA;CACb;AAED,8DAA8D;AAC9D,MAAM,MAAM,QAAQ,GAAG,OAAO,GAAG,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,CAAA;AAE5E,6GAA6G;AAC7G,MAAM,WAAW,cAAc;IAC7B,SAAS,EAAE,MAAM,CAAA;IACjB,OAAO,EAAE,MAAM,GAAG,IAAI,CAAA;IACtB,IAAI,EAAE,KAAK,GAAG,QAAQ,CAAA;CACvB;AAED,2EAA2E;AAC3E,MAAM,WAAW,aAAa;IAC5B,SAAS,EAAE,MAAM,CAAA;CAClB;AAED,uFAAuF;AACvF,MAAM,WAAW,aAAa;IAC5B,SAAS,EAAE,MAAM,CAAA;IACjB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;CACvB;AAED,wDAAwD;AACxD,MAAM,WAAW,aAAa;IAC5B,OAAO,EAAE,MAAM,CAAA;CAChB;AAED,gD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;CAAE,CAAA;AAMzD,6FAA6F;AAC7F,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,QAAQ,GAAG,MAAM,EAAE,QAAQ,CAAC,EAAE,OAAO,GAAG,cAAc,CAoChG;AAED,gEAAgE;AAChE,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,YAAY,CAAA;IAClB,IAAI,EAAE,MAAM,CAAA;CACb;AAED,6DAA6D;AAC7D,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,UAAU,CAAA;IAChB,kDAAkD;IAClD,MAAM,CAAC,EAAE,MAAM,CAAA;CAChB;AAED,yDAAyD;AACzD,MAAM,WAAW,QAAQ;IACvB,IAAI,EAAE,KAAK,CAAA;IACX,wFAAwF;IACxF,KAAK,CAAC,EAAE,MAAM,CAAA;CACf;AAED,qFAAqF;AACrF,MAAM,WAAW,iBAAiB;IAChC,IAAI,EAAE,eAAe,CAAA;IACrB,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,4FAA4F;IAC5F,MAAM,CAAC,EAAE,MAAM,CAAA;CAChB;AAED,wCAAwC;AACxC,MAAM,MAAM,KAAK,GACb,YAAY,GACZ,UAAU,GACV,cAAc,GACd,cAAc,GACd,YAAY,GACZ,QAAQ,GACR,iBAAiB,CAAA;AAErB,+BAA+B;AAC/B,MAAM,MAAM,SAAS,GAAG,KAAK,CAAC,MAAM,CAAC,CAAA"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Event types emitted by AI coding agents
|
|
3
|
+
*/
|
|
4
|
+
function isObject(v) {
|
|
5
|
+
return typeof v === "object" && v !== null && !Array.isArray(v);
|
|
6
|
+
}
|
|
7
|
+
/** Normalize raw provider payload into typed tool input and return a typed ToolStartEvent */
|
|
8
|
+
export function createToolStartEvent(name, rawInput) {
|
|
9
|
+
let input = rawInput;
|
|
10
|
+
if (name === "write" && isObject(rawInput)) {
|
|
11
|
+
const path = rawInput.file_path ?? rawInput.filePath ?? rawInput.path;
|
|
12
|
+
if (typeof path === "string") {
|
|
13
|
+
const kind = rawInput.kind === "add" || rawInput.kind === "update" ? rawInput.kind : "update";
|
|
14
|
+
input = {
|
|
15
|
+
file_path: path,
|
|
16
|
+
content: typeof rawInput.content === "string" ? rawInput.content : null,
|
|
17
|
+
kind,
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
else if (name === "read" && isObject(rawInput)) {
|
|
22
|
+
const path = rawInput.file_path ?? rawInput.filePath ?? rawInput.path;
|
|
23
|
+
if (typeof path === "string") {
|
|
24
|
+
input = { file_path: path };
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
else if (name === "edit" && isObject(rawInput)) {
|
|
28
|
+
const path = rawInput.file_path ?? rawInput.filePath ?? rawInput.path;
|
|
29
|
+
if (typeof path === "string") {
|
|
30
|
+
input = { file_path: path, ...rawInput };
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
else if (name === "shell" && isObject(rawInput) && typeof rawInput.command === "string") {
|
|
34
|
+
input = {
|
|
35
|
+
command: rawInput.command,
|
|
36
|
+
description: typeof rawInput.description === "string" ? rawInput.description : undefined,
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
else if (name === "glob" && isObject(rawInput) && typeof rawInput.pattern === "string") {
|
|
40
|
+
input = { pattern: rawInput.pattern };
|
|
41
|
+
}
|
|
42
|
+
else if (name === "grep" && isObject(rawInput) && typeof rawInput.pattern === "string") {
|
|
43
|
+
input = {
|
|
44
|
+
pattern: rawInput.pattern,
|
|
45
|
+
path: typeof rawInput.path === "string" ? rawInput.path : undefined,
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
return { type: "tool_start", name, input };
|
|
49
|
+
}
|
|
50
|
+
//# sourceMappingURL=events.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"events.js","sourceRoot":"","sources":["../../src/types/events.ts"],"names":[],"mappings":"AAAA;;GAEG;AAwEH,SAAS,QAAQ,C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":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAA;AAC3B,cAAc,eAAe,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAA;AAC3B,cAAc,eAAe,CAAA"}
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import type { Event } from "./events.js";
|
|
2
|
+
/**
|
|
3
|
+
* Provider-related types and interfaces
|
|
4
|
+
*/
|
|
5
|
+
/** Supported provider names */
|
|
6
|
+
export type ProviderName = "claude" | "codex" | "opencode" | "gemini";
|
|
7
|
+
/** Options for starting a background command that writes to a log file and signals when done. */
|
|
8
|
+
export interface ExecuteBackgroundOptions {
|
|
9
|
+
/** Full command line to run (stdout/stderr should be appended to outputFile). */
|
|
10
|
+
command: string;
|
|
11
|
+
/** Path in sandbox to append output to (e.g. /tmp/codeagent-<id>/0.jsonl). */
|
|
12
|
+
outputFile: string;
|
|
13
|
+
/** Unique run id (used for logging; PID is returned from executeBackground). */
|
|
14
|
+
runId: string;
|
|
15
|
+
timeout?: number;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Sandbox interface required by the SDK. Implement this yourself or use
|
|
19
|
+
* adaptDaytonaSandbox() to wrap a Daytona Sandbox from @daytonaio/sdk.
|
|
20
|
+
*/
|
|
21
|
+
export interface CodeAgentSandbox {
|
|
22
|
+
ensureProvider(name: ProviderName): Promise<void>;
|
|
23
|
+
setEnvVars(vars: Record<string, string>): void;
|
|
24
|
+
executeCommandStream(command: string, timeout?: number): AsyncGenerator<string, void, unknown>;
|
|
25
|
+
/** Optional: run a one-off command (used e.g. for Codex login). */
|
|
26
|
+
executeCommand?(command: string, timeout?: number): Promise<{
|
|
27
|
+
exitCode: number;
|
|
28
|
+
output: string;
|
|
29
|
+
}>;
|
|
30
|
+
/**
|
|
31
|
+
* Optional: start a command in the background and return its pid immediately.
|
|
32
|
+
* The sandbox must run the command with stdout/stderr >> outputFile and return
|
|
33
|
+
* the pid (e.g. via nohup + SSH so the channel closes right away). Implement
|
|
34
|
+
* this to avoid blocking on the command when using executeCommand.
|
|
35
|
+
*/
|
|
36
|
+
executeBackground?(options: ExecuteBackgroundOptions): Promise<{
|
|
37
|
+
pid: number;
|
|
38
|
+
}>;
|
|
39
|
+
/**
|
|
40
|
+
* Optional: kill a process by pid. Must use the same execution context that
|
|
41
|
+
* started it (e.g. SSH); process API kill won't see pids started over SSH.
|
|
42
|
+
*/
|
|
43
|
+
killBackgroundProcess?(pid: number): Promise<void>;
|
|
44
|
+
}
|
|
45
|
+
/** Command configuration for spawning a provider process */
|
|
46
|
+
export interface ProviderCommand {
|
|
47
|
+
cmd: string;
|
|
48
|
+
args: string[];
|
|
49
|
+
env?: Record<string, string>;
|
|
50
|
+
}
|
|
51
|
+
/** Options when adapting a Daytona sandbox for use with the SDK */
|
|
52
|
+
export interface AdaptSandboxOptions {
|
|
53
|
+
/** Environment variables for CLI execution (e.g. ANTHROPIC_API_KEY) */
|
|
54
|
+
env?: Record<string, string>;
|
|
55
|
+
}
|
|
56
|
+
/** Options for running a provider */
|
|
57
|
+
export interface RunOptions {
|
|
58
|
+
/** The prompt to send to the provider */
|
|
59
|
+
prompt?: string;
|
|
60
|
+
/**
|
|
61
|
+
* Optional system prompt / high-level instructions.
|
|
62
|
+
* When set via createSession, providers that support system prompts will use
|
|
63
|
+
* their native mechanism; others will have this string prepended to the first
|
|
64
|
+
* user prompt in the session.
|
|
65
|
+
*/
|
|
66
|
+
systemPrompt?: string;
|
|
67
|
+
/** Optional session ID to resume */
|
|
68
|
+
sessionId?: string;
|
|
69
|
+
/** Whether to persist session ID to file (only for local mode) */
|
|
70
|
+
persistSession?: boolean;
|
|
71
|
+
/** Custom session file path (only for local mode) */
|
|
72
|
+
sessionFile?: string;
|
|
73
|
+
/** Working directory for the provider process */
|
|
74
|
+
cwd?: string;
|
|
75
|
+
/** Environment variables to pass to the provider */
|
|
76
|
+
env?: Record<string, string>;
|
|
77
|
+
/** Skip installing the CLI in the sandbox (default: false) */
|
|
78
|
+
skipInstall?: boolean;
|
|
79
|
+
/** Timeout in seconds for sandbox execution (default: 120) */
|
|
80
|
+
timeout?: number;
|
|
81
|
+
/** Model to use (provider-specific, e.g., "openai/gpt-4o") */
|
|
82
|
+
model?: string;
|
|
83
|
+
}
|
|
84
|
+
/** Default run options merged into every run (used by createSession) */
|
|
85
|
+
export type RunDefaults = Partial<Omit<RunOptions, "prompt">>;
|
|
86
|
+
/** Options for creating a provider */
|
|
87
|
+
export interface ProviderOptions {
|
|
88
|
+
/**
|
|
89
|
+
* Sandbox for secure execution. Pass a Sandbox from @daytonaio/sdk directly
|
|
90
|
+
* (the SDK adapts it internally). Optional env here is used for CLI execution.
|
|
91
|
+
*/
|
|
92
|
+
sandbox?: CodeAgentSandbox | import("@daytonaio/sdk").Sandbox;
|
|
93
|
+
/** Environment variables for CLI execution (e.g. when sandbox is a Daytona Sandbox) */
|
|
94
|
+
env?: Record<string, string>;
|
|
95
|
+
/** Skip installing the provider CLI when the provider is created (default: false) */
|
|
96
|
+
skipInstall?: boolean;
|
|
97
|
+
/**
|
|
98
|
+
* Allow running commands directly on local machine without sandbox.
|
|
99
|
+
* ⚠️ DANGEROUS: Only use this if you trust the code being executed.
|
|
100
|
+
*/
|
|
101
|
+
dangerouslyAllowLocalExecution?: boolean;
|
|
102
|
+
/** Defaults merged into every run() call (model, timeout, sessionId, env). Set by createSession. */
|
|
103
|
+
runDefaults?: RunDefaults;
|
|
104
|
+
}
|
|
105
|
+
/** Event handler callback */
|
|
106
|
+
export type EventHandler = (event: Event) => void | Promise<void>;
|
|
107
|
+
/** Provider interface that all providers must implement */
|
|
108
|
+
export interface IProvider {
|
|
109
|
+
/** Provider name */
|
|
110
|
+
readonly name: ProviderName;
|
|
111
|
+
/** Current session ID */
|
|
112
|
+
sessionId: string | null;
|
|
113
|
+
/** Convenience accessor for current session id */
|
|
114
|
+
getSessionId(): string | null;
|
|
115
|
+
/** Get the command to spawn the provider */
|
|
116
|
+
getCommand(options?: RunOptions): ProviderCommand;
|
|
117
|
+
/** Parse a line of output into one or more events */
|
|
118
|
+
parse(line: string): Event | Event[] | null;
|
|
119
|
+
/** Resolves when CLI install and setup (env, Codex login) have completed. Await before first run if you want "ready" UX. */
|
|
120
|
+
readonly ready: Promise<void>;
|
|
121
|
+
/** Run the provider and emit events. Pass a prompt string or full RunOptions. */
|
|
122
|
+
run(promptOrOptions?: string | RunOptions): AsyncGenerator<Event, void, unknown>;
|
|
123
|
+
}
|
|
124
|
+
//# sourceMappingURL=provider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../../src/types/provider.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,aAAa,CAAA;AAExC;;GAEG;AAEH,+BAA+B;AAC/B,MAAM,MAAM,YAAY,GAAG,QAAQ,GAAG,OAAO,GAAG,UAAU,GAAG,QAAQ,CAAA;AAErE,iGAAiG;AACjG,MAAM,WAAW,wBAAwB;IACvC,iFAAiF;IACjF,OAAO,EAAE,MAAM,CAAA;IACf,8EAA8E;IAC9E,UAAU,EAAE,MAAM,CAAA;IAClB,gFAAgF;IAChF,KAAK,EAAE,MAAM,CAAA;IACb,OAAO,CAAC,EAAE,MAAM,CAAA;CACjB;AAED;;;GAGG;AACH,MAAM,WAAW,gBAAgB;IAC/B,cAAc,CAAC,IAAI,EAAE,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;IACjD,UAAU,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,IAAI,CAAA;IAC9C,oBAAoB,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,cAAc,CAAC,MAAM,EAAE,IAAI,EAAE,OAAO,CAAC,CAAA;IAC9F,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OAAO,CAAC,CAAA;CACjF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"provider.js","sourceRoot":"","sources":["../../src/types/provider.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAA;AACzB,cAAc,cAAc,CAAA;AAC5B,cAAc,cAAc,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAA;AACzB,cAAc,cAAc,CAAA;AAC5B,cAAc,cAAc,CAAA"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { ProviderName } from "../types/index.js";
|
|
2
|
+
/**
|
|
3
|
+
* Check if a CLI command is available in PATH
|
|
4
|
+
*/
|
|
5
|
+
export declare function isCliInstalled(name: ProviderName): boolean;
|
|
6
|
+
/**
|
|
7
|
+
* Get the npm package name for a provider
|
|
8
|
+
*/
|
|
9
|
+
export declare function getPackageName(name: ProviderName): string;
|
|
10
|
+
/**
|
|
11
|
+
* Install a provider CLI globally via npm
|
|
12
|
+
* @returns true if installation succeeded
|
|
13
|
+
*/
|
|
14
|
+
export declare function installProvider(name: ProviderName): boolean;
|
|
15
|
+
/**
|
|
16
|
+
* Ensure a provider CLI is installed, installing it if necessary
|
|
17
|
+
* @param name - Provider name
|
|
18
|
+
* @param autoInstall - Whether to automatically install if missing (default: false)
|
|
19
|
+
* @returns true if CLI is available (either already installed or successfully installed)
|
|
20
|
+
* @throws Error if CLI is not installed and autoInstall is false
|
|
21
|
+
*/
|
|
22
|
+
export declare function ensureCliInstalled(name: ProviderName, autoInstall?: boolean): boolean;
|
|
23
|
+
/**
|
|
24
|
+
* Check installation status of all providers
|
|
25
|
+
*/
|
|
26
|
+
export declare function getInstallationStatus(): Record<ProviderName, boolean>;
|
|
27
|
+
//# sourceMappingURL=install.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"install.d.ts","sourceRoot":"","sources":["../../src/utils/install.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AAYrD;;GAEG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,YAAY,GAAG,OAAO,CAU1D;AAED;;GAEG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,YAAY,GAAG,MAAM,CAEzD;AAED;;;GAGG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,YAAY,GAAG,OAAO,CAY3D;AAED;;;;;;GAMG;AACH,wBAAgB,kBAAkB,CAChC,IAAI,EAAE,YAAY,EAClB,WAAW,GAAE,OAAe,GAC3B,OAAO,CA0BT;AAED;;GAEG;AACH,wBAAgB,qBAAqB,IAAI,MAAM,CAAC,YAAY,EAAE,OAAO,CAAC,CASrE"}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { execSync, spawnSync } from "node:child_process";
|
|
2
|
+
/**
|
|
3
|
+
* CLI package information for each provider
|
|
4
|
+
*/
|
|
5
|
+
const PROVIDER_PACKAGES = {
|
|
6
|
+
claude: "@anthropic-ai/claude-code",
|
|
7
|
+
codex: "@openai/codex",
|
|
8
|
+
opencode: "opencode",
|
|
9
|
+
gemini: "@google/gemini-cli",
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* Check if a CLI command is available in PATH
|
|
13
|
+
*/
|
|
14
|
+
export function isCliInstalled(name) {
|
|
15
|
+
try {
|
|
16
|
+
const result = spawnSync("which", [name], {
|
|
17
|
+
encoding: "utf8",
|
|
18
|
+
stdio: ["pipe", "pipe", "pipe"],
|
|
19
|
+
});
|
|
20
|
+
return result.status === 0;
|
|
21
|
+
}
|
|
22
|
+
catch {
|
|
23
|
+
return false;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Get the npm package name for a provider
|
|
28
|
+
*/
|
|
29
|
+
export function getPackageName(name) {
|
|
30
|
+
return PROVIDER_PACKAGES[name];
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Install a provider CLI globally via npm
|
|
34
|
+
* @returns true if installation succeeded
|
|
35
|
+
*/
|
|
36
|
+
export function installProvider(name) {
|
|
37
|
+
const packageName = PROVIDER_PACKAGES[name];
|
|
38
|
+
try {
|
|
39
|
+
execSync(`npm install -g ${packageName}`, {
|
|
40
|
+
stdio: "inherit",
|
|
41
|
+
encoding: "utf8",
|
|
42
|
+
});
|
|
43
|
+
return true;
|
|
44
|
+
}
|
|
45
|
+
catch {
|
|
46
|
+
return false;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Ensure a provider CLI is installed, installing it if necessary
|
|
51
|
+
* @param name - Provider name
|
|
52
|
+
* @param autoInstall - Whether to automatically install if missing (default: false)
|
|
53
|
+
* @returns true if CLI is available (either already installed or successfully installed)
|
|
54
|
+
* @throws Error if CLI is not installed and autoInstall is false
|
|
55
|
+
*/
|
|
56
|
+
export function ensureCliInstalled(name, autoInstall = false) {
|
|
57
|
+
if (isCliInstalled(name)) {
|
|
58
|
+
return true;
|
|
59
|
+
}
|
|
60
|
+
if (!autoInstall) {
|
|
61
|
+
const packageName = PROVIDER_PACKAGES[name];
|
|
62
|
+
throw new Error(`CLI '${name}' is not installed. ` +
|
|
63
|
+
`Install it with: npm install -g ${packageName}`);
|
|
64
|
+
}
|
|
65
|
+
console.log(`Installing ${name} CLI...`);
|
|
66
|
+
const success = installProvider(name);
|
|
67
|
+
if (!success) {
|
|
68
|
+
const packageName = PROVIDER_PACKAGES[name];
|
|
69
|
+
throw new Error(`Failed to install '${name}' CLI. ` +
|
|
70
|
+
`Try manually: npm install -g ${packageName}`);
|
|
71
|
+
}
|
|
72
|
+
console.log(`Successfully installed ${name} CLI`);
|
|
73
|
+
return true;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Check installation status of all providers
|
|
77
|
+
*/
|
|
78
|
+
export function getInstallationStatus() {
|
|
79
|
+
const providers = ["claude", "codex", "opencode", "gemini"];
|
|
80
|
+
const status = {};
|
|
81
|
+
for (const provider of providers) {
|
|
82
|
+
status[provider] = isCliInstalled(provider);
|
|
83
|
+
}
|
|
84
|
+
return status;
|
|
85
|
+
}
|
|
86
|
+
//# sourceMappingURL=install.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"install.js","sourceRoot":"","sources":["../../src/utils/install.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAA;AAGxD;;GAEG;AACH,MAAM,iBAAiB,GAAiC;IACtD,MAAM,EAAE,2BAA2B;IACnC,KAAK,EAAE,eAAe;IACtB,QAAQ,EAAE,UAAU;IACpB,MAAM,EAAE,oBAAoB;CAC7B,CAAA;AAED;;GAEG;AACH,MAAM,UAAU,cAAc,CAAC,IAAkB;IAC/C,IAAI,CAAC;QACH,MAAM,MAAM,GAAG,SAAS,CAAC,OAAO,EAAE,CAAC,IAAI,CAAC,EAAE;YACxC,QAAQ,EAAE,MAAM;YAChB,KAAK,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC;SAChC,CAAC,CAAA;QACF,OAAO,MAAM,CAAC,MAAM,KAAK,CAAC,CAAA;IAC5B,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,KAAK,CAAA;IACd,CAAC;AACH,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,cAAc,CAAC,IAAkB;IAC/C,OAAO,iBAAiB,CAAC,IAAI,CAAC,CAAA;AAChC,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,eAAe,CAAC,IAAkB;IAChD,MAAM,WAAW,GAAG,iBAAiB,CAAC,IAAI,CAAC,CAAA;IAE3C,IAAI,CAAC;QACH,QAAQ,CAAC,kBAA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;IAED,OAAO,MAAuC,CAAA;AAChD,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"json.d.ts","sourceRoot":"","sources":["../../src/utils/json.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;GAEG;AACH,wBAAgB,aAAa,CAAC,CAAC,GAAG,OAAO,EAAE,IAAI,EAAE,MAAM,GAAG,CAAC,GAAG,IAAI,CAMjE"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"json.js","sourceRoot":"","sources":["../../src/utils/json.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;GAEG;AACH,MAAM,UAAU,aAAa,CAAc,IAAY;IACrD,IAAI,CAAC;QACH,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAM,CAAA;IAC9B,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,IAAI,CAAA;IACb,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Get the default session file path
|
|
3
|
+
*/
|
|
4
|
+
export declare function getDefaultSessionPath(providerName: string): string;
|
|
5
|
+
/**
|
|
6
|
+
* Load a session ID from file
|
|
7
|
+
*/
|
|
8
|
+
export declare function loadSession(filePath: string): string | null;
|
|
9
|
+
/**
|
|
10
|
+
* Store a session ID to file
|
|
11
|
+
*/
|
|
12
|
+
export declare function storeSession(filePath: string, sessionId: string): boolean;
|
|
13
|
+
/**
|
|
14
|
+
* Clear a session file
|
|
15
|
+
*/
|
|
16
|
+
export declare function clearSession(filePath: string): boolean;
|
|
17
|
+
//# sourceMappingURL=session.d.ts.map
|