@github/copilot-sdk 0.1.33-unstable.1 → 0.2.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,616 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var session_exports = {};
20
+ __export(session_exports, {
21
+ CopilotSession: () => CopilotSession,
22
+ NO_RESULT_PERMISSION_V2_ERROR: () => NO_RESULT_PERMISSION_V2_ERROR
23
+ });
24
+ module.exports = __toCommonJS(session_exports);
25
+ var import_node = require("vscode-jsonrpc/node.js");
26
+ var import_rpc = require("./generated/rpc.js");
27
+ var import_telemetry = require("./telemetry.js");
28
+ const NO_RESULT_PERMISSION_V2_ERROR = "Permission handlers cannot return 'no-result' when connected to a protocol v2 server.";
29
+ class CopilotSession {
30
+ /**
31
+ * Creates a new CopilotSession instance.
32
+ *
33
+ * @param sessionId - The unique identifier for this session
34
+ * @param connection - The JSON-RPC message connection to the Copilot CLI
35
+ * @param workspacePath - Path to the session workspace directory (when infinite sessions enabled)
36
+ * @param traceContextProvider - Optional callback to get W3C Trace Context for outbound RPCs
37
+ * @internal This constructor is internal. Use {@link CopilotClient.createSession} to create sessions.
38
+ */
39
+ constructor(sessionId, connection, _workspacePath, traceContextProvider) {
40
+ this.sessionId = sessionId;
41
+ this.connection = connection;
42
+ this._workspacePath = _workspacePath;
43
+ this.traceContextProvider = traceContextProvider;
44
+ }
45
+ eventHandlers = /* @__PURE__ */ new Set();
46
+ typedEventHandlers = /* @__PURE__ */ new Map();
47
+ toolHandlers = /* @__PURE__ */ new Map();
48
+ permissionHandler;
49
+ userInputHandler;
50
+ hooks;
51
+ transformCallbacks;
52
+ _rpc = null;
53
+ traceContextProvider;
54
+ /**
55
+ * Typed session-scoped RPC methods.
56
+ */
57
+ get rpc() {
58
+ if (!this._rpc) {
59
+ this._rpc = (0, import_rpc.createSessionRpc)(this.connection, this.sessionId);
60
+ }
61
+ return this._rpc;
62
+ }
63
+ /**
64
+ * Path to the session workspace directory when infinite sessions are enabled.
65
+ * Contains checkpoints/, plan.md, and files/ subdirectories.
66
+ * Undefined if infinite sessions are disabled.
67
+ */
68
+ get workspacePath() {
69
+ return this._workspacePath;
70
+ }
71
+ /**
72
+ * Sends a message to this session and waits for the response.
73
+ *
74
+ * The message is processed asynchronously. Subscribe to events via {@link on}
75
+ * to receive streaming responses and other session events.
76
+ *
77
+ * @param options - The message options including the prompt and optional attachments
78
+ * @returns A promise that resolves with the message ID of the response
79
+ * @throws Error if the session has been disconnected or the connection fails
80
+ *
81
+ * @example
82
+ * ```typescript
83
+ * const messageId = await session.send({
84
+ * prompt: "Explain this code",
85
+ * attachments: [{ type: "file", path: "./src/index.ts" }]
86
+ * });
87
+ * ```
88
+ */
89
+ async send(options) {
90
+ const response = await this.connection.sendRequest("session.send", {
91
+ ...await (0, import_telemetry.getTraceContext)(this.traceContextProvider),
92
+ sessionId: this.sessionId,
93
+ prompt: options.prompt,
94
+ attachments: options.attachments,
95
+ mode: options.mode
96
+ });
97
+ return response.messageId;
98
+ }
99
+ /**
100
+ * Sends a message to this session and waits until the session becomes idle.
101
+ *
102
+ * This is a convenience method that combines {@link send} with waiting for
103
+ * the `session.idle` event. Use this when you want to block until the
104
+ * assistant has finished processing the message.
105
+ *
106
+ * Events are still delivered to handlers registered via {@link on} while waiting.
107
+ *
108
+ * @param options - The message options including the prompt and optional attachments
109
+ * @param timeout - Timeout in milliseconds (default: 60000). Controls how long to wait; does not abort in-flight agent work.
110
+ * @returns A promise that resolves with the final assistant message when the session becomes idle,
111
+ * or undefined if no assistant message was received
112
+ * @throws Error if the timeout is reached before the session becomes idle
113
+ * @throws Error if the session has been disconnected or the connection fails
114
+ *
115
+ * @example
116
+ * ```typescript
117
+ * // Send and wait for completion with default 60s timeout
118
+ * const response = await session.sendAndWait({ prompt: "What is 2+2?" });
119
+ * console.log(response?.data.content); // "4"
120
+ * ```
121
+ */
122
+ async sendAndWait(options, timeout) {
123
+ const effectiveTimeout = timeout ?? 6e4;
124
+ let resolveIdle;
125
+ let rejectWithError;
126
+ const idlePromise = new Promise((resolve, reject) => {
127
+ resolveIdle = resolve;
128
+ rejectWithError = reject;
129
+ });
130
+ let lastAssistantMessage;
131
+ const unsubscribe = this.on((event) => {
132
+ if (event.type === "assistant.message") {
133
+ lastAssistantMessage = event;
134
+ } else if (event.type === "session.idle") {
135
+ resolveIdle();
136
+ } else if (event.type === "session.error") {
137
+ const error = new Error(event.data.message);
138
+ error.stack = event.data.stack;
139
+ rejectWithError(error);
140
+ }
141
+ });
142
+ let timeoutId;
143
+ try {
144
+ await this.send(options);
145
+ const timeoutPromise = new Promise((_, reject) => {
146
+ timeoutId = setTimeout(
147
+ () => reject(
148
+ new Error(
149
+ `Timeout after ${effectiveTimeout}ms waiting for session.idle`
150
+ )
151
+ ),
152
+ effectiveTimeout
153
+ );
154
+ });
155
+ await Promise.race([idlePromise, timeoutPromise]);
156
+ return lastAssistantMessage;
157
+ } finally {
158
+ if (timeoutId !== void 0) {
159
+ clearTimeout(timeoutId);
160
+ }
161
+ unsubscribe();
162
+ }
163
+ }
164
+ on(eventTypeOrHandler, handler) {
165
+ if (typeof eventTypeOrHandler === "string" && handler) {
166
+ const eventType = eventTypeOrHandler;
167
+ if (!this.typedEventHandlers.has(eventType)) {
168
+ this.typedEventHandlers.set(eventType, /* @__PURE__ */ new Set());
169
+ }
170
+ const storedHandler = handler;
171
+ this.typedEventHandlers.get(eventType).add(storedHandler);
172
+ return () => {
173
+ const handlers = this.typedEventHandlers.get(eventType);
174
+ if (handlers) {
175
+ handlers.delete(storedHandler);
176
+ }
177
+ };
178
+ }
179
+ const wildcardHandler = eventTypeOrHandler;
180
+ this.eventHandlers.add(wildcardHandler);
181
+ return () => {
182
+ this.eventHandlers.delete(wildcardHandler);
183
+ };
184
+ }
185
+ /**
186
+ * Dispatches an event to all registered handlers.
187
+ * Also handles broadcast request events internally (external tool calls, permissions).
188
+ *
189
+ * @param event - The session event to dispatch
190
+ * @internal This method is for internal use by the SDK.
191
+ */
192
+ _dispatchEvent(event) {
193
+ this._handleBroadcastEvent(event);
194
+ const typedHandlers = this.typedEventHandlers.get(event.type);
195
+ if (typedHandlers) {
196
+ for (const handler of typedHandlers) {
197
+ try {
198
+ handler(event);
199
+ } catch (_error) {
200
+ }
201
+ }
202
+ }
203
+ for (const handler of this.eventHandlers) {
204
+ try {
205
+ handler(event);
206
+ } catch (_error) {
207
+ }
208
+ }
209
+ }
210
+ /**
211
+ * Handles broadcast request events by executing local handlers and responding via RPC.
212
+ * Handlers are dispatched as fire-and-forget — rejections propagate as unhandled promise
213
+ * rejections, consistent with standard EventEmitter / event handler semantics.
214
+ * @internal
215
+ */
216
+ _handleBroadcastEvent(event) {
217
+ if (event.type === "external_tool.requested") {
218
+ const { requestId, toolName } = event.data;
219
+ const args = event.data.arguments;
220
+ const toolCallId = event.data.toolCallId;
221
+ const traceparent = event.data.traceparent;
222
+ const tracestate = event.data.tracestate;
223
+ const handler = this.toolHandlers.get(toolName);
224
+ if (handler) {
225
+ void this._executeToolAndRespond(
226
+ requestId,
227
+ toolName,
228
+ toolCallId,
229
+ args,
230
+ handler,
231
+ traceparent,
232
+ tracestate
233
+ );
234
+ }
235
+ } else if (event.type === "permission.requested") {
236
+ const { requestId, permissionRequest } = event.data;
237
+ if (this.permissionHandler) {
238
+ void this._executePermissionAndRespond(requestId, permissionRequest);
239
+ }
240
+ }
241
+ }
242
+ /**
243
+ * Executes a tool handler and sends the result back via RPC.
244
+ * @internal
245
+ */
246
+ async _executeToolAndRespond(requestId, toolName, toolCallId, args, handler, traceparent, tracestate) {
247
+ try {
248
+ const rawResult = await handler(args, {
249
+ sessionId: this.sessionId,
250
+ toolCallId,
251
+ toolName,
252
+ arguments: args,
253
+ traceparent,
254
+ tracestate
255
+ });
256
+ let result;
257
+ if (rawResult == null) {
258
+ result = "";
259
+ } else if (typeof rawResult === "string") {
260
+ result = rawResult;
261
+ } else {
262
+ result = JSON.stringify(rawResult);
263
+ }
264
+ await this.rpc.tools.handlePendingToolCall({ requestId, result });
265
+ } catch (error) {
266
+ const message = error instanceof Error ? error.message : String(error);
267
+ try {
268
+ await this.rpc.tools.handlePendingToolCall({ requestId, error: message });
269
+ } catch (rpcError) {
270
+ if (!(rpcError instanceof import_node.ConnectionError || rpcError instanceof import_node.ResponseError)) {
271
+ throw rpcError;
272
+ }
273
+ }
274
+ }
275
+ }
276
+ /**
277
+ * Executes a permission handler and sends the result back via RPC.
278
+ * @internal
279
+ */
280
+ async _executePermissionAndRespond(requestId, permissionRequest) {
281
+ try {
282
+ const result = await this.permissionHandler(permissionRequest, {
283
+ sessionId: this.sessionId
284
+ });
285
+ if (result.kind === "no-result") {
286
+ return;
287
+ }
288
+ await this.rpc.permissions.handlePendingPermissionRequest({ requestId, result });
289
+ } catch (_error) {
290
+ try {
291
+ await this.rpc.permissions.handlePendingPermissionRequest({
292
+ requestId,
293
+ result: {
294
+ kind: "denied-no-approval-rule-and-could-not-request-from-user"
295
+ }
296
+ });
297
+ } catch (rpcError) {
298
+ if (!(rpcError instanceof import_node.ConnectionError || rpcError instanceof import_node.ResponseError)) {
299
+ throw rpcError;
300
+ }
301
+ }
302
+ }
303
+ }
304
+ /**
305
+ * Registers custom tool handlers for this session.
306
+ *
307
+ * Tools allow the assistant to execute custom functions. When the assistant
308
+ * invokes a tool, the corresponding handler is called with the tool arguments.
309
+ *
310
+ * @param tools - An array of tool definitions with their handlers, or undefined to clear all tools
311
+ * @internal This method is typically called internally when creating a session with tools.
312
+ */
313
+ registerTools(tools) {
314
+ this.toolHandlers.clear();
315
+ if (!tools) {
316
+ return;
317
+ }
318
+ for (const tool of tools) {
319
+ this.toolHandlers.set(tool.name, tool.handler);
320
+ }
321
+ }
322
+ /**
323
+ * Retrieves a registered tool handler by name.
324
+ *
325
+ * @param name - The name of the tool to retrieve
326
+ * @returns The tool handler if found, or undefined
327
+ * @internal This method is for internal use by the SDK.
328
+ */
329
+ getToolHandler(name) {
330
+ return this.toolHandlers.get(name);
331
+ }
332
+ /**
333
+ * Registers a handler for permission requests.
334
+ *
335
+ * When the assistant needs permission to perform certain actions (e.g., file operations),
336
+ * this handler is called to approve or deny the request.
337
+ *
338
+ * @param handler - The permission handler function, or undefined to remove the handler
339
+ * @internal This method is typically called internally when creating a session.
340
+ */
341
+ registerPermissionHandler(handler) {
342
+ this.permissionHandler = handler;
343
+ }
344
+ /**
345
+ * Registers a user input handler for ask_user requests.
346
+ *
347
+ * When the agent needs input from the user (via ask_user tool),
348
+ * this handler is called to provide the response.
349
+ *
350
+ * @param handler - The user input handler function, or undefined to remove the handler
351
+ * @internal This method is typically called internally when creating a session.
352
+ */
353
+ registerUserInputHandler(handler) {
354
+ this.userInputHandler = handler;
355
+ }
356
+ /**
357
+ * Registers hook handlers for session lifecycle events.
358
+ *
359
+ * Hooks allow custom logic to be executed at various points during
360
+ * the session lifecycle (before/after tool use, session start/end, etc.).
361
+ *
362
+ * @param hooks - The hook handlers object, or undefined to remove all hooks
363
+ * @internal This method is typically called internally when creating a session.
364
+ */
365
+ registerHooks(hooks) {
366
+ this.hooks = hooks;
367
+ }
368
+ /**
369
+ * Registers transform callbacks for system message sections.
370
+ *
371
+ * @param callbacks - Map of section ID to transform callback, or undefined to clear
372
+ * @internal This method is typically called internally when creating a session.
373
+ */
374
+ registerTransformCallbacks(callbacks) {
375
+ this.transformCallbacks = callbacks;
376
+ }
377
+ /**
378
+ * Handles a systemMessage.transform request from the runtime.
379
+ * Dispatches each section to its registered transform callback.
380
+ *
381
+ * @param sections - Map of section IDs to their current rendered content
382
+ * @returns A promise that resolves with the transformed sections
383
+ * @internal This method is for internal use by the SDK.
384
+ */
385
+ async _handleSystemMessageTransform(sections) {
386
+ const result = {};
387
+ for (const [sectionId, { content }] of Object.entries(sections)) {
388
+ const callback = this.transformCallbacks?.get(sectionId);
389
+ if (callback) {
390
+ try {
391
+ const transformed = await callback(content);
392
+ result[sectionId] = { content: transformed };
393
+ } catch (_error) {
394
+ result[sectionId] = { content };
395
+ }
396
+ } else {
397
+ result[sectionId] = { content };
398
+ }
399
+ }
400
+ return { sections: result };
401
+ }
402
+ /**
403
+ * Handles a permission request in the v2 protocol format (synchronous RPC).
404
+ * Used as a back-compat adapter when connected to a v2 server.
405
+ *
406
+ * @param request - The permission request data from the CLI
407
+ * @returns A promise that resolves with the permission decision
408
+ * @internal This method is for internal use by the SDK.
409
+ */
410
+ async _handlePermissionRequestV2(request) {
411
+ if (!this.permissionHandler) {
412
+ return { kind: "denied-no-approval-rule-and-could-not-request-from-user" };
413
+ }
414
+ try {
415
+ const result = await this.permissionHandler(request, {
416
+ sessionId: this.sessionId
417
+ });
418
+ if (result.kind === "no-result") {
419
+ throw new Error(NO_RESULT_PERMISSION_V2_ERROR);
420
+ }
421
+ return result;
422
+ } catch (error) {
423
+ if (error instanceof Error && error.message === NO_RESULT_PERMISSION_V2_ERROR) {
424
+ throw error;
425
+ }
426
+ return { kind: "denied-no-approval-rule-and-could-not-request-from-user" };
427
+ }
428
+ }
429
+ /**
430
+ * Handles a user input request from the Copilot CLI.
431
+ *
432
+ * @param request - The user input request data from the CLI
433
+ * @returns A promise that resolves with the user's response
434
+ * @internal This method is for internal use by the SDK.
435
+ */
436
+ async _handleUserInputRequest(request) {
437
+ if (!this.userInputHandler) {
438
+ throw new Error("User input requested but no handler registered");
439
+ }
440
+ try {
441
+ const result = await this.userInputHandler(request, {
442
+ sessionId: this.sessionId
443
+ });
444
+ return result;
445
+ } catch (error) {
446
+ throw error;
447
+ }
448
+ }
449
+ /**
450
+ * Handles a hooks invocation from the Copilot CLI.
451
+ *
452
+ * @param hookType - The type of hook being invoked
453
+ * @param input - The input data for the hook
454
+ * @returns A promise that resolves with the hook output, or undefined
455
+ * @internal This method is for internal use by the SDK.
456
+ */
457
+ async _handleHooksInvoke(hookType, input) {
458
+ if (!this.hooks) {
459
+ return void 0;
460
+ }
461
+ const handlerMap = {
462
+ preToolUse: this.hooks.onPreToolUse,
463
+ postToolUse: this.hooks.onPostToolUse,
464
+ userPromptSubmitted: this.hooks.onUserPromptSubmitted,
465
+ sessionStart: this.hooks.onSessionStart,
466
+ sessionEnd: this.hooks.onSessionEnd,
467
+ errorOccurred: this.hooks.onErrorOccurred
468
+ };
469
+ const handler = handlerMap[hookType];
470
+ if (!handler) {
471
+ return void 0;
472
+ }
473
+ try {
474
+ const result = await handler(input, { sessionId: this.sessionId });
475
+ return result;
476
+ } catch (_error) {
477
+ return void 0;
478
+ }
479
+ }
480
+ /**
481
+ * Retrieves all events and messages from this session's history.
482
+ *
483
+ * This returns the complete conversation history including user messages,
484
+ * assistant responses, tool executions, and other session events.
485
+ *
486
+ * @returns A promise that resolves with an array of all session events
487
+ * @throws Error if the session has been disconnected or the connection fails
488
+ *
489
+ * @example
490
+ * ```typescript
491
+ * const events = await session.getMessages();
492
+ * for (const event of events) {
493
+ * if (event.type === "assistant.message") {
494
+ * console.log("Assistant:", event.data.content);
495
+ * }
496
+ * }
497
+ * ```
498
+ */
499
+ async getMessages() {
500
+ const response = await this.connection.sendRequest("session.getMessages", {
501
+ sessionId: this.sessionId
502
+ });
503
+ return response.events;
504
+ }
505
+ /**
506
+ * Disconnects this session and releases all in-memory resources (event handlers,
507
+ * tool handlers, permission handlers).
508
+ *
509
+ * Session state on disk (conversation history, planning state, artifacts) is
510
+ * preserved, so the conversation can be resumed later by calling
511
+ * {@link CopilotClient.resumeSession} with the session ID. To permanently
512
+ * remove all session data including files on disk, use
513
+ * {@link CopilotClient.deleteSession} instead.
514
+ *
515
+ * After calling this method, the session object can no longer be used.
516
+ *
517
+ * @returns A promise that resolves when the session is disconnected
518
+ * @throws Error if the connection fails
519
+ *
520
+ * @example
521
+ * ```typescript
522
+ * // Clean up when done — session can still be resumed later
523
+ * await session.disconnect();
524
+ * ```
525
+ */
526
+ async disconnect() {
527
+ await this.connection.sendRequest("session.destroy", {
528
+ sessionId: this.sessionId
529
+ });
530
+ this.eventHandlers.clear();
531
+ this.typedEventHandlers.clear();
532
+ this.toolHandlers.clear();
533
+ this.permissionHandler = void 0;
534
+ }
535
+ /**
536
+ * @deprecated Use {@link disconnect} instead. This method will be removed in a future release.
537
+ *
538
+ * Disconnects this session and releases all in-memory resources.
539
+ * Session data on disk is preserved for later resumption.
540
+ *
541
+ * @returns A promise that resolves when the session is disconnected
542
+ * @throws Error if the connection fails
543
+ */
544
+ async destroy() {
545
+ return this.disconnect();
546
+ }
547
+ /** Enables `await using session = ...` syntax for automatic cleanup. */
548
+ async [Symbol.asyncDispose]() {
549
+ return this.disconnect();
550
+ }
551
+ /**
552
+ * Aborts the currently processing message in this session.
553
+ *
554
+ * Use this to cancel a long-running request. The session remains valid
555
+ * and can continue to be used for new messages.
556
+ *
557
+ * @returns A promise that resolves when the abort request is acknowledged
558
+ * @throws Error if the session has been disconnected or the connection fails
559
+ *
560
+ * @example
561
+ * ```typescript
562
+ * // Start a long-running request
563
+ * const messagePromise = session.send({ prompt: "Write a very long story..." });
564
+ *
565
+ * // Abort after 5 seconds
566
+ * setTimeout(async () => {
567
+ * await session.abort();
568
+ * }, 5000);
569
+ * ```
570
+ */
571
+ async abort() {
572
+ await this.connection.sendRequest("session.abort", {
573
+ sessionId: this.sessionId
574
+ });
575
+ }
576
+ /**
577
+ * Change the model for this session.
578
+ * The new model takes effect for the next message. Conversation history is preserved.
579
+ *
580
+ * @param model - Model ID to switch to
581
+ * @param options - Optional settings for the new model
582
+ *
583
+ * @example
584
+ * ```typescript
585
+ * await session.setModel("gpt-4.1");
586
+ * await session.setModel("claude-sonnet-4.6", { reasoningEffort: "high" });
587
+ * ```
588
+ */
589
+ async setModel(model, options) {
590
+ await this.rpc.model.switchTo({ modelId: model, ...options });
591
+ }
592
+ /**
593
+ * Log a message to the session timeline.
594
+ * The message appears in the session event stream and is visible to SDK consumers
595
+ * and (for non-ephemeral messages) persisted to the session event log on disk.
596
+ *
597
+ * @param message - Human-readable message text
598
+ * @param options - Optional log level and ephemeral flag
599
+ *
600
+ * @example
601
+ * ```typescript
602
+ * await session.log("Processing started");
603
+ * await session.log("Disk usage high", { level: "warning" });
604
+ * await session.log("Connection failed", { level: "error" });
605
+ * await session.log("Debug info", { ephemeral: true });
606
+ * ```
607
+ */
608
+ async log(message, options) {
609
+ await this.rpc.log({ message, ...options });
610
+ }
611
+ }
612
+ // Annotate the CommonJS export names for ESM import in node:
613
+ 0 && (module.exports = {
614
+ CopilotSession,
615
+ NO_RESULT_PERMISSION_V2_ERROR
616
+ });
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var telemetry_exports = {};
20
+ __export(telemetry_exports, {
21
+ getTraceContext: () => getTraceContext
22
+ });
23
+ module.exports = __toCommonJS(telemetry_exports);
24
+ async function getTraceContext(provider) {
25
+ if (!provider) return {};
26
+ try {
27
+ return await provider() ?? {};
28
+ } catch {
29
+ return {};
30
+ }
31
+ }
32
+ // Annotate the CommonJS export names for ESM import in node:
33
+ 0 && (module.exports = {
34
+ getTraceContext
35
+ });
@@ -0,0 +1,49 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var types_exports = {};
20
+ __export(types_exports, {
21
+ SYSTEM_PROMPT_SECTIONS: () => SYSTEM_PROMPT_SECTIONS,
22
+ approveAll: () => approveAll,
23
+ defineTool: () => defineTool
24
+ });
25
+ module.exports = __toCommonJS(types_exports);
26
+ function defineTool(name, config) {
27
+ return { name, ...config };
28
+ }
29
+ const SYSTEM_PROMPT_SECTIONS = {
30
+ identity: { description: "Agent identity preamble and mode statement" },
31
+ tone: { description: "Response style, conciseness rules, output formatting preferences" },
32
+ tool_efficiency: { description: "Tool usage patterns, parallel calling, batching guidelines" },
33
+ environment_context: { description: "CWD, OS, git root, directory listing, available tools" },
34
+ code_change_rules: { description: "Coding rules, linting/testing, ecosystem tools, style" },
35
+ guidelines: { description: "Tips, behavioral best practices, behavioral guidelines" },
36
+ safety: { description: "Environment limitations, prohibited actions, security policies" },
37
+ tool_instructions: { description: "Per-tool usage instructions" },
38
+ custom_instructions: { description: "Repository and organization custom instructions" },
39
+ last_instructions: {
40
+ description: "End-of-prompt instructions: parallel tool calling, persistence, task completion"
41
+ }
42
+ };
43
+ const approveAll = () => ({ kind: "approved" });
44
+ // Annotate the CommonJS export names for ESM import in node:
45
+ 0 && (module.exports = {
46
+ SYSTEM_PROMPT_SECTIONS,
47
+ approveAll,
48
+ defineTool
49
+ });