@agentknight/sdk 0.9.62 → 0.9.68

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 (28) hide show
  1. package/dist/chunks/{acp-adapter-MBYKOCA2.js → acp-adapter-RZX5SUB3.js} +4 -4
  2. package/dist/chunks/chunk-35OF2ZNS.js +275 -0
  3. package/dist/chunks/chunk-4XT65OSG.js +72 -0
  4. package/dist/chunks/{chunk-A4YCCQ3I.js → chunk-AWVC5NX4.js} +1 -1
  5. package/dist/chunks/chunk-B777YB6E.js +109 -0
  6. package/dist/chunks/{chunk-7CNBPLNE.js → chunk-CFQQOAQV.js} +5 -2
  7. package/dist/chunks/{chunk-P2PH5KMV.js → chunk-DWTXWVIA.js} +6 -0
  8. package/dist/chunks/{chunk-ZNQ2I5EF.js → chunk-EDYVCZIR.js} +11 -132
  9. package/dist/chunks/{chunk-3AMFPDE5.js → chunk-FY4XTWUF.js} +4 -4
  10. package/dist/chunks/{chunk-H4SHMWQ6.js → chunk-IXGVSREH.js} +1 -1
  11. package/dist/chunks/{chunk-SIFCCGXF.js → chunk-LCA2MWOQ.js} +2 -2
  12. package/dist/chunks/{chunk-ALUQLM54.js → chunk-MB3H6HEI.js} +2 -2
  13. package/dist/chunks/{chunk-CHKNC6PD.js → chunk-Q5OUZJCZ.js} +1 -1
  14. package/dist/chunks/{chunk-7OGTK7KB.js → chunk-UHRUQM4D.js} +1 -1
  15. package/dist/chunks/chunk-VIWTNPVC.js +66 -0
  16. package/dist/chunks/chunk-Y6NCJB55.js +302 -0
  17. package/dist/chunks/{claude-adapter-D3JWXMNX.js → claude-adapter-FQSQIYUY.js} +4 -4
  18. package/dist/chunks/{codex-adapter-655KHW7H.js → codex-adapter-TOXSRT2W.js} +4 -4
  19. package/dist/chunks/{copilot-adapter-EZUXHBE3.js → copilot-adapter-KUCX7XQW.js} +56 -148
  20. package/dist/chunks/{managed-agent-adapter-BOJNEJ75.js → managed-agent-adapter-LGBRXDGP.js} +33 -24
  21. package/dist/chunks/{pi-adapter-LAD5GOCP.js → pi-adapter-RXNZSE4F.js} +330 -53
  22. package/dist/configuration.js +5 -5
  23. package/dist/index.js +20 -31
  24. package/dist/runtime.js +2 -2
  25. package/dist/session-analytics-worker.js +7 -5
  26. package/package.json +1 -1
  27. package/dist/chunks/chunk-CM5LVXVL.js +0 -572
  28. package/dist/chunks/chunk-XPHAIOKN.js +0 -64
@@ -1,40 +1,17 @@
1
+ import {
2
+ decodeTimelineImage,
3
+ normalizeImageMimeType,
4
+ splitTimelineImages
5
+ } from "./chunk-4XT65OSG.js";
1
6
  import {
2
7
  CONVERSATION_SOURCE_ID_LIMIT
3
- } from "./chunk-P2PH5KMV.js";
8
+ } from "./chunk-DWTXWVIA.js";
4
9
 
5
10
  // src/conversation-normalizer.ts
6
11
  import { createHash } from "node:crypto";
7
12
  var SUMMARY_LIMIT = 4096;
8
13
  var IDENTIFIER_LIMIT = 256;
9
14
  var TASK_COMPLETE_TOOL_NAME = "task_complete";
