@intella/sdk 0.0.1 → 0.0.3

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 (117) hide show
  1. package/README.md +6 -483
  2. package/dist/agent-manager.d.ts +47 -0
  3. package/dist/agent-manager.d.ts.map +1 -0
  4. package/dist/agent-manager.js +90 -0
  5. package/dist/agent-manager.js.map +1 -0
  6. package/dist/agents/base-agent.d.ts +41 -0
  7. package/dist/agents/base-agent.d.ts.map +1 -0
  8. package/dist/agents/base-agent.js +148 -0
  9. package/dist/agents/base-agent.js.map +1 -0
  10. package/dist/agents/claude-agent.d.ts +24 -0
  11. package/dist/agents/claude-agent.d.ts.map +1 -0
  12. package/dist/agents/claude-agent.js +65 -0
  13. package/dist/agents/claude-agent.js.map +1 -0
  14. package/dist/agents/codex-agent.d.ts +25 -0
  15. package/dist/agents/codex-agent.d.ts.map +1 -0
  16. package/dist/agents/codex-agent.js +62 -0
  17. package/dist/agents/codex-agent.js.map +1 -0
  18. package/dist/agents/intella-lite-agent.d.ts +21 -0
  19. package/dist/agents/intella-lite-agent.d.ts.map +1 -0
  20. package/dist/agents/intella-lite-agent.js +43 -0
  21. package/dist/agents/intella-lite-agent.js.map +1 -0
  22. package/dist/agents/opencode-agent.d.ts +20 -0
  23. package/dist/agents/opencode-agent.d.ts.map +1 -0
  24. package/dist/agents/opencode-agent.js +36 -0
  25. package/dist/agents/opencode-agent.js.map +1 -0
  26. package/dist/filesystem/base-provider.d.ts +55 -0
  27. package/dist/filesystem/base-provider.d.ts.map +1 -0
  28. package/dist/filesystem/base-provider.js +45 -0
  29. package/dist/filesystem/base-provider.js.map +1 -0
  30. package/dist/filesystem/index.d.ts +3 -0
  31. package/dist/filesystem/index.d.ts.map +1 -0
  32. package/{src/filesystem/index.ts → dist/filesystem/index.js} +1 -2
  33. package/dist/filesystem/index.js.map +1 -0
  34. package/dist/filesystem/memory-provider.d.ts +44 -0
  35. package/dist/filesystem/memory-provider.d.ts.map +1 -0
  36. package/dist/filesystem/memory-provider.js +227 -0
  37. package/dist/filesystem/memory-provider.js.map +1 -0
  38. package/dist/filesystem-manager.d.ts +75 -0
  39. package/dist/filesystem-manager.d.ts.map +1 -0
  40. package/dist/filesystem-manager.js +162 -0
  41. package/dist/filesystem-manager.js.map +1 -0
  42. package/dist/index.d.ts +18 -0
  43. package/dist/index.d.ts.map +1 -0
  44. package/{src/index.ts → dist/index.js} +4 -47
  45. package/dist/index.js.map +1 -0
  46. package/dist/orchestrator.d.ts +32 -0
  47. package/dist/orchestrator.d.ts.map +1 -0
  48. package/dist/orchestrator.js +137 -0
  49. package/dist/orchestrator.js.map +1 -0
  50. package/dist/sandbox/base-provider.d.ts +106 -0
  51. package/dist/sandbox/base-provider.d.ts.map +1 -0
  52. package/dist/sandbox/base-provider.js +74 -0
  53. package/dist/sandbox/base-provider.js.map +1 -0
  54. package/dist/sandbox/daytona-provider.d.ts +93 -0
  55. package/dist/sandbox/daytona-provider.d.ts.map +1 -0
  56. package/dist/sandbox/daytona-provider.js +378 -0
  57. package/dist/sandbox/daytona-provider.js.map +1 -0
  58. package/dist/sandbox/e2b-provider.d.ts +85 -0
  59. package/dist/sandbox/e2b-provider.d.ts.map +1 -0
  60. package/dist/sandbox/e2b-provider.js +363 -0
  61. package/dist/sandbox/e2b-provider.js.map +1 -0
  62. package/dist/sandbox/modal-provider.d.ts +92 -0
  63. package/dist/sandbox/modal-provider.d.ts.map +1 -0
  64. package/dist/sandbox/modal-provider.js +516 -0
  65. package/dist/sandbox/modal-provider.js.map +1 -0
  66. package/dist/sandbox-manager.d.ts +59 -0
  67. package/dist/sandbox-manager.d.ts.map +1 -0
  68. package/dist/sandbox-manager.js +141 -0
  69. package/dist/sandbox-manager.js.map +1 -0
  70. package/dist/sdk.d.ts +173 -0
  71. package/dist/sdk.d.ts.map +1 -0
  72. package/dist/sdk.js +277 -0
  73. package/dist/sdk.js.map +1 -0
  74. package/dist/types.d.ts +423 -0
  75. package/dist/types.d.ts.map +1 -0
  76. package/dist/types.js +2 -0
  77. package/dist/types.js.map +1 -0
  78. package/dist/utils/code-extractor.d.ts +103 -0
  79. package/dist/utils/code-extractor.d.ts.map +1 -0
  80. package/dist/utils/code-extractor.js +133 -0
  81. package/dist/utils/code-extractor.js.map +1 -0
  82. package/package.json +23 -11
  83. package/examples/claude-code/README.md +0 -178
  84. package/examples/claude-code/advanced-config.ts +0 -55
  85. package/examples/claude-code/basic-usage.ts +0 -56
  86. package/examples/claude-code/model-comparison.ts +0 -50
  87. package/examples/claude-code/orchestration.ts +0 -70
  88. package/examples/claude-code/streaming.ts +0 -69
  89. package/examples/claude-code/tsconfig.json +0 -19
  90. package/examples/code-extractor/README.md +0 -77
  91. package/examples/code-extractor/example.ts +0 -145
  92. package/examples/filesystem/basic-usage.ts +0 -84
  93. package/examples/integrated-task/README.md +0 -68
  94. package/examples/integrated-task/integrated-usage.ts +0 -193
  95. package/examples/integrated-task/simple-example.ts +0 -51
  96. package/examples/integrated-task/tsconfig.json +0 -19
  97. package/examples/sandbox/basic-usage.ts +0 -173
  98. package/src/agent-manager.ts +0 -104
  99. package/src/agents/base-agent.ts +0 -166
  100. package/src/agents/claude-agent.ts +0 -77
  101. package/src/agents/codex-agent.ts +0 -72
  102. package/src/agents/intella-lite-agent.ts +0 -55
  103. package/src/agents/opencode-agent.ts +0 -45
  104. package/src/filesystem/agentfs-provider.ts +0 -328
  105. package/src/filesystem/base-provider.ts +0 -98
  106. package/src/filesystem/memory-provider.ts +0 -267
  107. package/src/filesystem-manager.ts +0 -213
  108. package/src/orchestrator.ts +0 -177
  109. package/src/sandbox/base-provider.ts +0 -184
  110. package/src/sandbox/daytona-provider.ts +0 -462
  111. package/src/sandbox/e2b-provider.ts +0 -419
  112. package/src/sandbox/modal-provider.ts +0 -597
  113. package/src/sandbox-manager.ts +0 -175
  114. package/src/sdk.ts +0 -401
  115. package/src/types.ts +0 -451
  116. package/src/utils/code-extractor.ts +0 -194
  117. package/tsconfig.json +0 -25
