lark-to-codex 0.1.0

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.
@@ -0,0 +1,134 @@
1
+ type AgentEvent = {
2
+ type: 'system';
3
+ sessionId?: string;
4
+ cwd?: string;
5
+ model?: string;
6
+ } | {
7
+ type: 'text';
8
+ delta: string;
9
+ } | {
10
+ type: 'thinking';
11
+ delta: string;
12
+ } | {
13
+ type: 'tool_use';
14
+ id: string;
15
+ name: string;
16
+ input: unknown;
17
+ } | {
18
+ type: 'tool_result';
19
+ id: string;
20
+ output: string;
21
+ isError: boolean;
22
+ } | {
23
+ type: 'usage';
24
+ inputTokens?: number;
25
+ outputTokens?: number;
26
+ costUsd?: number;
27
+ } | {
28
+ type: 'done';
29
+ sessionId?: string;
30
+ } | {
31
+ type: 'error';
32
+ message: string;
33
+ };
34
+ interface AgentRunOptions {
35
+ prompt: string;
36
+ cwd?: string;
37
+ sessionId?: string;
38
+ model?: string;
39
+ permissionMode?: 'default' | 'acceptEdits' | 'bypassPermissions' | 'plan';
40
+ /**
41
+ * Grace period (ms) between SIGTERM and SIGKILL when stop() is called on
42
+ * the returned run. Lets the agent (and any subprocess it spawned, e.g.
43
+ * lark-cli mid-OAuth) clean up before the kernel reaps the tree.
44
+ * Adapters that don't kill via signals are free to ignore this. Defaults
45
+ * are adapter-specific.
46
+ */
47
+ stopGraceMs?: number;
48
+ }
49
+ interface AgentRun {
50
+ readonly events: AsyncIterable<AgentEvent>;
51
+ stop(): Promise<void>;
52
+ /**
53
+ * Wait up to `timeoutMs` for the agent process to exit on its own.
54
+ * Resolves true if it exited within the window, false if the timer
55
+ * fired first (caller usually wants to fall back to stop()).
56
+ *
57
+ * Use this after a terminal stream event (`done` / `error`): the
58
+ * stream-json `result` line arrives before codex has actually closed
59
+ * stdout — there's a brief telemetry/cleanup tail in between. Calling
60
+ * stop() in that window forces a SIGTERM and the run exits with code
61
+ * 143 instead of 0; waiting it out lets it exit cleanly.
62
+ */
63
+ waitForExit(timeoutMs: number): Promise<boolean>;
64
+ }
65
+ interface AgentAdapter {
66
+ readonly id: string;
67
+ readonly displayName: string;
68
+ isAvailable(): Promise<boolean>;
69
+ run(opts: AgentRunOptions): AgentRun;
70
+ }
71
+
72
+ type ToolStatus = 'running' | 'done' | 'error';
73
+ interface ToolEntry {
74
+ id: string;
75
+ name: string;
76
+ input: unknown;
77
+ status: ToolStatus;
78
+ output?: string;
79
+ }
80
+ type Block = {
81
+ kind: 'text';
82
+ content: string;
83
+ streaming: boolean;
84
+ } | {
85
+ kind: 'tool';
86
+ tool: ToolEntry;
87
+ };
88
+ type FooterStatus = 'thinking' | 'tool_running' | 'streaming' | null;
89
+ type Terminal = 'running' | 'done' | 'interrupted' | 'error' | 'idle_timeout';
90
+ interface RunState {
91
+ blocks: Block[];
92
+ reasoning: {
93
+ content: string;
94
+ active: boolean;
95
+ };
96
+ footer: FooterStatus;
97
+ terminal: Terminal;
98
+ errorMsg?: string;
99
+ /** Set when terminal === 'idle_timeout' — how long codex was idle before
100
+ * the watchdog gave up (so the message can say "N 分钟无响应"). */
101
+ idleTimeoutMinutes?: number;
102
+ }
103
+ declare const initialState: RunState;
104
+ declare function reduce(state: RunState, evt: AgentEvent): RunState;
105
+ declare function markInterrupted(state: RunState): RunState;
106
+ declare function finalizeIfRunning(state: RunState): RunState;
107
+
108
+ declare function renderCard(state: RunState): object;
109
+
110
+ /**
111
+ * Render `RunState` as plain markdown text — used in `messageReply: 'text'`
112
+ * mode where we stream a markdown message instead of a card.
113
+ *
114
+ * Differences vs `renderCard`:
115
+ * - No collapsible panels, no buttons (markdown messages have neither)
116
+ * - Tool calls collapse to a single short line each (no body)
117
+ * - No reasoning / thinking output (no place to fold it; would be noise)
118
+ * - Footer is appended inline at the bottom while running
119
+ */
120
+ declare function renderText(state: RunState): string;
121
+
122
+ interface CodexAdapterOptions {
123
+ binary?: string;
124
+ }
125
+ declare class CodexAdapter implements AgentAdapter {
126
+ readonly id = "codex";
127
+ readonly displayName = "Codex";
128
+ private readonly binary;
129
+ constructor(opts?: CodexAdapterOptions);
130
+ isAvailable(): Promise<boolean>;
131
+ run(opts: AgentRunOptions): AgentRun;
132
+ }
133
+
134
+ export { type Block, CodexAdapter, type FooterStatus, type RunState, type Terminal, type ToolEntry, type ToolStatus, finalizeIfRunning, initialState, markInterrupted, reduce, renderCard, renderText };