10
- var MAX_INLINE_IMAGE_BYTES = 3 * 1024 * 1024;
11
- var MAX_INLINE_IMAGE_MESSAGE_BYTES = 3 * 1024 * 1024;
12
- var MAX_INLINE_IMAGES_PER_MESSAGE = 4;
13
- var SUPPORTED_IMAGE_MIME_TYPES = /* @__PURE__ */ new Set([
14
- "image/gif",
15
- "image/jpeg",
16
- "image/png",
17
- "image/webp"
18
- ]);
19
- function splitToolImages(images) {
20
- const groups = [];
21
- let group = [];
22
- let groupBytes = 0;
23
- for (const image of images) {
24
- const imageBytes = image.attachment.byteLength ?? 0;
25
- if (group.length > 0 && (group.length >= MAX_INLINE_IMAGES_PER_MESSAGE || groupBytes + imageBytes > MAX_INLINE_IMAGE_MESSAGE_BYTES)) {
26
- groups.push(group);
27
- group = [];
28
- groupBytes = 0;
29
- }
30
- group.push(image);
31
- groupBytes += imageBytes;
32
- }
33
- if (group.length > 0) {
34
- groups.push(group);
35
- }
36
- return groups;
37
- }
38
15
  function protocolId(value) {
39
16
  if (value.length <= IDENTIFIER_LIMIT) {
40
17
  return value;
@@ -261,106 +238,15 @@ function projectCitation(source) {
261
238
  name: source.title ?? source.id
262
239
  };
263
240
  }
264
- function normalizeImageMimeType(value) {
265
- return value.toLowerCase() === "image/jpg" ? "image/jpeg" : value.toLowerCase();
266
- }
267
- function hasImageSignature(bytes, mimeType) {
268
- switch (mimeType) {
269
- case "image/jpeg":
270
- return bytes.length >= 3 && bytes[0] === 255 && bytes[1] === 216 && bytes[2] === 255;
271
- case "image/png":
272
- return bytes.length >= 8 && bytes.subarray(0, 8).equals(
273
- Buffer.from([137, 80, 78, 71, 13, 10, 26, 10])
274
- );
275
- case "image/webp":
276
- return bytes.length >= 12 && bytes.subarray(0, 4).toString("ascii") === "RIFF" && bytes.subarray(8, 12).toString("ascii") === "WEBP";
277
- case "image/gif":
278
- return bytes.length >= 6 && (bytes.subarray(0, 6).toString("ascii") === "GIF87a" || bytes.subarray(0, 6).toString("ascii") === "GIF89a");
279
- default:
280
- return false;
281
- }
282
- }
283
- function decodeImageBase64(value, expectedMimeType) {
284
- const dataUrlMatch = /^data:([^;,]+);base64,(.*)$/isu.exec(value);
285
- if (dataUrlMatch !== null && normalizeImageMimeType(dataUrlMatch[1] ?? "") !== expectedMimeType) {
286
- return void 0;
287
- }
288
- const payload = dataUrlMatch?.[2] ?? value;
289
- const normalized = payload.replaceAll("-", "+").replaceAll("_", "/");
290
- if (normalized.length === 0 || normalized.length % 4 === 1 || !/^[A-Za-z0-9+/]*={0,2}$/u.test(normalized)) {
291
- return void 0;
292
- }
293
- const bytes = Buffer.from(normalized, "base64");
294
- return bytes.toString("base64").replace(/=+$/u, "") === normalized.replace(/=+$/u, "") ? bytes : void 0;
295
- }
296
- function projectInlineToolImage(data, mimeTypeValue, name, expectedByteLength, source = "binary-result") {
241
+ function projectInlineToolImage(data, mimeTypeValue, name, source = "binary-result") {
297
242
  const mimeType = normalizeImageMimeType(mimeTypeValue);
298
243
  const metadata = {
299
244
  kind: "image",
300
245
  name: boundedText(name, 1024, "Copilot image"),
301
246
  mimeType: boundedText(mimeType, 256, "application/octet-stream")
302
247
  };
303
- if (!SUPPORTED_IMAGE_MIME_TYPES.has(mimeType)) {
304
- return {
305
- attachment: metadata,
306
- failure: { source, reason: "mime-unsupported", mimeType }
307
- };
308
- }
309
- const bytes = decodeImageBase64(data, mimeType);
310
- if (bytes === void 0) {
311
- return {
312
- attachment: metadata,
313
- failure: { source, reason: "data-invalid", mimeType }
314
- };
315
- }
316
- if (bytes.length === 0) {
317
- return {
318
- attachment: metadata,
319
- failure: { source, reason: "data-empty", mimeType, actualByteLength: 0 }
320
- };
321
- }
322
- if (bytes.length > MAX_INLINE_IMAGE_BYTES) {
323
- return {
324
- attachment: metadata,
325
- failure: {
326
- source,
327
- reason: "data-too-large",
328
- mimeType,
329
- actualByteLength: bytes.length
330
- }
331
- };
332
- }
333
- if (expectedByteLength !== void 0 && bytes.length !== expectedByteLength) {
334
- return {
335
- attachment: metadata,
336
- failure: {
337
- source,
338
- reason: "length-mismatch",
339
- mimeType,
340
- expectedByteLength,
341
- actualByteLength: bytes.length
342
- }
343
- };
344
- }
345
- if (!hasImageSignature(bytes, mimeType)) {
346
- return {
347
- attachment: metadata,
348
- failure: {
349
- source,
350
- reason: "signature-mismatch",
351
- mimeType,
352
- actualByteLength: bytes.length
353
- }
354
- };
355
- }
356
- return {
357
- attachment: {
358
- ...metadata,
359
- data: bytes.toString("base64"),
360
- byteLength: bytes.length,
361
- sha256: createHash("sha256").update(bytes).digest("hex")
362
- }
363
- };
248
+ const image = decodeTimelineImage(data, mimeType, source);
249
+ return "failure" in image ? { attachment: metadata, failure: image.failure } : { attachment: { ...metadata, ...image } };
364
250
  }
365
251
  function projectToolBinaryResult(result, name, assets) {
366
252
  if (result.type !== "image") {
@@ -398,7 +284,6 @@ function projectToolBinaryResult(result, name, assets) {
398
284
  asset.data.data,
399
285
  asset.data.mimeType,
400
286
  result.description ?? asset.data.description ?? name,
401
- void 0,
402
287
  "binary-asset"
403
288
  );
404
289
  const attachment = projected.attachment;
@@ -448,13 +333,7 @@ function projectToolBinaryResult(result, name, assets) {
448
333
  };
449
334
  }
450
335
  function projectToolContentImage(image, name) {
451
- return projectInlineToolImage(
452
- image.data,
453
- image.mimeType,
454
- name,
455
- void 0,
456
- "content"
457
- );
336
+ return projectInlineToolImage(image.data, image.mimeType, name, "content");
458
337
  }
459
338
  function permissionName(kind) {
460
339
  const words = kind.replaceAll("_", " ").replaceAll("-", " ");
@@ -1138,7 +1017,7 @@ var ConversationNormalizer = class {
1138
1017
  toolName
1139
1018
  });
1140
1019
  }
1141
- const imageGroups = splitToolImages(projectedImages);
1020
+ const imageGroups = splitTimelineImages(projectedImages, (image) => image.attachment.byteLength ?? 0);
1142
1021
  return imageGroups.map((imageGroup, groupIndex) => {
1143
1022
  const multipleGroups = imageGroups.length > 1;
1144
1023
  const id = scopedId(
@@ -6,13 +6,13 @@ import {
6
6
  ConversationNormalizer,
7
7
  ConversationToolLifecycles,
8
8
  assistantMessageId
9
- } from "./chunk-ZNQ2I5EF.js";
9
+ } from "./chunk-EDYVCZIR.js";
10
10
  import {
11
11
  isContentfulAssistant
12
- } from "./chunk-H4SHMWQ6.js";
12
+ } from "./chunk-IXGVSREH.js";
13
13
  import {
14
14
  SessionOperationError
15
- } from "./chunk-7OGTK7KB.js";
15
+ } from "./chunk-UHRUQM4D.js";
16
16
  import {
17
17
  IdSchema,
18
18
  SESSION_DIRECTORY_LIST_OPERATION,
@@ -48,7 +48,7 @@ import {
48
48
  WorkbenchReasoningPageSchema,
49
49
  WorkbenchReasoningRequestSchema,
50
50
  isSafeSessionDirectoryPath
51
- } from "./chunk-P2PH5KMV.js";
51
+ } from "./chunk-DWTXWVIA.js";
52
52
 
53
53
  // src/session-image-uploader.ts
54
54
  import { createHash } from "node:crypto";
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  SessionAssistantPreviewSchema,
3
3
  SessionUserPreviewSchema
4
- } from "./chunk-P2PH5KMV.js";
4
+ } from "./chunk-DWTXWVIA.js";
5
5
 