@@ -0,0 +1,423 @@
1
+ import type { LanguageModel } from 'ai';
2
+ /**
3
+ * Supported agent types
4
+ */
5
+ export type AgentType = 'intella-lite' | 'claude' | 'codex' | 'opencode';
6
+ /**
7
+ * Agent configuration interface
8
+ */
9
+ export interface AgentConfig {
10
+ /** API key for the agent (provider-specific) */
11
+ apiKey?: string;
12
+ /** Model identifier to use */
13
+ model?: string;
14
+ /** Temperature for generation (0-2) */
15
+ temperature?: number;
16
+ /** Maximum tokens to generate */
17
+ maxTokens?: number;
18
+ /** Working directory */
19
+ cwd?: string;
20
+ /** Custom headers for the provider */
21
+ headers?: Record<string, string>;
22
+ /** Base URL for the provider (if applicable) */
23
+ baseURL?: string;
24
+ /** Additional provider-specific options */
25
+ [key: string]: unknown;
26
+ }
27
+ /**
28
+ * Text part for message content
29
+ */
30
+ export interface TextPart {
31
+ type: 'text';
32
+ text: string;
33
+ }
34
+ /**
35
+ * File part for message content (attachments)
36
+ */
37
+ export interface FilePart {
38
+ type: 'file';
39
+ data: string | Uint8Array | ArrayBuffer | Buffer | URL;
40
+ filename?: string;
41
+ mediaType: string;
42
+ }
43
+ /**
44
+ * Message content can be a string or array of parts (text and/or files)
45
+ */
46
+ export type MessageContent = string | Array<TextPart | FilePart>;
47
+ /**
48
+ * Task execution request
49
+ */
50
+ export interface TaskRequest {
51
+ /** The prompt or task description */
52
+ prompt: string;
53
+ /** System prompt (optional) */
54
+ systemPrompt?: string;
55
+ /** Additional messages for context */
56
+ messages?: Array<{
57
+ role: 'user' | 'assistant' | 'system';
58
+ content: MessageContent;
59
+ }>;
60
+ /** Generation parameters */
61
+ temperature?: number;
62
+ maxTokens?: number;
63
+ /** Additional options */
64
+ [key: string]: unknown;
65
+ }
66
+ /**
67
+ * Task execution response
68
+ */
69
+ export interface TaskResponse {
70
+ /** Generated text response */
71
+ text: string;
72
+ /** Agent type that generated the response */
73
+ agentType: AgentType;
74
+ /** Additional metadata */
75
+ metadata?: {
76
+ usage?: {
77
+ promptTokens?: number;
78
+ completionTokens?: number;
79
+ totalTokens?: number;
80
+ };
81
+ finishReason?: string;
82
+ [key: string]: unknown;
83
+ };
84
+ }
85
+ /**
86
+ * Streaming response chunk
87
+ */
88
+ export interface StreamChunk {
89
+ /** Chunk ID */
90
+ id: string;
91
+ /** Text chunk */
92
+ text: string;
93
+ /** Agent type */
94
+ agentType: AgentType;
95
+ /** Whether this is the final chunk */
96
+ isDone: boolean;
97
+ }
98
+ /**
99
+ * Orchestration strategy types
100
+ */
101
+ export type OrchestrationStrategy = 'sequential' | 'parallel' | 'conditional';
102
+ /**
103
+ * Multi-agent orchestration request
104
+ */
105
+ export interface OrchestrationRequest {
106
+ /** The task to execute */
107
+ task: TaskRequest;
108
+ /** List of agent types to use */
109
+ agents: AgentType[];
110
+ /** Orchestration strategy */
111
+ strategy: OrchestrationStrategy;
112
+ /** Strategy-specific options */
113
+ options?: {
114
+ /** For sequential: whether to pass previous results to next agent */
115
+ passResults?: boolean;
116
+ /** For parallel: how to combine results */
117
+ combineStrategy?: 'merge' | 'first' | 'best';
118
+ /** For conditional: routing function */
119
+ router?: (task: TaskRequest) => AgentType;
120
+ };
121
+ }
122
+ /**
123
+ * Multi-agent orchestration response
124
+ */
125
+ export interface OrchestrationResponse {
126
+ /** Final result */
127
+ result: string;
128
+ /** Individual agent responses */
129
+ agentResponses: Array<{
130
+ agentType: AgentType;
131
+ response: string;
132
+ metadata?: TaskResponse['metadata'];
133
+ }>;
134
+ /** Strategy used */
135
+ strategy: OrchestrationStrategy;
136
+ }
137
+ /**
138
+ * Base agent interface
139
+ */
140
+ export interface IAgent {
141
+ /** Agent type */
142
+ readonly type: AgentType;
143
+ /** Execute a task and return the response */
144
+ execute(request: TaskRequest): Promise<TaskResponse>;
145
+ /** Stream a task execution */
146
+ stream(request: TaskRequest): AsyncIterable<StreamChunk>;
147
+ /** Configure the agent */
148
+ configure(config: AgentConfig): void;
149
+ /** Get current configuration */
150
+ getConfig(): AgentConfig;
151
+ /** Get the underlying language model */
152
+ getModel(): LanguageModel | Promise<LanguageModel>;
153
+ }
154
+ /**
155
+ * Supported filesystem provider types
156
+ */
157
+ export type FilesystemProviderType = 'agentfs' | 'memory' | 'sandbox';
158
+ /**
159
+ * Filesystem provider configuration
160
+ */
161
+ export interface FilesystemConfig {
162
+ /** Provider-specific configuration */
163
+ provider?: FilesystemProviderType;
164
+ /** Agent ID for the filesystem (used by AgentFS) */
165
+ agentId?: string;
166
+ /** Database path for AgentFS */
167
+ dbPath?: string;
168
+ /** Additional provider-specific options */
169
+ [key: string]: unknown;
170
+ }
171
+ /**
172
+ * File statistics
173
+ */
174
+ export interface FileStats {
175
+ /** File size in bytes */
176
+ size: number;
177
+ /** Whether it's a directory */
178
+ isDirectory: boolean;
179
+ /** Whether it's a file */
180
+ isFile: boolean;
181
+ /** Creation time (Unix timestamp) */
182
+ createdAt?: number;
183
+ /** Modification time (Unix timestamp) */
184
+ modifiedAt?: number;
185
+ }
186
+ /**
187
+ * Directory entry
188
+ */
189
+ export interface DirectoryEntry {
190
+ /** Entry name */
191
+ name: string;
192
+ /** Entry path */
193
+ path: string;
194
+ /** Entry statistics */
195
+ stats: FileStats;
196
+ }
197
+ /**
198
+ * Tool call metadata for recording
199
+ */
200
+ export interface ToolCallMetadata {
201
+ /** Tool name */
202
+ tool: string;
203
+ /** Start time (Unix timestamp in seconds) */
204
+ startedAt: number;
205
+ /** End time (Unix timestamp in seconds) */
206
+ endedAt: number;
207
+ /** Tool input parameters */
208
+ input?: Record<string, unknown>;
209
+ /** Tool output/result */
210
+ output?: unknown;
211
+ /** Tool status */
212
+ status?: 'success' | 'error' | 'pending';
213
+ /** Error message if status is 'error' */
214
+ error?: string;
215
+ }
216
+ /**
217
+ * Filesystem provider interface
218
+ */
219
+ export interface IFilesystemProvider {
220
+ /** Provider type */
221
+ readonly type: FilesystemProviderType;
222
+ /** Initialize the filesystem */
223
+ initialize(config?: FilesystemConfig): Promise<void>;
224
+ /** Check if filesystem is initialized */
225
+ isInitialized(): boolean;
226
+ /** Close/cleanup the filesystem */
227
+ close(): Promise<void>;
228
+ /** Read file contents */
229
+ readFile(path: string): Promise<Buffer | string>;
230
+ /** Write file contents */
231
+ writeFile(path: string, data: Buffer | string): Promise<void>;
232
+ /** Append to file */
233
+ appendFile(path: string, data: Buffer | string): Promise<void>;
234
+ /** Check if file/directory exists */
235
+ exists(path: string): Promise<boolean>;
236
+ /** Get file/directory statistics */
237
+ stat(path: string): Promise<FileStats>;
238
+ /** Read directory contents */
239
+ readdir(path: string): Promise<DirectoryEntry[]>;
240
+ /** Create directory */
241
+ mkdir(path: string, recursive?: boolean): Promise<void>;
242
+ /** Remove file or directory */
243
+ unlink(path: string, recursive?: boolean): Promise<void>;
244
+ /** Copy file or directory */
245
+ copy(src: string, dest: string): Promise<void>;
246
+ /** Move/rename file or directory */
247
+ move(src: string, dest: string): Promise<void>;
248
+ /** Get value by key */
249
+ get(key: string): Promise<unknown>;
250
+ /** Set value for key */
251
+ set(key: string, value: unknown): Promise<void>;
252
+ /** Delete key */
253
+ delete(key: string): Promise<void>;
254
+ /** List all keys (optionally with prefix) */
255
+ listKeys(prefix?: string): Promise<string[]>;
256
+ /** Check if key exists */
257
+ hasKey(key: string): Promise<boolean>;
258
+ /** Record a tool call */
259
+ recordToolCall(metadata: ToolCallMetadata): Promise<void>;
260
+ /** Get tool call history (optionally filtered) */
261
+ getToolCallHistory(filter?: {
262
+ tool?: string;
263
+ status?: ToolCallMetadata['status'];
264
+ since?: number;
265
+ until?: number;
266
+ limit?: number;
267
+ }): Promise<ToolCallMetadata[]>;
268
+ }
269
+ /**
270
+ * Supported sandbox provider types
271
+ */
272
+ export type SandboxProviderType = 'e2b' | 'daytona' | 'modal';
273
+ /**
274
+ * Sandbox provider configuration
275
+ */
276
+ export interface SandboxConfig {
277
+ fromSandboxId?: string;
278
+ /** Provider-specific configuration */
279
+ provider?: SandboxProviderType;
280
+ /** API key for the sandbox provider */
281
+ apiKey?: string;
282
+ /** Sandbox template ID (for E2B) or workspace ID (for Daytona) */
283
+ templateId?: string;
284
+ /** Base URL for the provider (if applicable) */
285
+ baseURL?: string;
286
+ /** Environment variables to set in the sandbox */
287
+ env?: Record<string, string>;
288
+ /** Timeout in milliseconds */
289
+ timeout?: number;
290
+ /** Additional provider-specific options */
291
+ [key: string]: unknown;
292
+ }
293
+ /**
294
+ * Command execution result
295
+ */
296
+ export interface CommandResult {
297
+ /** Exit code */
298
+ exitCode: number;
299
+ /** Standard output */
300
+ stdout: string;
301
+ /** Standard error */
302
+ stderr: string;
303
+ /** Execution time in milliseconds */
304
+ executionTime?: number;
305
+ }
306
+ /**
307
+ * Code execution result (for interpreted code like Python, JavaScript, etc.)
308
+ */
309
+ export interface CodeExecutionResult {
310
+ /** Text representation of the main result */
311
+ text?: string;
312
+ /** All results from the execution (including charts, tables, etc.) */
313
+ results: Array<{
314
+ text?: string;
315
+ html?: string;
316
+ markdown?: string;
317
+ [key: string]: unknown;
318
+ }>;
319
+ /** Logs printed to stdout during execution */
320
+ stdout: string[];
321
+ /** Logs printed to stderr during execution */
322
+ stderr: string[];
323
+ /** Error information if execution failed */
324
+ error?: {
325
+ name: string;
326
+ value: string;
327
+ traceback: string;
328
+ };
329
+ /** Execution time in milliseconds */
330
+ executionTime?: number;
331
+ }
332
+ /**
333
+ * Sandbox execution result
334
+ */
335
+ export interface SandboxExecutionResult {
336
+ /** Command execution result */
337
+ result: CommandResult;
338
+ /** Sandbox ID */
339
+ sandboxId: string;
340
+ /** Provider type */
341
+ provider: SandboxProviderType;
342
+ /** Additional metadata */
343
+ metadata?: {
344
+ [key: string]: unknown;
345
+ };
346
+ }
347
+ /**
348
+ * Sandbox information
349
+ */
350
+ export interface SandboxInfo {
351
+ /** Sandbox ID */
352
+ sandboxId: string;
353
+ /** Provider type */
354
+ provider: SandboxProviderType;
355
+ /** Whether the sandbox is running */
356
+ isRunning: boolean;
357
+ /** Whether the sandbox is initialized */
358
+ isInitialized: boolean;
359
+ /** Creation timestamp (Unix timestamp in milliseconds) */
360
+ createdAt?: Date | string | number;
361
+ /** Additional provider-specific information */
362
+ metadata?: {
363
+ [key: string]: any;
364
+ };
365
+ /** Sandbox raw info from the provider*/
366
+ info?: any;
367
+ }
368
+ /**
369
+ * Sandbox provider interface
370
+ */
371
+ export interface ISandboxProvider {
372
+ /** Provider type */
373
+ readonly type: SandboxProviderType;
374
+ /** Get the client */
375
+ getClient(): any;
376
+ /** Initialize/create a sandbox (or connect to existing if fromSandboxId is provided) */
377
+ initialize(config?: SandboxConfig): Promise<void>;
378
+ /** Connect to an existing sandbox by ID */
379
+ fromSandbox(sandboxId: string, config?: SandboxConfig): Promise<any>;
380
+ /** Check if sandbox is initialized */
381
+ isInitialized(): boolean;
382
+ /** Close/cleanup the sandbox */
383
+ close(): Promise<void>;
384
+ /** Get sandbox ID */
385
+ getSandboxId(): string | null;
386
+ /** Execute a command in the sandbox */
387
+ executeCommand(command: string, options?: {
388
+ cwd?: string;
389
+ env?: Record<string, string>;
390
+ timeout?: number;
391
+ }): Promise<CommandResult>;
392
+ /** Run code (e.g., Python, JavaScript) in the sandbox */
393
+ runCode(code: string, options?: {
394
+ language?: string;
395
+ env?: Record<string, string>;
396
+ timeout?: number;
397
+ onStdout?: (data: string) => void;
398
+ onStderr?: (data: string) => void;
399
+ }): Promise<CodeExecutionResult>;
400
+ /** Upload a file to the sandbox */
401
+ uploadFile(localPath: string, remotePath: string): Promise<void>;
402
+ /** Download a file from the sandbox */
403
+ downloadFile(remotePath: string, localPath: string): Promise<void>;
404
+ /** Read a file from the sandbox */
405
+ readFile(path: string): Promise<string>;
406
+ /** Write a file to the sandbox */
407
+ writeFile(path: string, content: string): Promise<void>;
408
+ /** List files in a directory */
409
+ listFiles(path: string): Promise<string[]>;
410
+ /** Check if a file exists */
411
+ fileExists(path: string): Promise<boolean>;
412
+ /** Delete a file */
413
+ deleteFile(path: string): Promise<void>;
414
+ /** Get sandbox status */
415
+ getStatus(): Promise<{
416
+ isRunning: boolean;
417
+ createdAt?: number;
418
+ [key: string]: unknown;
419
+ }>;
420
+ /** Get detailed sandbox information */
421
+ getInfo(sandboxId?: string): Promise<SandboxInfo>;
422
+ }
423
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,IAAI,CAAC;AAExC;;GAEG;AACH,MAAM,MAAM,SAAS,GAAG,cAAc,GAAG,QAAQ,GAAG,OAAO,GAAG,UAAU,CAAC;AAEzE;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B,gDAAgD;IAChD,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,8BAA8B;IAC9B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,uCAAuC;IACvC,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,iCAAiC;IACjC,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,wBAAwB;IACxB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,sCAAsC;IACtC,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACjC,gDAAgD;IAChD,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,2CAA2C;IAC3C,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB;AAED;;GAEG;AACH,MAAM,WAAW,QAAQ;IACvB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;CACd;AAED;;GAEG;AACH,MAAM,WAAW,QAAQ;IACvB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,GAAG,UAAU,GAAG,WAAW,GAAG,MAAM,GAAG,GAAG,CAAC;IACvD,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;CACnB;AAED;;GAEG;AACH,MAAM,MAAM,cAAc,GAAG,MAAM,GAAG,KAAK,CAAC,Q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IAAI,CAAC,CAAC;IACxC,yBAAyB;IACzB,SAAS,IAAI,OAAO,CAAC;QACnB,SAAS,EAAE,OAAO,CAAC;QACnB,SAAS,CAAC,EAAE,MAAM,CAAC;QACnB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;KACxB,CAAC,CAAC;IACH,uCAAuC;IACvC,OAAO,CAAC,SAAS,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC;CACnD"}
package/dist/types.js ADDED
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
@@ -0,0 +1,103 @@
1
+ /**
2
+ * Represents a code block extracted from markdown
3
+ */
4
+ export interface CodeBlock {
5
+ /** The language identifier (e.g., 'typescript', 'bash', 'python') */
6
+ language: string;
7
+ /** The code content without the markdown fences */
8
+ code: string;
9
+ /** The full match including fences (for reference) */
10
+ fullMatch?: string;
11
+ }
12
+ /**
13
+ * Options for extracting code blocks
14
+ */
15
+ export interface ExtractCodeBlocksOptions {
16
+ /** If true, only extract code blocks with the specified language(s) */
17
+ languages?: string[];
18
+ /** If true, return only the code content without language info */
19
+ codeOnly?: boolean;
20
+ /** If true, include the full match in the result */
21
+ includeFullMatch?: boolean;
22
+ /** Custom wrapper for code blocks */
23
+ customWrapper?: {
24
+ start: string;
25
+ end: string;
26
+ };
27
+ }
28
+ /**
29
+ * Extracts code blocks from markdown text.
30
+ * Handles multiple code blocks and returns an array of extracted blocks.
31
+ *
32
+ * @param text - The markdown text containing code blocks
33
+ * @param options - Optional configuration for extraction
34
+ * @returns Array of code blocks or code strings (if codeOnly is true)
35
+ *
36
+ * @example
37
+ * ```typescript
38
+ * const markdown = `
39
+ * Here's some code:
40
+ * \`\`\`typescript
41
+ * const x = 1;
42
+ * \`\`\`
43
+ *
44
+ * And a command:
45
+ * \`\`\`bash
46
+ * npm install
47
+ * \`\`\`
48
+ * `;
49
+ *
50
+ * const blocks = extractCodeBlocks(markdown);
51
+ * // Returns:
52
+ * // [
53
+ * // { language: 'typescript', code: 'const x = 1;' },
54
+ * // { language: 'bash', code: 'npm install' }
55
+ * // ]
56
+ *
57
+ * const typescriptOnly = extractCodeBlocks(markdown, { languages: ['typescript'] });
58
+ * const codeStrings = extractCodeBlocks(markdown, { codeOnly: true });
59
+ *
60
+ * // Using custom wrapper
61
+ * const customMarkdown = '<code>typescript\nconst x = 1;\n</code>';
62
+ * const customBlocks = extractCodeBlocks(customMarkdown, {
63
+ * customWrapper: { start: '<code>', end: '</code>' }
64
+ * });
65
+ * ```
66
+ */
67
+ export declare function extractCodeBlocks(text: string, options?: ExtractCodeBlocksOptions): CodeBlock[] | string[];
68
+ /**
69
+ * Extracts a single code block from markdown text.
70
+ * Returns the first matching code block, or null if none found.
71
+ *
72
+ * @param text - The markdown text containing code blocks
73
+ * @param language - Optional language filter (case-insensitive)
74
+ * @returns The first matching code block, or null
75
+ *
76
+ * @example
77
+ * ```typescript
78
+ * const markdown = '```bash\nnpm install\n```';
79
+ * const block = extractCodeBlock(markdown);
80
+ * // Returns: { language: 'bash', code: 'npm install' }
81
+ *
82
+ * const tsBlock = extractCodeBlock(markdown, 'typescript');
83
+ * // Returns: null (no typescript block found)
84
+ * ```
85
+ */
86
+ export declare function extractCodeBlock(text: string, language?: string): CodeBlock | null;
87
+ /**
88
+ * Extracts code content from a single code block (without language info).
89
+ * Returns the code string, or null if no code block found.
90
+ *
91
+ * @param text - The markdown text containing code blocks
92
+ * @param language - Optional language filter (case-insensitive)
93
+ * @returns The code content as a string, or null
94
+ *
95
+ * @example
96
+ * ```typescript
97
+ * const markdown = '```bash\nnpm install\n```';
98
+ * const code = extractCode(markdown);
99
+ * // Returns: 'npm install'
100
+ * ```
101
+ */
102
+ export declare function extractCode(text: string, language?: string): string | null;
103
+ //# sourceMappingURL=code-extractor.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"code-extractor.d.ts","sourceRoot":"","sources":["../../src/utils/code-extractor.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,WAAW,SAAS;IACxB,qEAAqE;IACrE,QAAQ,EAAE,MAAM,CAAC;IACjB,mDAAmD;IACnD,IAAI,EAAE,MAAM,CAAC;IACb,sDAAsD;IACtD,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED;;GAEG;AACH,MAAM,WAAW,wBAAwB;IACvC,uEAAuE;IACvE,SAAS,CAAC,EAAE,MAAM,EAAE,CAAC;IACrB,kEAAkE;IAClE,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,oDAAoD;IACpD,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,qCAAqC;IACrC,aAAa,CAAC,EAAE;QACd,KAAK,EAAE,MAAM,CAAC;QACd,GAAG,EAAE,MAAM,CAAC;KACb,CAAC;CACH;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG;AACH,wBAAgB,iBAAiB,CAC/B,IAAI,EAAE,MAAM,EACZ,OAAO,GAAE,wBAA6B,GACrC,SAAS,EAAE,GAAG,MAAM,EAAE,CAqExB;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,gBAAgB,CAC9B,IAAI,EAAE,MAAM,EACZ,QAAQ,CAAC,EAAE,MAAM,GAChB,SAAS,GAAG,IAAI,CAOlB;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,WAAW,CACzB,IAAI,EAAE,MAAM,EACZ,QAAQ,CAAC,EAAE,MAAM,GAChB,MAAM,GAAG,IAAI,CAGf"}
@@ -0,0 +1,133 @@
1
+ /**
2
+ * Extracts code blocks from markdown text.
3
+ * Handles multiple code blocks and returns an array of extracted blocks.
4
+ *
5
+ * @param text - The markdown text containing code blocks
6
+ * @param options - Optional configuration for extraction
7
+ * @returns Array of code blocks or code strings (if codeOnly is true)
8
+ *
9
+ * @example
10
+ * ```typescript
11
+ * const markdown = `
12
+ * Here's some code:
13
+ * \`\`\`typescript
14
+ * const x = 1;
15
+ * \`\`\`
16
+ *
17
+ * And a command:
18
+ * \`\`\`bash
19
+ * npm install
20
+ * \`\`\`
21
+ * `;
22
+ *
23
+ * const blocks = extractCodeBlocks(markdown);
24
+ * // Returns:
25
+ * // [
26
+ * // { language: 'typescript', code: 'const x = 1;' },
27
+ * // { language: 'bash', code: 'npm install' }
28
+ * // ]
29
+ *
30
+ * const typescriptOnly = extractCodeBlocks(markdown, { languages: ['typescript'] });
31
+ * const codeStrings = extractCodeBlocks(markdown, { codeOnly: true });
32
+ *
33
+ * // Using custom wrapper
34
+ * const customMarkdown = '<code>typescript\nconst x = 1;\n</code>';
35
+ * const customBlocks = extractCodeBlocks(customMarkdown, {
36
+ * customWrapper: { start: '<code>', end: '</code>' }
37
+ * });
38
+ * ```
39
+ */
40
+ export function extractCodeBlocks(text, options = {}) {
41
+ const { languages, codeOnly = false, includeFullMatch = false, customWrapper, } = options;
42
+ // Determine the wrapper strings to use
43
+ const startWrapper = customWrapper?.start ?? '```';
44
+ const endWrapper = customWrapper?.end ?? '```';
45
+ // Escape special regex characters in the wrapper strings
46
+ const escapeRegex = (str) => {
47
+ return str.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
48
+ };
49
+ const escapedStart = escapeRegex(startWrapper);
50
+ const escapedEnd = escapeRegex(endWrapper);
51
+ // Build regex pattern: startWrapper language?\n?code\nendWrapper
52
+ // Handles:
53
+ // - Optional language identifier (with optional whitespace)
54
+ // - Code blocks with or without newline after language
55
+ // - Empty code blocks
56
+ // - Code blocks without language
57
+ // - Custom wrappers
58
+ const codeBlockRegex = new RegExp(`${escapedStart}(\\w+)?\\s*\\n?([\\s\\S]*?)${escapedEnd}`, 'g');
59
+ const blocks = [];
60
+ let match;
61
+ // Reset regex lastIndex to ensure we start from the beginning
62
+ codeBlockRegex.lastIndex = 0;
63
+ while ((match = codeBlockRegex.exec(text)) !== null) {
64
+ const language = match[1] || '';
65
+ const code = match[2]?.trim() || '';
66
+ // Filter by language if specified
67
+ if (languages && languages.length > 0) {
68
+ const normalizedLanguage = language.toLowerCase();
69
+ const normalizedLanguages = languages.map((lang) => lang.toLowerCase());
70
+ if (!normalizedLanguages.includes(normalizedLanguage)) {
71
+ continue;
72
+ }
73
+ }
74
+ const codeBlock = {
75
+ language,
76
+ code,
77
+ };
78
+ if (includeFullMatch) {
79
+ codeBlock.fullMatch = match[0];
80
+ }
81
+ blocks.push(codeBlock);
82
+ }
83
+ // Return code strings only if requested
84
+ if (codeOnly) {
85
+ return blocks.map((block) => block.code);
86
+ }
87
+ return blocks;
88
+ }
89
+ /**
90
+ * Extracts a single code block from markdown text.
91
+ * Returns the first matching code block, or null if none found.
92
+ *
93
+ * @param text - The markdown text containing code blocks
94
+ * @param language - Optional language filter (case-insensitive)
95
+ * @returns The first matching code block, or null
96
+ *
97
+ * @example
98
+ * ```typescript
99
+ * const markdown = '```bash\nnpm install\n```';
100
+ * const block = extractCodeBlock(markdown);
101
+ * // Returns: { language: 'bash', code: 'npm install' }
102
+ *
103
+ * const tsBlock = extractCodeBlock(markdown, 'typescript');
104
+ * // Returns: null (no typescript block found)
105
+ * ```
106
+ */
107
+ export function extractCodeBlock(text, language) {
108
+ const options = language
109
+ ? { languages: [language] }
110
+ : {};
111
+ const blocks = extractCodeBlocks(text, options);
112
+ return blocks.length > 0 ? blocks[0] : null;
113
+ }
114
+ /**
115
+ * Extracts code content from a single code block (without language info).
116
+ * Returns the code string, or null if no code block found.
117
+ *
118
+ * @param text - The markdown text containing code blocks
119
+ * @param language - Optional language filter (case-insensitive)
120
+ * @returns The code content as a string, or null
121
+ *
122
+ * @example
123
+ * ```typescript
124
+ * const markdown = '```bash\nnpm install\n```';
125
+ * const code = extractCode(markdown);
126
+ * // Returns: 'npm install'
127
+ * ```
128
+ */
129
+ export function extractCode(text, language) {
130
+ const block = extractCodeBlock(text, language);
131
+ return block ? block.code : null;
132
+ }
133
+ //# sourceMappingURL=code-extractor.js.map