cccc-sdk 0.1.0 → 0.1.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.
Files changed (50) hide show
  1. package/README.md +68 -186
  2. package/dist/client.d.ts +136 -186
  3. package/dist/client.d.ts.map +1 -0
  4. package/dist/client.js +419 -414
  5. package/dist/client.js.map +1 -0
  6. package/dist/errors.d.ts +32 -10
  7. package/dist/errors.d.ts.map +1 -0
  8. package/dist/errors.js +46 -16
  9. package/dist/errors.js.map +1 -0
  10. package/dist/index.d.ts +7 -7
  11. package/dist/index.d.ts.map +1 -0
  12. package/dist/index.js +11 -10
  13. package/dist/index.js.map +1 -0
  14. package/dist/transport.d.ts +44 -24
  15. package/dist/transport.d.ts.map +1 -0
  16. package/dist/transport.js +248 -92
  17. package/dist/transport.js.map +1 -0
  18. package/dist/types.d.ts +273 -0
  19. package/dist/types.d.ts.map +1 -0
  20. package/dist/types.js +5 -0
  21. package/dist/types.js.map +1 -0
  22. package/package.json +27 -26
  23. package/dist/types/actor.d.ts +0 -42
  24. package/dist/types/actor.d.ts.map +0 -1
  25. package/dist/types/actor.js +0 -5
  26. package/dist/types/actor.js.map +0 -1
  27. package/dist/types/context.d.ts +0 -89
  28. package/dist/types/context.d.ts.map +0 -1
  29. package/dist/types/context.js +0 -5
  30. package/dist/types/context.js.map +0 -1
  31. package/dist/types/event.d.ts +0 -15
  32. package/dist/types/event.d.ts.map +0 -1
  33. package/dist/types/event.js +0 -5
  34. package/dist/types/event.js.map +0 -1
  35. package/dist/types/group.d.ts +0 -33
  36. package/dist/types/group.d.ts.map +0 -1
  37. package/dist/types/group.js +0 -5
  38. package/dist/types/group.js.map +0 -1
  39. package/dist/types/index.d.ts +0 -10
  40. package/dist/types/index.d.ts.map +0 -1
  41. package/dist/types/index.js +0 -10
  42. package/dist/types/index.js.map +0 -1
  43. package/dist/types/ipc.d.ts +0 -24
  44. package/dist/types/ipc.d.ts.map +0 -1
  45. package/dist/types/ipc.js +0 -10
  46. package/dist/types/ipc.js.map +0 -1
  47. package/dist/types/message.d.ts +0 -53
  48. package/dist/types/message.d.ts.map +0 -1
  49. package/dist/types/message.js +0 -5
  50. package/dist/types/message.js.map +0 -1
package/dist/transport.js CHANGED
@@ -1,142 +1,298 @@
1
1
  /**
2
- * Unix Socket Transport Layer for CCCC daemon IPC
3
- *
4
- * Protocol:
5
- * - Uses Unix Domain Socket at $CCCC_HOME/daemon/ccccd.sock
6
- * - Messages are newline-delimited JSON
7
- * - Request: {"v": 1, "op": "xxx", "args": {...}}
8
- * - Response: {"v": 1, "ok": true/false, "result": {...}, "error": {...}}
2
+ * CCCC SDK transport layer - Unix socket / TCP
9
3
  */
10
4
  import * as net from 'node:net';
5
+ import * as fs from 'node:fs/promises';
11
6
  import * as path from 'node:path';
12
7
  import * as os from 'node:os';