6
6
  // src/assistant-preview.ts
7
7
  function isContentfulAssistant(item) {
@@ -1,10 +1,10 @@
1
1
  import {
2
2
  CODING_AGENT_IDS
3
- } from "./chunk-7CNBPLNE.js";
3
+ } from "./chunk-CFQQOAQV.js";
4
4
  import {
5
5
  BYTES_PER_KIB,
6
6
  LEGACY_SECURE_MESSAGE_MAX_CIPHERTEXT_LENGTH
7
- } from "./chunk-P2PH5KMV.js";
7
+ } from "./chunk-DWTXWVIA.js";
8
8
 
9
9
  // src/agent-selection.ts
10
10
  import { z } from "zod";
@@ -1,14 +1,14 @@
1
1
  import {
2
2
  AgentSessionRenameError,
3
3
  validateSessionName
4
- } from "./chunk-7CNBPLNE.js";
4
+ } from "./chunk-CFQQOAQV.js";
5
5
  import {
6
6
  ConversationItemSchema,
7
7
  GroupChatInfoSchema,
8
8
  GroupChatParticipantSchema,
9
9
  SESSION_TIMELINE_PAGE_SIZE,
10
10
  SessionSummarySchema
11
- } from "./chunk-P2PH5KMV.js";
11
+ } from "./chunk-DWTXWVIA.js";
12
12
 
13
13
  // src/group-chat.ts
14
14
  import { createHash, randomUUID } from "node:crypto";
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  IdSchema
3
- } from "./chunk-P2PH5KMV.js";
3
+ } from "./chunk-DWTXWVIA.js";
4
4
 
5
5
  // src/data-directory.ts
6
6
  import { randomUUID } from "node:crypto";
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  SessionCommunicationDataSchema,
3
3
  WorkbenchOperationStatusSchema
4
- } from "./chunk-P2PH5KMV.js";
4
+ } from "./chunk-DWTXWVIA.js";
5
5
 
6
6
  // src/session-operations.ts
7
7
  import { createHash, randomUUID } from "node:crypto";