13
- import * as fs from 'node:fs';
14
- import { CCCCError } from './errors.js';
15
- const DEFAULT_TIMEOUT_MS = 60_000;
16
- const MAX_RESPONSE_SIZE = 4_000_000; // 4MB
17
- /**
18
- * Get default CCCC home directory
19
- */
20
- export function getDefaultCcccHome() {
21
- return process.env['CCCC_HOME'] || path.join(os.homedir(), '.cccc');
8
+ import { DaemonUnavailableError } from './errors.js';
9
+ // ============================================================
10
+ // Constants
11
+ // ============================================================
12
+ export const MAX_LINE_SIZE = 4000000; // 4MB
13
+ export const DEFAULT_TIMEOUT_MS = 30000;
14
+ const MAX_PORT = 65535;
15
+ function normalizeTcpConnectHost(rawHost) {
16
+ const host = String(rawHost ?? '').trim();
17
+ if (!host || host === 'localhost' || host === '0.0.0.0') {
18
+ return '127.0.0.1';
19
+ }
20
+ // Daemon IPC currently uses AF_INET only; fall back to loopback for
21
+ // IPv6-style addresses (contains ':') or the IPv6 loopback literal.
22
+ if (host.includes(':') || host === '::1') {
23
+ return '127.0.0.1';
24
+ }
25
+ return host;
22
26
  }
27
+ // ============================================================
28
+ // Endpoint discovery
29
+ // ============================================================
23
30
  /**
24
- * Get socket path for CCCC daemon
31
+ * Get the default CCCC home directory path.
32
+ * Uses `$CCCC_HOME` if set, otherwise `~/.cccc`.
33
+ * @returns Absolute path to the CCCC home directory.
25
34
  */
26
- export function getSocketPath(ccccHome) {
27
- const home = ccccHome || getDefaultCcccHome();
28
- return path.join(home, 'daemon', 'ccccd.sock');
35
+ export function defaultHome() {
36
+ return process.env['CCCC_HOME'] || path.join(os.homedir(), '.cccc');
29
37
  }
30
38
  /**
31
- * Check if daemon socket exists
39
+ * Discover the daemon IPC endpoint by reading `ccccd.addr.json`.
40
+ * Falls back to the default Unix socket path if the address file is missing or unreadable.
41
+ * @param home - Optional CCCC home directory override.
42
+ * @returns The resolved {@link DaemonEndpoint} (TCP or Unix).
32
43
  */
33
- export function socketExists(ccccHome) {
34
- const sockPath = getSocketPath(ccccHome);
44
+ export async function discoverEndpoint(home) {
45
+ const ccccHome = home || defaultHome();
46
+ const addrPath = path.join(ccccHome, 'daemon', 'ccccd.addr.json');
35
47
  try {
36
- fs.accessSync(sockPath, fs.constants.F_OK);
37
- return true;
48
+ const content = await fs.readFile(addrPath, 'utf-8');
49
+ const descriptor = JSON.parse(content);
50
+ if (descriptor.v === 1) {
51
+ if (descriptor.transport === 'tcp' && descriptor.port) {
52
+ const port = Number(descriptor.port);
53
+ if (!Number.isInteger(port) || port <= 0 || port > MAX_PORT) {
54
+ throw new Error(`invalid daemon tcp port: ${descriptor.port}`);
55
+ }
56
+ return {
57
+ transport: 'tcp',
58
+ host: normalizeTcpConnectHost(descriptor.host),
59
+ port,
60
+ path: '',
61
+ };
62
+ }
63
+ if (descriptor.transport === 'unix' && descriptor.path) {
64
+ return {
65
+ transport: 'unix',
66
+ path: descriptor.path,
67
+ host: '',
68
+ port: 0,
69
+ };
70
+ }
71
+ }
38
72
  }
39
73
  catch {
40
- return false;
74
+ // Ignore read errors and try fallback.
41
75
  }
76
+ // Fallback to Unix socket.
77
+ const sockPath = path.join(ccccHome, 'daemon', 'ccccd.sock');
78
+ return {
79
+ transport: 'unix',
80
+ path: sockPath,
81
+ host: '',
82
+ port: 0,
83
+ };
42
84
  }
85
+ // ============================================================
86
+ // Socket connection
87
+ // ============================================================
43
88
  /**
44
- * Send a request to the CCCC daemon and receive a response
89
+ * Create socket connection
45
90
  */
46
- export async function callDaemon(request, options = {}) {
47
- const { ccccHome, timeoutMs = DEFAULT_TIMEOUT_MS } = options;
48
- const sockPath = getSocketPath(ccccHome);
49
- // Check socket exists
50
- if (!socketExists(ccccHome)) {
51
- throw new CCCCError('SOCKET_NOT_FOUND', `Socket not found at ${sockPath}`);
52
- }
91
+ function connect(endpoint, timeoutMs) {
53
92
  return new Promise((resolve, reject) => {
54
- const socket = net.createConnection(sockPath);
55
- let buffer = '';
56
- let resolved = false;
93
+ const socket = new net.Socket();
94
+ socket.setTimeout(timeoutMs);
57
95
  const cleanup = () => {
58
96
  socket.removeAllListeners();
97
+ };
98
+ const onError = (err) => {
99
+ cleanup();
59
100
  socket.destroy();
101
+ reject(new DaemonUnavailableError(err.message));
60
102
  };
61
- const handleError = (error) => {
62
- if (resolved)
63
- return;
64
- resolved = true;
103
+ const onTimeout = () => {
65
104
  cleanup();
66
- if (error.code === 'ECONNREFUSED') {
67
- reject(new CCCCError('DAEMON_NOT_RUNNING', 'Daemon is not running'));
68
- }
69
- else if (error.code === 'ENOENT') {
70
- reject(new CCCCError('SOCKET_NOT_FOUND', `Socket not found at ${sockPath}`));
71
- }
72
- else {
73
- reject(new CCCCError('INTERNAL', error.message));
74
- }
105
+ socket.destroy();
106
+ reject(new DaemonUnavailableError('Connection timeout'));
75
107
  };
76
- // Set timeout
77
- const timeoutId = setTimeout(() => {
78
- if (resolved)
79
- return;
80
- resolved = true;
108
+ socket.once('error', onError);
109
+ socket.once('timeout', onTimeout);
110
+ const onConnect = () => {
81
111
  cleanup();
82
- reject(new CCCCError('TIMEOUT', `Request timed out after ${timeoutMs}ms`));
83
- }, timeoutMs);
84
- socket.on('connect', () => {
85
- // Send request as newline-delimited JSON
86
- const payload = JSON.stringify(request) + '\n';
87
- socket.write(payload, 'utf-8');
88
- });
112
+ resolve(socket);
113
+ };
114
+ if (endpoint.transport === 'tcp') {
115
+ socket.connect(endpoint.port, endpoint.host, onConnect);
116
+ }
117
+ else if (endpoint.transport === 'unix') {
118
+ socket.connect(endpoint.path, onConnect);
119
+ }
120
+ else {
121
+ reject(new DaemonUnavailableError(`Invalid endpoint transport: ${endpoint.transport}`));
122
+ }
123
+ });
124
+ }
125
+ // ============================================================
126
+ // IPC calls
127
+ // ============================================================
128
+ /**
129
+ * Send a single IPC request to the daemon and return the response.
130
+ * Opens a new socket, sends the JSON-line request, reads exactly one JSON-line response,
131
+ * then destroys the socket.
132
+ * @param endpoint - The daemon endpoint to connect to.
133
+ * @param request - The IPC request envelope.
134
+ * @param timeoutMs - Connection and response timeout in milliseconds.
135
+ * @returns The parsed {@link DaemonResponse}.
136
+ * @throws {DaemonUnavailableError} On connection, write, or parse failure.
137
+ */
138
+ export async function callDaemon(endpoint, request, timeoutMs = DEFAULT_TIMEOUT_MS) {
139
+ const socket = await connect(endpoint, timeoutMs);
140
+ return new Promise((resolve, reject) => {
141
+ let buffer = '';
142
+ let resolved = false;
143
+ const cleanup = () => {
144
+ socket.removeAllListeners();
145
+ };
89
146
  socket.on('data', (chunk) => {
90
147
  buffer += chunk.toString('utf-8');
91
- // Check size limit
92
- if (buffer.length > MAX_RESPONSE_SIZE) {
93
- if (resolved)
148
+ const newlineIndex = buffer.indexOf('\n');
149
+ if (newlineIndex !== -1 && !resolved) {
150
+ resolved = true;
151
+ const line = buffer.slice(0, newlineIndex);
152
+ cleanup();
153
+ socket.destroy();
154
+ if (line.length > MAX_LINE_SIZE) {
155
+ reject(new DaemonUnavailableError('Response too large'));
94
156
  return;
157
+ }
158
+ try {
159
+ resolve(JSON.parse(line));
160
+ }
161
+ catch {
162
+ reject(new DaemonUnavailableError('Invalid JSON response'));
163
+ }
164
+ }
165
+ });
166
+ socket.on('error', (err) => {
167
+ if (!resolved) {
168
+ resolved = true;
169
+ cleanup();
170
+ socket.destroy();
171
+ reject(new DaemonUnavailableError(err.message));
172
+ }
173
+ });
174
+ socket.on('close', () => {
175
+ if (!resolved) {
176
+ resolved = true;
177
+ cleanup();
178
+ socket.destroy();
179
+ reject(new DaemonUnavailableError('Connection closed unexpectedly'));
180
+ }
181
+ });
182
+ // Send request.
183
+ const line = JSON.stringify(request) + '\n';
184
+ socket.write(line, (err) => {
185
+ if (err && !resolved) {
95
186
  resolved = true;
96
- clearTimeout(timeoutId);
97
187
  cleanup();
98
- reject(new CCCCError('INTERNAL', 'Response too large'));
99
- return;
188
+ socket.destroy();
189
+ reject(new DaemonUnavailableError(`Write failed: ${err.message}`));
100
190
  }
101
- // Check for complete response (newline terminated)
191
+ });
192
+ });
193
+ }
194
+ /**
195
+ * Open a long-lived event stream connection to the daemon.
196
+ * Sends the request, reads the handshake response, and returns the socket
197
+ * for continued streaming via {@link readLines}.
198
+ * @param endpoint - The daemon endpoint to connect to.
199
+ * @param request - The IPC request envelope (op should be `events_stream`).
200
+ * @param timeoutMs - Connection and handshake timeout in milliseconds.
201
+ * @returns The socket, handshake response, and any buffered data after the handshake.
202
+ * @throws {DaemonUnavailableError} On connection or handshake failure.
203
+ */
204
+ export async function openEventsStream(endpoint, request, timeoutMs = DEFAULT_TIMEOUT_MS) {
205
+ const socket = await connect(endpoint, timeoutMs);
206
+ // Send request.
207
+ const line = JSON.stringify(request) + '\n';
208
+ await new Promise((resolve, reject) => {
209
+ socket.write(line, (err) => {
210
+ if (err) {
211
+ socket.destroy();
212
+ reject(new DaemonUnavailableError(`Write failed: ${err.message}`));
213
+ }
214
+ else {
215
+ resolve();
216
+ }
217
+ });
218
+ });
219
+ // Read handshake response.
220
+ const { handshake, remainingBuffer } = await new Promise((resolve, reject) => {
221
+ let buffer = '';
222
+ let resolved = false;
223
+ const cleanup = () => {
224
+ socket.removeAllListeners();
225
+ };
226
+ const onData = (chunk) => {
227
+ buffer += chunk.toString('utf-8');
102
228
  const newlineIndex = buffer.indexOf('\n');
103
- if (newlineIndex !== -1) {
104
- if (resolved)
105
- return;
229
+ if (newlineIndex !== -1 && !resolved) {
106
230
  resolved = true;
107
- clearTimeout(timeoutId);
108
231
  cleanup();
109
- const line = buffer.slice(0, newlineIndex);
232
+ const responseLine = buffer.slice(0, newlineIndex);
233
+ const remaining = buffer.slice(newlineIndex + 1);
110
234
  try {
111
- const response = JSON.parse(line);
112
- resolve(response);
235
+ resolve({
236
+ handshake: JSON.parse(responseLine),
237
+ remainingBuffer: remaining,
238
+ });
113
239
  }
114
240
  catch {
115
- reject(new CCCCError('INTERNAL', 'Invalid JSON response from daemon'));
241
+ socket.destroy();
242
+ reject(new DaemonUnavailableError('Invalid handshake JSON'));
116
243
  }
117
244
  }
245
+ };
246
+ socket.on('data', onData);
247
+ socket.once('error', (err) => {
248
+ if (!resolved) {
249
+ resolved = true;
250
+ cleanup();
251
+ socket.destroy();
252
+ reject(new DaemonUnavailableError(err.message));
253
+ }
118
254
  });
119
- socket.on('error', handleError);
120
- socket.on('close', () => {
121
- if (resolved)
122
- return;
123
- resolved = true;
124
- clearTimeout(timeoutId);
125
- cleanup();
126
- reject(new CCCCError('DAEMON_NOT_RUNNING', 'Connection closed unexpectedly'));
255
+ socket.once('close', () => {
256
+ if (!resolved) {
257
+ resolved = true;
258
+ cleanup();
259
+ socket.destroy();
260
+ reject(new DaemonUnavailableError('Connection closed during handshake'));
261
+ }
127
262
  });
128
263
  });
264
+ // Remove timeout after handshake.
265
+ socket.setTimeout(0);
266
+ return { socket, handshake, initialBuffer: remainingBuffer };
129
267
  }
130
268
  /**
131
- * Ping the daemon to check if it's running
269
+ * Async generator that yields newline-delimited lines from a socket.
270
+ * Handles buffering and splits on `\n`. Empty/whitespace-only lines are skipped.
271
+ * @param socket - The connected socket to read from.
272
+ * @param initialBuffer - Any data already buffered before this generator starts.
273
+ * @yields Each non-empty line as a string (without the trailing newline).
132
274
  */
133
- export async function pingDaemon(options = {}) {
134
- try {
135
- const response = await callDaemon({ v: 1, op: 'ping', args: {} }, options);
136
- return response.ok;
275
+ export async function* readLines(socket, initialBuffer = '') {
276
+ let buffer = initialBuffer;
277
+ // Handle lines from initial buffer.
278
+ let newlineIndex;
279
+ while ((newlineIndex = buffer.indexOf('\n')) !== -1) {
280
+ const line = buffer.slice(0, newlineIndex);
281
+ buffer = buffer.slice(newlineIndex + 1);
282
+ if (line.trim()) {
283
+ yield line;
284
+ }
137
285
  }
138
- catch {
139
- return false;
286
+ // Continue reading from socket.
287
+ for await (const chunk of socket) {
288
+ buffer += chunk.toString('utf-8');
289
+ while ((newlineIndex = buffer.indexOf('\n')) !== -1) {
290
+ const line = buffer.slice(0, newlineIndex);
291
+ buffer = buffer.slice(newlineIndex + 1);
292
+ if (line.trim()) {
293
+ yield line;
294
+ }
295
+ }
140
296
  }
141
297
  }
142
298
  //# sourceMappingURL=transport.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transport.js","sourceRoot":"","sources":["../src/transport.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,GAAG,MAAM,UAAU,CAAC;AAChC,OAAO,KAAK,EAAE,MAAM,kBAAkB,CAAC;AACvC,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAClC,OAAO,KAAK,EAAE,MAAM,SAAS,CAAC;AAO9B,OAAO,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAC;AAErD,+DAA+D;AAC/D,YAAY;AACZ,+DAA+D;AAE/D,MAAM,CAAC,MAAM,aAAa,GAAG,OAAS,CAAC,CAAC,MAAM;AAC9C,MAAM,CAAC,MAAM,kBAAkB,GAAG,KAAM,CAAC;AACzC,MAAM,QAAQ,GAAG,KAAM,CAAC;AAExB,SAAS,uBAAuB,CAAC,OAA2B;IAC1D,MAAM,IAAI,GAAG,MAAM,CAAC,OAAO,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC;IAC1C,IAAI,CAAC,IAAI,IAAI,IAAI,KAAK,WAAW,IA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E,YAAY,CAAC,CAAC;QAC3C,MAAM,GAAG,MAAM,CAAC,KAAK,CAAC,YAAY,GAAG,CAAC,CAAC,CAAC;QACxC,IAAI,IAAI,CAAC,IAAI,EAAE,EAAE,CAAC;YAChB,MAAM,IAAI,CAAC;QACb,CAAC;IACH,CAAC;IAED,gCAAgC;IAChC,IAAI,KAAK,EAAE,MAAM,KAAK,IAAI,MAAM,EAAE,CAAC;QACjC,MAAM,IAAK,KAAgB,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;QAE9C,OAAO,CAAC,YAAY,GAAG,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC;YACpD,MAAM,IAAI,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,YAAY,CAAC,CAAC;YAC3C,MAAM,GAAG,MAAM,CAAC,KAAK,CAAC,YAAY,GAAG,CAAC,CAAC,CAAC;YACxC,IAAI,IAAI,CAAC,IAAI,EAAE,EAAE,CAAC;gBAChB,MAAM,IAAI,CAAC;YACb,CAAC;QACH,CAAC;IACH,CAAC;AACH,CAAC"}
@@ -0,0 +1,273 @@
1
+ /**
2
+ * CCCC SDK type definitions
3
+ */
4
+ /** IPC request envelope */
5
+ export interface DaemonRequest {
6
+ v: 1;
7
+ op: string;
8
+ args?: Record<string, unknown>;
9
+ }
10
+ /** IPC response envelope */
11
+ export interface DaemonResponse {
12
+ v?: 1;
13
+ ok: boolean;
14
+ result?: Record<string, unknown>;
15
+ error?: DaemonErrorPayload;
16
+ }
17
+ /** Error payload */
18
+ export interface DaemonErrorPayload {
19
+ code: string;
20
+ message: string;
21
+ details?: Record<string, unknown>;
22
+ }
23
+ /** Daemon endpoint */
24
+ export interface DaemonEndpoint {
25
+ readonly transport: 'unix' | 'tcp' | '';
26
+ readonly path: string;
27
+ readonly host: string;
28
+ readonly port: number;
29
+ }
30
+ /** Address descriptor (ccccd.addr.json) */
31
+ export interface AddressDescriptor {
32
+ v: 1;
33
+ transport: 'unix' | 'tcp';
34
+ path?: string;
35
+ host?: string;
36
+ port?: number;
37
+ pid?: number;
38
+ version?: string;
39
+ ts?: string;
40
+ }
41
+ /** Event stream item */
42
+ export type EventStreamItem = {
43
+ t: 'event';
44
+ event: CCCSEvent;
45
+ } | {
46
+ t: 'heartbeat';
47
+ ts: string;
48
+ } | {
49
+ t: string;
50
+ [key: string]: unknown;
51
+ };
52
+ /** CCCS event */
53
+ export interface CCCSEvent {
54
+ id: string;
55
+ ts: string;
56
+ kind: string;
57
+ group_id: string;
58
+ data: Record<string, unknown>;
59
+ }
60
+ /** Client initialization options */
61
+ export interface CCCCClientOptions {
62
+ ccccHome?: string;
63
+ endpoint?: DaemonEndpoint;
64
+ timeoutMs?: number;
65
+ }
66
+ /** Compatibility check options */
67
+ export interface CompatibilityOptions {
68
+ requireIpcV?: number;
69
+ requireCapabilities?: Record<string, boolean>;
70
+ requireOps?: string[];
71
+ }
72
+ /** Send message options */
73
+ export interface SendOptions {
74
+ groupId: string;
75
+ text: string;
76
+ by?: string;
77
+ to?: string[];
78
+ priority?: 'normal' | 'attention';
79
+ replyRequired?: boolean;
80
+ path?: string;
81
+ }
82
+ /** Send-cross-group options */
83
+ export interface SendCrossGroupOptions {
84
+ groupId: string;
85
+ dstGroupId: string;
86
+ text: string;
87
+ by?: string;
88
+ to?: string[];
89
+ priority?: 'normal' | 'attention';
90
+ replyRequired?: boolean;
91
+ }
92
+ /** Reply message options */
93
+ export interface ReplyOptions {
94
+ groupId: string;
95
+ replyTo: string;
96
+ text: string;
97
+ by?: string;
98
+ to?: string[];
99
+ priority?: 'normal' | 'attention';
100
+ replyRequired?: boolean;
101
+ }
102
+ /** Add actor options */
103
+ export interface ActorAddOptions {
104
+ groupId: string;
105
+ actorId?: string;
106
+ title?: string;
107
+ runtime?: string;
108
+ runner?: string;
109
+ command?: string[];
110
+ env?: Record<string, string>;
111
+ envPrivate?: Record<string, string>;
112
+ defaultScopeKey?: string;
113
+ submit?: string;
114
+ by?: string;
115
+ }
116
+ /** Update actor options */
117
+ export interface ActorUpdateOptions {
118
+ groupId: string;
119
+ actorId: string;
120
+ patch: Record<string, unknown>;
121
+ by?: string;
122
+ }
123
+ /** Actor private env vars (secrets, runtime-only) */
124
+ export interface ActorEnvPrivateUpdateOptions {
125
+ groupId: string;
126
+ actorId: string;
127
+ by?: string;
128
+ set?: Record<string, string>;
129
+ unset?: string[];
130
+ clear?: boolean;
131
+ }
132
+ /** Create group options */
133
+ export interface GroupCreateOptions {
134
+ title?: string;
135
+ topic?: string;
136
+ by?: string;
137
+ }
138
+ /** Update group options */
139
+ export interface GroupUpdateOptions {
140
+ groupId: string;
141
+ patch: Record<string, unknown>;
142
+ by?: string;
143
+ }
144
+ /** Automation notify priority */
145
+ export type AutomationNotifyPriority = 'low' | 'normal' | 'high' | 'urgent';
146
+ /** Automation trigger (interval) */
147
+ export interface AutomationTriggerInterval {
148
+ kind: 'interval';
149
+ every_seconds: number;
150
+ }
151
+ /** Automation trigger (cron) */
152
+ export interface AutomationTriggerCron {
153
+ kind: 'cron';
154
+ cron: string;
155
+ timezone?: string;
156
+ }
157
+ /** Automation trigger (one-time) */
158
+ export interface AutomationTriggerAt {
159
+ kind: 'at';
160
+ at: string;
161
+ }
162
+ /** Automation trigger */
163
+ export type AutomationTrigger = AutomationTriggerInterval | AutomationTriggerCron | AutomationTriggerAt;
164
+ /** Automation action (notify) */
165
+ export interface AutomationActionNotify {
166
+ kind: 'notify';
167
+ title?: string;
168
+ snippet_ref?: string | null;
169
+ message?: string;
170
+ priority?: AutomationNotifyPriority;
171
+ requires_ack?: boolean;
172
+ }
173
+ /** Automation action (group state) */
174
+ export interface AutomationActionGroupState {
175
+ kind: 'group_state';
176
+ state: 'active' | 'idle' | 'paused' | 'stopped';
177
+ }
178
+ /** Automation action (actor control) */
179
+ export interface AutomationActionActorControl {
180
+ kind: 'actor_control';
181
+ operation: 'start' | 'stop' | 'restart';
182
+ targets?: string[];
183
+ }
184
+ /** Automation action */
185
+ export type AutomationAction = AutomationActionNotify | AutomationActionGroupState | AutomationActionActorControl;
186
+ /** Automation rule */
187
+ export interface AutomationRule {
188
+ id: string;
189
+ enabled?: boolean;
190
+ scope?: 'group' | 'personal';
191
+ owner_actor_id?: string | null;
192
+ to?: string[];
193
+ trigger?: AutomationTrigger;
194
+ action?: AutomationAction;
195
+ }
196
+ /** Automation ruleset */
197
+ export interface AutomationRuleSet {
198
+ rules: AutomationRule[];
199
+ snippets: Record<string, string>;
200
+ }
201
+ /** Automation manage action: create rule */
202
+ export interface AutomationManageCreateRule {
203
+ type: 'create_rule';
204
+ rule: AutomationRule;
205
+ }
206
+ /** Automation manage action: update rule */
207
+ export interface AutomationManageUpdateRule {
208
+ type: 'update_rule';
209
+ rule: AutomationRule;
210
+ }
211
+ /** Automation manage action: toggle rule */
212
+ export interface AutomationManageSetRuleEnabled {
213
+ type: 'set_rule_enabled';
214
+ rule_id: string;
215
+ enabled: boolean;
216
+ }
217
+ /** Automation manage action: delete rule */
218
+ export interface AutomationManageDeleteRule {
219
+ type: 'delete_rule';
220
+ rule_id: string;
221
+ }
222
+ /** Automation manage action: replace all */
223
+ export interface AutomationManageReplaceAllRules {
224
+ type: 'replace_all_rules';
225
+ ruleset: AutomationRuleSet;
226
+ }
227
+ /** Automation manage action */
228
+ export type AutomationManageAction = AutomationManageCreateRule | AutomationManageUpdateRule | AutomationManageSetRuleEnabled | AutomationManageDeleteRule | AutomationManageReplaceAllRules;
229
+ /** Group automation update options */
230
+ export interface GroupAutomationUpdateOptions {
231
+ groupId: string;
232
+ ruleset: AutomationRuleSet;
233
+ by?: string;
234
+ expectedVersion?: number;
235
+ }
236
+ /** Group automation incremental-manage options */
237
+ export interface GroupAutomationManageOptions {
238
+ groupId: string;
239
+ by?: string;
240
+ expectedVersion?: number;
241
+ actions: AutomationManageAction[];
242
+ }
243
+ /** Group automation reset options */
244
+ export interface GroupAutomationResetBaselineOptions {
245
+ groupId: string;
246
+ by?: string;
247
+ expectedVersion?: number;
248
+ }
249
+ /** Inbox list options */
250
+ export interface InboxListOptions {
251
+ groupId: string;
252
+ actorId: string;
253
+ by?: string;
254
+ limit?: number;
255
+ kindFilter?: string;
256
+ }
257
+ /** Context sync options */
258
+ export interface ContextSyncOptions {
259
+ groupId: string;
260
+ ops: Record<string, unknown>[];
261
+ by?: string;
262
+ dryRun?: boolean;
263
+ }
264
+ /** Event stream options */
265
+ export interface EventsStreamOptions {
266
+ groupId: string;
267
+ by?: string;
268
+ kinds?: Set<string> | string[];
269
+ sinceEventId?: string;
270
+ sinceTs?: string;
271
+ timeoutMs?: number;
272
+ }
273
+ //# sourceMappingURL=types.d.ts.map