@@ -0,0 +1,66 @@
1
+ // src/coding-agent-presentation.ts
2
+ var copilotIcon = '<svg viewBox="0 0 24 24" aria-hidden="true" focusable="false"><path fill="currentColor" d="M23.922 16.992c-.861 1.495-5.859 5.023-11.922 5.023-6.063 0-11.061-3.528-11.922-5.023A.641.641 0 0 1 0 16.736v-2.869a.841.841 0 0 1 .053-.22c.372-.935 1.347-2.292 2.605-2.656.167-.429.414-1.055.644-1.517a10.195 10.195 0 0 1-.052-1.086c0-1.331.282-2.499 1.132-3.368.397-.406.89-.717 1.474-.952 1.399-1.136 3.392-2.093 6.122-2.093 2.731 0 4.767.957 6.166 2.093.584.235 1.077.546 1.474.952.85.869 1.132 2.037 1.132 3.368 0 .368-.014.733-.052 1.086.23.462.477 1.088.644 1.517 1.258.364 2.233 1.721 2.605 2.656a.832.832 0 0 1 .053.22v2.869a.641.641 0 0 1-.078.256ZM12.172 11h-.344a4.323 4.323 0 0 1-.355.508C10.703 12.455 9.555 13 7.965 13c-1.725 0-2.989-.359-3.782-1.259a2.005 2.005 0 0 1-.085-.104L4 11.741v6.585c1.435.779 4.514 2.179 8 2.179 3.486 0 6.565-1.4 8-2.179v-6.585l-.098-.104s-.033.045-.085.104c-.793.9-2.057 1.259-3.782 1.259-1.59 0-2.738-.545-3.508-1.492a4.323 4.323 0 0 1-.355-.508h-.016.016Zm.641-2.935c.136 1.057.403 1.913.878 2.497.442.544 1.134.938 2.344.938 1.573 0 2.292-.337 2.657-.751.384-.435.558-1.15.558-2.361 0-1.14-.243-1.847-.705-2.319-.477-.488-1.319-.862-2.824-1.025-1.487-.161-2.192.138-2.533.529-.269.307-.437.808-.438 1.578v.021c0 .265.021.562.063.893Zm-1.626 0c.042-.331.063-.628.063-.894v-.02c-.001-.77-.169-1.271-.438-1.578-.341-.391-1.046-.69-2.533-.529-1.505.163-2.347.537-2.824 1.025-.462.472-.705 1.179-.705 2.319 0 1.211.175 1.926.558 2.361.365.414 1.084.751 2.657.751 1.21 0 1.902-.394 2.344-.938.475-.584.742-1.44.878-2.497Z"/><path fill="currentColor" d="M14.5 14.25a1 1 0 0 1 1 1v2a1 1 0 0 1-2 0v-2a1 1 0 0 1 1-1Zm-5 0a1 1 0 0 1 1 1v2a1 1 0 0 1-2 0v-2a1 1 0 0 1 1-1Z"/></svg>';
3
+ var piIcon = '<svg viewBox="0 0 16 16" aria-hidden="true" focusable="false" fill="currentColor"><path d="M1 1H11.7692V7.9999H8.17942V11.4999H4.58982V15H1V1ZM4.58982 4.50005V7.9999H8.17942V4.50005H4.58982Z"/><path d="M11.7692 7.46154H15V15H11.7692V7.46154Z"/></svg>';
4
+ var codexIcon = '<svg viewBox="0 0 24 24" aria-hidden="true" focusable="false" fill="currentColor"><path d="M22.282 9.821a5.985 5.985 0 0 0-.516-4.91 6.046 6.046 0 0 0-6.51-2.9A6.065 6.065 0 0 0 4.981 4.18a5.985 5.985 0 0 0-3.998 2.9 6.046 6.046 0 0 0 .743 7.097 5.98 5.98 0 0 0 .51 4.911 6.051 6.051 0 0 0 6.515 2.9A5.985 5.985 0 0 0 13.26 24a6.056 6.056 0 0 0 5.772-4.206 5.99 5.99 0 0 0 3.997-2.9 6.056 6.056 0 0 0-.747-7.073zM13.26 22.43a4.476 4.476 0 0 1-2.876-1.04l.141-.081 4.779-2.758a.795.795 0 0 0 .392-.681v-6.737l2.02 1.168a.071.071 0 0 1 .038.052v5.583a4.504 4.504 0 0 1-4.494 4.494zM3.6 18.304a4.47 4.47 0 0 1-.535-3.014l.142.085 4.783 2.759a.771.771 0 0 0 .78 0l5.843-3.369v2.332a.08.08 0 0 1-.033.062L9.74 19.95a4.5 4.5 0 0 1-6.14-1.646zM2.34 7.896a4.485 4.485 0 0 1 2.366-1.973V11.6a.766.766 0 0 0 .388.676l5.815 3.355-2.02 1.168a.076.076 0 0 1-.071 0l-4.83-2.786A4.504 4.504 0 0 1 2.34 7.872zm16.597 3.855l-5.833-3.387L15.119 7.2a.076.076 0 0 1 .071 0l4.83 2.791a4.494 4.494 0 0 1-.676 8.105v-5.678a.79.79 0 0 0-.407-.667zm2.01-3.023l-.141-.085-4.774-2.782a.776.776 0 0 0-.785 0L9.409 9.23V6.897a.066.066 0 0 1 .028-.061l4.83-2.787a4.5 4.5 0 0 1 6.68 4.66zm-12.64 4.135l-2.02-1.164a.08.08 0 0 1-.038-.057V6.075a4.5 4.5 0 0 1 7.375-3.453l-.142.08L8.704 5.46a.795.795 0 0 0-.393.681zm1.097-2.365l2.602-1.5 2.607 1.5v2.999l-2.597 1.5-2.607-1.5z"/></svg>';
5
+ var claudeIcon = '<svg viewBox="0 0 1200 1200" aria-hidden="true" focusable="false" fill="currentColor"><path d="M 233.959793 800.214905 L 468.644287 668.536987 L 472.590637 657.100647 L 468.644287 650.738403 L 457.208069 650.738403 L 417.986633 648.322144 L 283.892639 644.69812 L 167.597321 639.865845 L 54.926208 633.825623 L 26.577238 627.785339 L 3.3e-05 592.751709 L 2.73832 575.27533 L 26.577238 559.248352 L 60.724873 562.228149 L 136.187973 567.382629 L 249.422867 575.194763 L 331.570496 580.026978 L 453.261841 592.671082 L 472.590637 592.671082 L 475.328857 584.859009 L 468.724915 580.026978 L 463.570557 575.194763 L 346.389313 495.785217 L 219.543671 411.865906 L 153.100723 363.543762 L 117.181267 339.060425 L 99.060455 316.107361 L 91.248367 266.01355 L 123.865784 230.093994 L 167.677887 233.073853 L 178.872513 236.053772 L 223.248367 270.201477 L 318.040283 343.570496 L 441.825592 434.738342 L 459.946411 449.798706 L 467.194672 444.64447 L 468.080597 441.020203 L 459.946411 427.409485 L 392.617493 305.718323 L 320.778564 181.932983 L 288.80542 130.630859 L 280.348999 99.865845 C 277.369171 87.221436 275.194641 76.590698 275.194641 63.624268 L 312.322174 13.20813 L 332.8591 6.604126 L 382.389313 13.20813 L 403.248352 31.328979 L 434.013519 101.71814 L 483.865753 212.537048 L 561.181274 363.221497 L 583.812134 407.919434 L 595.892639 449.315491 L 600.40271 461.959839 L 608.214783 461.959839 L 608.214783 454.711609 L 614.577271 369.825623 L 626.335632 265.61084 L 637.771851 131.516846 L 641.718201 93.745117 L 660.402832 48.483276 L 697.530334 24.000122 L 726.52356 37.852417 L 750.362549 72 L 747.060486 94.067139 L 732.886047 186.201416 L 705.100708 330.52356 L 686.979919 427.167847 L 697.530334 427.167847 L 709.61084 415.087341 L 758.496704 350.174561 L 840.644348 247.490051 L 876.885925 206.738342 L 919.167847 161.71814 L 946.308838 140.29541 L 997.61084 140.29541 L 1035.38269 196.429626 L 1018.469849 254.416199 L 965.637634 321.422852 L 921.825562 378.201538 L 859.006714 462.765259 L 819.785278 530.41626 L 823.409424 535.812073 L 832.75177 534.92627 L 974.657776 504.724915 L 1051.328979 490.872559 L 1142.818848 475.167786 L 1184.214844 494.496582 L 1188.724854 514.147644 L 1172.456421 554.335693 L 1074.604126 578.496765 L 959.838989 601.449829 L 788.939636 641.879272 L 786.845764 643.409485 L 789.261841 646.389343 L 866.255127 653.637634 L 899.194702 655.409424 L 979.812134 655.409424 L 1129.932861 666.604187 L 1169.154419 692.537109 L 1192.671265 724.268677 L 1188.724854 748.429688 L 1128.322144 779.194641 L 1046.818848 759.865845 L 856.590759 714.604126 L 791.355774 698.335754 L 782.335693 698.335754 L 782.335693 703.731567 L 836.69812 756.885986 L 936.322205 846.845581 L 1061.073975 962.81897 L 1067.436279 991.490112 L 1051.409424 1014.120911 L 1034.496704 1011.704712 L 924.885986 929.234924 L 882.604126 892.107544 L 786.845764 811.48999 L 780.483276 811.48999 L 780.483276 819.946289 L 802.550415 852.241699 L 919.087341 1027.409424 L 925.127625 1081.127686 L 916.671204 1098.604126 L 886.469849 1109.154419 L 853.288696 1103.114136 L 785.073914 1007.355835 L 714.684631 899.516785 L 657.906067 802.872498 L 650.979858 806.81897 L 617.476624 1167.704834 L 601.771851 1186.147705 L 565.530212 1200 L 535.328857 1177.046997 L 519.302124 1139.919556 L 535.328857 1066.550537 L 554.657776 970.792053 L 570.362488 894.68457 L 584.536926 800.134277 L 592.993347 768.724976 L 592.429626 766.630859 L 585.503479 767.516968 L 514.22821 865.369263 L 405.825531 1011.865906 L 320.053711 1103.677979 L 299.516815 1111.812256 L 263.919525 1093.369263 L 267.221497 1060.429688 L 287.114136 1031.114136 L 405.825531 880.107361 L 477.422913 786.52356 L 523.651062 732.483276 L 523.328918 724.671265 L 520.590698 724.671265 L 205.288605 929.395935 L 149.154434 936.644409 L 124.993355 914.01355 L 127.973183 876.885986 L 139.409409 864.80542 L 234.201385 799.570435 L 233.879227 799.8927 Z"/></svg>';
6
+ var genericIcon = '<svg viewBox="0 0 24 24" aria-hidden="true" focusable="false"><g fill="none" stroke="currentColor" stroke-width="2"><rect x="4" y="6" width="16" height="14" rx="3"/><path d="M12 2v4M8 15h8"/><path d="M8 10v2m8-2v2"/></g></svg>';
7
+ var presentations = {
8
+ copilot: { name: "GitHub Copilot", icon: copilotIcon },
9
+ pi: { name: "PI", icon: piIcon },
10
+ codex: { name: "Codex", icon: codexIcon },
11
+ claude: { name: "Claude Code", icon: claudeIcon },
12
+ acp: { name: "ACP", icon: genericIcon }
13
+ };
14
+ var fallback = { name: "Agent", icon: genericIcon };
15
+ function codingAgentPresentation(agentId) {
16
+ return Object.hasOwn(presentations, agentId) ? presentations[agentId] : fallback;
17
+ }
18
+
19
+ // src/device-identity.ts
20
+ import { z } from "zod";
21
+ var DeviceIdentitySchema = z.object({
22
+ schemaVersion: z.literal(2),
23
+ machineId: z.uuid(),
24
+ stableDeviceId: z.uuid(),
25
+ machineName: z.string().trim().min(1).max(120),
26
+ createdAt: z.iso.datetime({ offset: true })
27
+ });
28
+
29
+ // src/relay-authorization.ts
30
+ async function relayRequestToken(config) {
31
+ if (config.relayAuthorization === void 0) return config.relayToken;
32
+ const credential = await config.relayAuthorization.getAccessToken();
33
+ if (!Number.isSafeInteger(credential.expiresAt) || credential.expiresAt <= Date.now() || !/^[\x21-\x7e]{1,32768}$/u.test(credential.token)) {
34
+ throw new Error("Relay authorization expired or is invalid. Sign in again.");
35
+ }
36
+ return credential.token;
37
+ }
38
+
39
+ export {
40
+ codingAgentPresentation,
41
+ DeviceIdentitySchema,
42
+ relayRequestToken
43
+ };
44
+ /*!
45
+ * Copilot artwork: https://github.com/primer/octicons
46
+ * MIT License
47
+ * Copyright (c) 2026 GitHub Inc.
48
+ *
49
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
50
+ * of this software and associated documentation files (the "Software"), to deal
51
+ * in the Software without restriction, including without limitation the rights
52
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
53
+ * copies of the Software, and to permit persons to whom the Software is
54
+ * furnished to do so, subject to the following conditions:
55
+ *
56
+ * The above copyright notice and this permission notice shall be included in all
57
+ * copies or substantial portions of the Software.
58
+ *
59
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
60
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
61
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
62
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
63
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
64
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
65
+ * SOFTWARE.
66
+ */
@@ -0,0 +1,302 @@
1
+ import {
2
+ ConversationNormalizer
3
+ } from "./chunk-EDYVCZIR.js";
4
+ import {
5
+ resolveCopilotSessionDirectory
6
+ } from "./chunk-35OF2ZNS.js";
7
+ import {
8
+ isContentfulAssistant
9
+ } from "./chunk-IXGVSREH.js";
10
+ import {
11
+ SessionAnalyticsRequestSchema,
12
+ SessionTimelinePageSchema
13
+ } from "./chunk-DWTXWVIA.js";
14
+
15
+ // src/session-analytics-messages.ts
16
+ import { z } from "zod";
17
+ var AnalyticsEventSchema = z.object({
18
+ id: z.string().min(1).max(1024),
19
+ timestamp: z.iso.datetime({ offset: true }),
20
+ type: z.string(),
21
+ agentId: z.string().optional(),
22
+ data: z.record(z.string(), z.unknown())
23
+ });
24
+ var SessionId = z.string().min(1).max(128).regex(/^[A-Za-z0-9][A-Za-z0-9._-]*$/u);
25
+ var Observation = z.object({ sessionId: SessionId, event: AnalyticsEventSchema });
26
+ var Gap = z.object({ sessionId: SessionId, since: z.number(), count: z.number().int().nonnegative() });
27
+ var History = {
28
+ sessionId: SessionId,
29
+ environment: z.object({ COPILOT_HOME: z.string().optional() }),
30
+ allowMissingEventLog: z.boolean()
31
+ };
32
+ var AnalyticsCommandSchema = z.discriminatedUnion("operation", [
33
+ z.object({ operation: z.literal("observe"), observations: z.array(Observation).max(32), gaps: z.array(Gap) }),
34
+ z.object({ operation: z.literal("index"), ...History }),
35
+ z.object({ operation: z.literal("read"), ...History, request: SessionAnalyticsRequestSchema }),
36
+ z.object({ operation: z.literal("telemetry"), ...History }),
37
+ z.object({ operation: z.literal("remove"), sessionId: SessionId }),
38
+ z.object({ operation: z.literal("close") })
39
+ ]);
40
+ var AnalyticsReplySchema = z.object({
41
+ id: z.number().int(),
42
+ result: z.unknown().optional(),
43
+ error: z.object({ code: z.string(), message: z.string() }).optional()
44
+ });
45
+ var AnalyticsIndexResultSchema = z.object({ complete: z.boolean(), catchUp: z.boolean() });
46
+
47
+ // src/session-update-reader.ts
48
+ import { lstat, open, realpath } from "node:fs/promises";
49
+ import { resolve } from "node:path";
50
+ import { z as z2 } from "zod";
51
+ var MAX_HEAD_BYTES = 8 * 1024 * 1024;
52
+ var EnvelopeSchema = z2.object({
53
+ id: z2.string(),
54
+ type: z2.string(),
55
+ timestamp: z2.iso.datetime({ offset: true }),
56
+ agentId: z2.string().optional(),
57
+ data: z2.unknown()
58
+ });
59
+ var HumanSchema = z2.object({
60
+ content: z2.string(),
61
+ messageId: z2.string().optional(),
62
+ interactionId: z2.string().optional(),
63
+ source: z2.string().optional(),
64
+ isAutopilotContinuation: z2.boolean().optional()
65
+ });
66
+ var AssistantSchema = z2.object({
67
+ messageId: z2.string(),
68
+ content: z2.string(),
69
+ parentToolCallId: z2.string().optional(),
70
+ apiCallId: z2.string().optional(),
71
+ chunkIndex: z2.number().int().nonnegative().optional(),
72
+ chunkCount: z2.number().int().positive().optional(),
73
+ interactionId: z2.string().optional(),
74
+ turnId: z2.string().optional()
75
+ });
76
+ var ToolStartSchema = z2.object({
77
+ toolCallId: z2.string(),
78
+ toolName: z2.string(),
79
+ parentToolCallId: z2.string().optional()
80
+ });
81
+ var ImageSchema = z2.object({
82
+ type: z2.literal("image"),
83
+ data: z2.string(),
84
+ mimeType: z2.string()
85
+ });
86
+ var ImageReferenceSchema = z2.object({
87
+ type: z2.literal("image"),
88
+ assetId: z2.string(),
89
+ mimeType: z2.string(),
90
+ byteLength: z2.number()
91
+ });
92
+ var ToolCompleteSchema = z2.object({
93
+ toolCallId: z2.string(),
94
+ success: z2.boolean(),
95
+ result: z2.object({
96
+ content: z2.string().optional(),
97
+ binaryResultsForLlm: z2.array(z2.unknown()).optional(),
98
+ contents: z2.array(z2.unknown()).optional()
99
+ }).optional(),
100
+ toolDescription: z2.object({ name: z2.string() }).optional(),
101
+ parentToolCallId: z2.string().optional()
102
+ });
103
+ var NoticeSchema = z2.object({ message: z2.string() });
104
+ var NotificationSchema = z2.object({ kind: z2.object({ type: z2.string() }).passthrough() });
105
+ var ShellCompletedSchema = z2.object({
106
+ type: z2.literal("shell_completed"),
107
+ shellId: z2.string(),
108
+ exitCode: z2.number().int().optional()
109
+ });
110
+ function metadataEvent(value, preview = false) {
111
+ const event = EnvelopeSchema.parse(value);
112
+ const toolEvent = event.type === "tool.execution_start" || event.type === "tool.execution_complete";
113
+ if (event.agentId !== void 0 && !toolEvent) return void 0;
114
+ const base = {
115
+ id: event.id,
116
+ timestamp: event.timestamp,
117
+ parentId: null,
118
+ ...event.agentId === void 0 ? {} : { agentId: event.agentId }
119
+ };
120
+ switch (event.type) {
121
+ case "session.binary_asset": {
122
+ if (!preview) return void 0;
123
+ const parsed = ImageSchema.extend({ assetId: z2.string(), byteLength: z2.number() }).safeParse(event.data);
124
+ return parsed.success ? { ...base, type: "session.binary_asset", data: parsed.data } : void 0;
125
+ }
126
+ case "user.message": {
127
+ const data = HumanSchema.parse(event.data);
128
+ if (data.isAutopilotContinuation === true) return void 0;
129
+ return { ...base, type: "user.message", data: {
130
+ content: data.content,
131
+ ...data.messageId === void 0 ? {} : { messageId: data.messageId },
132
+ ...data.interactionId === void 0 ? {} : { interactionId: data.interactionId },
133
+ ...data.source === void 0 ? {} : { source: data.source }
134
+ } };
135
+ }
136
+ case "assistant.message": {
137
+ const data = AssistantSchema.parse(event.data);
138
+ if (data.parentToolCallId !== void 0) return void 0;
139
+ return { ...base, type: "assistant.message", data: {
140
+ messageId: data.messageId,
141
+ content: data.content,
142
+ ...data.apiCallId === void 0 ? {} : { apiCallId: data.apiCallId },
143
+ ...data.chunkIndex === void 0 ? {} : { chunkIndex: data.chunkIndex },
144
+ ...data.chunkCount === void 0 ? {} : { chunkCount: data.chunkCount },
145
+ ...data.interactionId === void 0 ? {} : { interactionId: data.interactionId },
146
+ ...data.turnId === void 0 ? {} : { turnId: data.turnId }
147
+ } };
148
+ }
149
+ case "tool.execution_start": {
150
+ const data = ToolStartSchema.parse(event.data);
151
+ return preview || data.toolName === "task_complete" ? {
152
+ ...base,
153
+ type: "tool.execution_start",
154
+ data: {
155
+ toolCallId: data.toolCallId,
156
+ toolName: data.toolName,
157
+ ...data.parentToolCallId === void 0 ? {} : { parentToolCallId: data.parentToolCallId }
158
+ }
159
+ } : void 0;
160
+ }
161
+ case "tool.execution_complete": {
162
+ const data = ToolCompleteSchema.parse(event.data);
163
+ const images = preview ? data.result?.binaryResultsForLlm?.flatMap((value2) => {
164
+ const parsed = z2.union([ImageSchema, ImageReferenceSchema]).safeParse(value2);
165
+ return parsed.success ? [parsed.data] : [];
166
+ }) ?? [] : [];
167
+ const contents = preview ? data.result?.contents?.flatMap((value2) => {
168
+ const parsed = ImageSchema.safeParse(value2);
169
+ return parsed.success ? [parsed.data] : [];
170
+ }) ?? [] : [];
171
+ return {
172
+ ...base,
173
+ type: "tool.execution_complete",
174
+ data: {
175
+ toolCallId: data.toolCallId,
176
+ success: data.success,
177
+ ...data.result === void 0 ? {} : { result: {
178
+ content: data.result.content ?? "",
179
+ binaryResultsForLlm: images,
180
+ contents
181
+ } },
182
+ ...data.toolDescription === void 0 ? {} : { toolDescription: data.toolDescription },
183
+ ...data.parentToolCallId === void 0 ? {} : { parentToolCallId: data.parentToolCallId }
184
+ }
185
+ };
186
+ }
187
+ case "session.error": {
188
+ const data = NoticeSchema.extend({ errorType: z2.string() }).parse(event.data);
189
+ return { ...base, type: "session.error", data };
190
+ }
191
+ case "session.warning": {
192
+ const data = NoticeSchema.extend({ warningType: z2.string() }).parse(event.data);
193
+ return { ...base, type: "session.warning", data };
194
+ }
195
+ case "system.notification": {
196
+ const { kind } = NotificationSchema.parse(event.data);
197
+ if (kind.type !== "shell_completed") return void 0;
198
+ const shell = ShellCompletedSchema.parse(kind);
199
+ return {
200
+ ...base,
201
+ type: "system.notification",
202
+ data: {
203
+ content: "",
204
+ kind: {
205
+ type: "shell_completed",
206
+ shellId: shell.shellId,
207
+ ...shell.exitCode === void 0 ? {} : { exitCode: shell.exitCode }
208
+ }
209
+ }
210
+ };
211
+ }
212
+ default:
213
+ return void 0;
214
+ }
215
+ }
216
+ async function openSessionEventLog(sessionId, environment = process.env, options = {}) {
217
+ const directory = await realpath(resolveCopilotSessionDirectory(sessionId, environment));
218
+ const expectedPath = resolve(directory, "events.jsonl");
219
+ if (options.allowMissingEventLog?.() === true) {
220
+ try {
221
+ await lstat(expectedPath);
222
+ } catch (error) {
223
+ if (!(error instanceof Error) || !("code" in error) || error.code !== "ENOENT") throw error;
224
+ await realpath(directory);
225
+ if (options.allowMissingEventLog?.() !== true) throw error;
226
+ return void 0;
227
+ }
228
+ }
229
+ const path = await realpath(expectedPath);
230
+ if (path !== expectedPath) throw new Error("Session event log must not be a symbolic link");
231
+ return open(path, "r");
232
+ }
233
+ async function readSessionUpdatePage(sessionId, environment = process.env, resolveInputProvenance, options = {}) {
234
+ const file = await openSessionEventLog(sessionId, environment, options);
235
+ if (file === void 0) return { items: [], cursor: "", hasMore: false, cursorStatus: "ok" };
236
+ try {
237
+ const { size } = await file.stat();
238
+ if (size === 0) {
239
+ options.onEventLogRead?.();
240
+ return { items: [], cursor: "", hasMore: false, cursorStatus: "ok" };
241
+ }
242
+ const start = Math.max(0, size - MAX_HEAD_BYTES);
243
+ const buffer = Buffer.alloc(size - start);
244
+ const { bytesRead } = await file.read(buffer, 0, buffer.length, start);
245
+ const text = buffer.subarray(0, bytesRead).toString("utf8");
246
+ const first = start === 0 ? 0 : text.indexOf("\n") + 1;
247
+ const end = text.lastIndexOf("\n");
248
+ if (first === 0 && start > 0 || end < first) {
249
+ throw new Error("Session event log has no complete records in its metadata window");
250
+ }
251
+ const events = text.slice(first, end).split("\n").filter((line) => line.trim().length > 0).map((line) => metadataEvent(JSON.parse(line), options.assistantPreview === true)).filter((event) => event !== void 0);
252
+ const toolStarts = events.filter((event) => event.type === "tool.execution_start");
253
+ const taskCompletionCallIdsWithStart = new Set(events.flatMap((event) => event.type === "tool.execution_start" && event.data.toolName === "task_complete" ? [event.data.toolCallId] : []));
254
+ const rootTools = new Set(toolStarts.filter((event) => event.agentId === void 0 && event.data.parentToolCallId === void 0).map((event) => event.data.toolCallId));
255
+ const childTools = new Set(toolStarts.filter((event) => event.agentId !== void 0 || event.data.parentToolCallId !== void 0).map((event) => event.data.toolCallId));
256
+ const hasCompleteHistory = start === 0;
257
+ const eventsForMetadata = events.filter((event) => {
258
+ if (event.type === "tool.execution_start" && event.data.toolName !== "task_complete") return false;
259
+ if (event.type !== "tool.execution_complete") {
260
+ return true;
261
+ }
262
+ if (options.assistantPreview === true && event.agentId === void 0 && event.data.parentToolCallId === void 0 && !childTools.has(event.data.toolCallId) && (hasCompleteHistory || rootTools.has(event.data.toolCallId)) && ((event.data.result?.binaryResultsForLlm?.length ?? 0) > 0 || (event.data.result?.contents?.length ?? 0) > 0)) return true;
263
+ if (taskCompletionCallIdsWithStart.has(event.data.toolCallId)) {
264
+ return true;
265
+ }
266
+ if (!hasCompleteHistory) {
267
+ return false;
268
+ }
269
+ return event.data.toolDescription?.name === "task_complete";
270
+ });
271
+ const normalizer = new ConversationNormalizer(void 0, void 0, resolveInputProvenance);
272
+ normalizer.apply(eventsForMetadata);
273
+ const items = normalizer.snapshot().filter((item) => (item.kind === "human-message" || item.kind === "assistant-message" || item.kind === "notice") && (item.actor === "human" || item.actor === "assistant" || item.actor === "system" || item.kind === "assistant-message" && item.actor === "subagent"));
274
+ const latest = items.at(-1);
275
+ const assistant = options.assistantPreview === true ? [...items].reverse().find(isContentfulAssistant) : void 0;
276
+ const human = options.assistantPreview === true ? [...items].reverse().find((item) => item.kind === "human-message" && item.actor === "human") : void 0;
277
+ const completion = [...items].reverse().find((item) => item.kind === "notice" && item.actor === "assistant" && item.severity === "success" && item.title === "Task completed");
278
+ const page = SessionTimelinePageSchema.parse({
279
+ items: [completion, latest, assistant, human].filter((item, index, all) => item !== void 0 && all.findIndex((candidate) => candidate?.id === item.id) === index).map((item) => item?.kind === "human-message" || item?.kind === "assistant-message" ? {
280
+ ...item,
281
+ content: item.id === assistant?.id || item.id === human?.id ? item.content.slice(0, 4096) : "",
282
+ attachments: item.id === assistant?.id ? item.attachments ?? [] : []
283
+ } : { ...item, content: item?.kind === "notice" && item.id === assistant?.id ? item.content.slice(0, 4096) : "" }),
284
+ hasMore: start > 0,
285
+ cursor: "",
286
+ cursorStatus: "ok"
287
+ });
288
+ options.onEventLogRead?.();
289
+ return page;
290
+ } finally {
291
+ await file.close();
292
+ }
293
+ }
294
+
295
+ export {
296
+ openSessionEventLog,
297
+ readSessionUpdatePage,
298
+ AnalyticsEventSchema,
299
+ AnalyticsCommandSchema,
300
+ AnalyticsReplySchema,
301
+ AnalyticsIndexResultSchema
302
+ };