@caplets/pi 0.5.9 → 0.6.1

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 +9 -10
  2. package/dist/chunk-V2S4ZYJR-BGe3hbja.js +1262 -0
  3. package/dist/completion-CbazRAiL-D6NxLI9z.js +497 -0
  4. package/dist/emscripten-module-D5GzfUNv.js +531 -0
  5. package/dist/emscripten-module.wasm +0 -0
  6. package/dist/ffi-7IElU4Co.js +146 -0
  7. package/dist/index.js +164 -18
  8. package/dist/lib.decorators.d.ts +382 -0
  9. package/dist/lib.decorators.legacy.d.ts +20 -0
  10. package/dist/lib.dom.asynciterable.d.ts +18 -0
  11. package/dist/lib.dom.d.ts +45125 -0
  12. package/dist/lib.dom.iterable.d.ts +18 -0
  13. package/dist/lib.es2015.collection.d.ts +150 -0
  14. package/dist/lib.es2015.core.d.ts +595 -0
  15. package/dist/lib.es2015.d.ts +26 -0
  16. package/dist/lib.es2015.generator.d.ts +75 -0
  17. package/dist/lib.es2015.iterable.d.ts +603 -0
  18. package/dist/lib.es2015.promise.d.ts +79 -0
  19. package/dist/lib.es2015.proxy.d.ts +126 -0
  20. package/dist/lib.es2015.reflect.d.ts +142 -0
  21. package/dist/lib.es2015.symbol.d.ts +44 -0
  22. package/dist/lib.es2015.symbol.wellknown.d.ts +324 -0
  23. package/dist/lib.es2016.array.include.d.ts +114 -0
  24. package/dist/lib.es2016.d.ts +19 -0
  25. package/dist/lib.es2016.full.d.ts +21 -0
  26. package/dist/lib.es2016.intl.d.ts +29 -0
  27. package/dist/lib.es2017.arraybuffer.d.ts +19 -0
  28. package/dist/lib.es2017.d.ts +24 -0
  29. package/dist/lib.es2017.date.d.ts +29 -0
  30. package/dist/lib.es2017.full.d.ts +21 -0
  31. package/dist/lib.es2017.intl.d.ts +42 -0
  32. package/dist/lib.es2017.object.d.ts +47 -0
  33. package/dist/lib.es2017.sharedmemory.d.ts +133 -0
  34. package/dist/lib.es2017.string.d.ts +43 -0
  35. package/dist/lib.es2017.typedarrays.d.ts +51 -0
  36. package/dist/lib.es2018.asyncgenerator.d.ts +75 -0
  37. package/dist/lib.es2018.asynciterable.d.ts +51 -0
  38. package/dist/lib.es2018.d.ts +22 -0
  39. package/dist/lib.es2018.full.d.ts +22 -0
  40. package/dist/lib.es2018.intl.d.ts +81 -0
  41. package/dist/lib.es2018.promise.d.ts +28 -0
  42. package/dist/lib.es2018.regexp.d.ts +35 -0
  43. package/dist/lib.es2019.array.d.ts +77 -0
  44. package/dist/lib.es2019.d.ts +22 -0
  45. package/dist/lib.es2019.full.d.ts +22 -0
  46. package/dist/lib.es2019.intl.d.ts +21 -0
  47. package/dist/lib.es2019.object.d.ts +31 -0
  48. package/dist/lib.es2019.string.d.ts +35 -0
  49. package/dist/lib.es2019.symbol.d.ts +22 -0
  50. package/dist/lib.es2020.bigint.d.ts +763 -0
  51. package/dist/lib.es2020.d.ts +25 -0
  52. package/dist/lib.es2020.date.d.ts +40 -0
  53. package/dist/lib.es2020.full.d.ts +22 -0
  54. package/dist/lib.es2020.intl.d.ts +472 -0
  55. package/dist/lib.es2020.number.d.ts +26 -0
  56. package/dist/lib.es2020.promise.d.ts +45 -0
  57. package/dist/lib.es2020.sharedmemory.d.ts +97 -0
  58. package/dist/lib.es2020.string.d.ts +42 -0
  59. package/dist/lib.es2020.symbol.wellknown.d.ts +39 -0
  60. package/dist/lib.es2021.d.ts +21 -0
  61. package/dist/lib.es2021.full.d.ts +22 -0
  62. package/dist/lib.es2021.intl.d.ts +164 -0
  63. package/dist/lib.es2021.promise.d.ts +46 -0
  64. package/dist/lib.es2021.string.d.ts +31 -0
  65. package/dist/lib.es2021.weakref.d.ts +76 -0
  66. package/dist/lib.es2022.array.d.ts +119 -0
  67. package/dist/lib.es2022.d.ts +23 -0
  68. package/dist/lib.es2022.error.d.ts +73 -0
  69. package/dist/lib.es2022.full.d.ts +22 -0
  70. package/dist/lib.es2022.intl.d.ts +143 -0
  71. package/dist/lib.es2022.object.d.ts +24 -0
  72. package/dist/lib.es2022.regexp.d.ts +37 -0
  73. package/dist/lib.es2022.string.d.ts +23 -0
  74. package/dist/lib.es2023.array.d.ts +922 -0
  75. package/dist/lib.es2023.collection.d.ts +19 -0
  76. package/dist/lib.es2023.d.ts +20 -0
  77. package/dist/lib.es2023.full.d.ts +22 -0
  78. package/dist/lib.es2023.intl.d.ts +62 -0
  79. package/dist/lib.es2024.arraybuffer.d.ts +63 -0
  80. package/dist/lib.es2024.collection.d.ts +27 -0
  81. package/dist/lib.es2024.d.ts +24 -0
  82. package/dist/lib.es2024.full.d.ts +22 -0
  83. package/dist/lib.es2024.object.d.ts +27 -0
  84. package/dist/lib.es2024.promise.d.ts +33 -0
  85. package/dist/lib.es2024.regexp.d.ts +23 -0
  86. package/dist/lib.es2024.sharedmemory.d.ts +66 -0
  87. package/dist/lib.es2024.string.d.ts +27 -0
  88. package/dist/lib.es2025.collection.d.ts +94 -0
  89. package/dist/lib.es2025.d.ts +23 -0
  90. package/dist/lib.es2025.float16.d.ts +443 -0
  91. package/dist/lib.es2025.full.d.ts +22 -0
  92. package/dist/lib.es2025.intl.d.ts +200 -0
  93. package/dist/lib.es2025.iterator.d.ts +146 -0
  94. package/dist/lib.es2025.promise.d.ts +32 -0
  95. package/dist/lib.es2025.regexp.d.ts +30 -0
  96. package/dist/lib.es5.d.ts +4599 -0
  97. package/dist/lib.es6.d.ts +21 -0
  98. package/dist/lib.esnext.array.d.ts +33 -0
  99. package/dist/lib.esnext.collection.d.ts +47 -0
  100. package/dist/lib.esnext.d.ts +27 -0
  101. package/dist/lib.esnext.date.d.ts +21 -0
  102. package/dist/lib.esnext.decorators.d.ts +26 -0
  103. package/dist/lib.esnext.disposable.d.ts +191 -0
  104. package/dist/lib.esnext.error.d.ts +22 -0
  105. package/dist/lib.esnext.full.d.ts +22 -0
  106. package/dist/lib.esnext.intl.d.ts +107 -0
  107. package/dist/lib.esnext.sharedmemory.d.ts +23 -0
  108. package/dist/lib.esnext.temporal.d.ts +485 -0
  109. package/dist/lib.esnext.typedarrays.d.ts +90 -0
  110. package/dist/lib.scripthost.d.ts +320 -0
  111. package/dist/lib.webworker.asynciterable.d.ts +18 -0
  112. package/dist/lib.webworker.d.ts +15606 -0
  113. package/dist/lib.webworker.importscripts.d.ts +21 -0
  114. package/dist/lib.webworker.iterable.d.ts +18 -0
  115. package/dist/module-ES6BEMUI-CxBA_RGh.js +2 -0
  116. package/dist/service-D0MwLNyb-eeEfNHql.js +215062 -0
  117. package/package.json +6 -5
package/dist/index.js CHANGED
@@ -1,10 +1,9 @@
1
+ import { o as generatedToolInputJsonSchema, r as createNativeCapletsService } from "./service-D0MwLNyb-eeEfNHql.js";
1
2
  import { createRequire } from "node:module";
2
3
  import { readFile } from "node:fs/promises";
3
4
  import { homedir } from "node:os";
4
5
  import { join } from "node:path";
5
6
  import { keyText } from "@earendil-works/pi-coding-agent";
6
- import { generatedToolInputJsonSchema } from "@caplets/core/generated-tool-input-schema";
7
- import { createNativeCapletsService, registerNativeCapletsProcessCleanup } from "@caplets/core/native";
8
7
  const ambiguousRanges = [
9
8
  161,
10
9
  161,
@@ -682,8 +681,9 @@ function eastAsianWidth(codePoint, { ambiguousAsWide = false } = {}) {
682
681
  return 1;
683
682
  }
684
683
  //#endregion
685
- //#region ../../node_modules/.pnpm/@earendil-works+pi-tui@0.75.5/node_modules/@earendil-works/pi-tui/dist/utils.js
686
- const segmenter$1 = new Intl.Segmenter(void 0, { granularity: "grapheme" });
684
+ //#region ../../node_modules/.pnpm/@earendil-works+pi-tui@0.78.0/node_modules/@earendil-works/pi-tui/dist/utils.js
685
+ const graphemeSegmenter$1 = new Intl.Segmenter(void 0, { granularity: "grapheme" });
686
+ new Intl.Segmenter(void 0, { granularity: "word" });
687
687
  /**
688
688
  * Check if a grapheme cluster (after segmentation) could possibly be an RGI emoji.
689
689
  * This is a fast heuristic to avoid the expensive rgiEmojiRegex test.
@@ -723,7 +723,7 @@ function truncateFragmentToWidth(text, maxWidth) {
723
723
  if (!hasAnsi && !hasTabs) {
724
724
  let result = "";
725
725
  let width = 0;
726
- for (const { segment } of segmenter$1.segment(text)) {
726
+ for (const { segment } of graphemeSegmenter$1.segment(text)) {
727
727
  const w = graphemeWidth(segment);
728
728
  if (width + w > maxWidth) break;
729
729
  result += segment;
@@ -761,7 +761,7 @@ function truncateFragmentToWidth(text, maxWidth) {
761
761
  if (extractAnsiCode(text, end)) break;
762
762
  end++;
763
763
  }
764
- for (const { segment } of segmenter$1.segment(text.slice(i, end))) {
764
+ for (const { segment } of graphemeSegmenter$1.segment(text.slice(i, end))) {
765
765
  const w = graphemeWidth(segment);
766
766
  if (width + w > maxWidth) return {
767
767
  text: result,
@@ -833,7 +833,7 @@ function visibleWidth(str) {
833
833
  clean = stripped;
834
834
  }
835
835
  let width = 0;
836
- for (const { segment } of segmenter$1.segment(clean)) width += graphemeWidth(segment);
836
+ for (const { segment } of graphemeSegmenter$1.segment(clean)) width += graphemeWidth(segment);
837
837
  if (widthCache.size >= WIDTH_CACHE_SIZE) {
838
838
  const firstKey = widthCache.keys().next().value;
839
839
  if (firstKey !== void 0) widthCache.delete(firstKey);
@@ -1134,8 +1134,8 @@ function wrapTextWithAnsi(text, width) {
1134
1134
  const result = [];
1135
1135
  const tracker = new AnsiCodeTracker();
1136
1136
  for (const inputLine of inputLines) {
1137
- const prefix = result.length > 0 ? tracker.getActiveCodes() : "";
1138
- result.push(...wrapSingleLine(prefix + inputLine, width));
1137
+ const wrappedLines = wrapSingleLine((result.length > 0 ? tracker.getActiveCodes() : "") + inputLine, width);
1138
+ for (const wrappedLine of wrappedLines) result.push(wrappedLine);
1139
1139
  updateTrackerFromText(inputLine, tracker);
1140
1140
  }
1141
1141
  return result.length > 0 ? result : [""];
@@ -1160,7 +1160,7 @@ function wrapSingleLine(line, width) {
1160
1160
  currentVisibleLength = 0;
1161
1161
  }
1162
1162
  const broken = breakLongWord(token, width, tracker);
1163
- wrapped.push(...broken.slice(0, -1));
1163
+ for (let i = 0; i < broken.length - 1; i++) wrapped.push(broken[i]);
1164
1164
  currentLine = broken[broken.length - 1];
1165
1165
  currentVisibleLength = visibleWidth(currentLine);
1166
1166
  continue;
@@ -1207,7 +1207,7 @@ function breakLongWord(word, width, tracker) {
1207
1207
  end++;
1208
1208
  }
1209
1209
  const textPortion = word.slice(i, end);
1210
- for (const seg of segmenter$1.segment(textPortion)) segments.push({
1210
+ for (const seg of graphemeSegmenter$1.segment(textPortion)) segments.push({
1211
1211
  type: "grapheme",
1212
1212
  value: seg.segment
1213
1213
  });
@@ -1287,7 +1287,7 @@ function truncateToWidth(text, maxWidth, ellipsis = "...", pad = false) {
1287
1287
  const hasAnsi = text.includes("\x1B");
1288
1288
  const hasTabs = text.includes(" ");
1289
1289
  if (!hasAnsi && !hasTabs) {
1290
- for (const { segment } of segmenter$1.segment(text)) {
1290
+ for (const { segment } of graphemeSegmenter$1.segment(text)) {
1291
1291
  const width = graphemeWidth(segment);
1292
1292
  if (keepContiguousPrefix && keptWidth + width <= targetWidth) {
1293
1293
  result += segment;
@@ -1334,7 +1334,7 @@ function truncateToWidth(text, maxWidth, ellipsis = "...", pad = false) {
1334
1334
  if (extractAnsiCode(text, end)) break;
1335
1335
  end++;
1336
1336
  }
1337
- for (const { segment } of segmenter$1.segment(text.slice(i, end))) {
1337
+ for (const { segment } of graphemeSegmenter$1.segment(text.slice(i, end))) {
1338
1338
  const width = graphemeWidth(segment);
1339
1339
  if (keepContiguousPrefix && keptWidth + width <= targetWidth) {
1340
1340
  if (pendingAnsi) {
@@ -1363,7 +1363,7 @@ function truncateToWidth(text, maxWidth, ellipsis = "...", pad = false) {
1363
1363
  }
1364
1364
  new AnsiCodeTracker();
1365
1365
  //#endregion
1366
- //#region ../../node_modules/.pnpm/@earendil-works+pi-tui@0.75.5/node_modules/@earendil-works/pi-tui/dist/keys.js
1366
+ //#region ../../node_modules/.pnpm/@earendil-works+pi-tui@0.78.0/node_modules/@earendil-works/pi-tui/dist/keys.js
1367
1367
  const MODIFIERS = {
1368
1368
  shift: 1,
1369
1369
  alt: 2,
@@ -1416,7 +1416,7 @@ new Map([
1416
1416
  ]);
1417
1417
  MODIFIERS.shift | LOCK_MASK;
1418
1418
  //#endregion
1419
- //#region ../../node_modules/.pnpm/@earendil-works+pi-tui@0.75.5/node_modules/@earendil-works/pi-tui/dist/components/text.js
1419
+ //#region ../../node_modules/.pnpm/@earendil-works+pi-tui@0.78.0/node_modules/@earendil-works/pi-tui/dist/components/text.js
1420
1420
  /**
1421
1421
  * Text component - displays multi-line text with word wrapping
1422
1422
  */
@@ -3324,7 +3324,7 @@ marked.parseInline;
3324
3324
  _Parser.parse;
3325
3325
  _Lexer.lex;
3326
3326
  //#endregion
3327
- //#region ../../node_modules/.pnpm/@earendil-works+pi-tui@0.75.5/node_modules/@earendil-works/pi-tui/dist/components/markdown.js
3327
+ //#region ../../node_modules/.pnpm/@earendil-works+pi-tui@0.78.0/node_modules/@earendil-works/pi-tui/dist/components/markdown.js
3328
3328
  const STRICT_STRIKETHROUGH_REGEX = /^(~~)(?=[^\s~])((?:\\.|[^\\])*?(?:\\.|[^\s~\\]))\1(?=[^~]|$)/;
3329
3329
  var StrictStrikethroughTokenizer = class extends _Tokenizer {
3330
3330
  del(src) {
@@ -3341,6 +3341,36 @@ var StrictStrikethroughTokenizer = class extends _Tokenizer {
3341
3341
  };
3342
3342
  new Marked().setOptions({ tokenizer: new StrictStrikethroughTokenizer() });
3343
3343
  createRequire(import.meta.url);
3344
+ createRequire(import.meta.url);
3345
+ //#endregion
3346
+ //#region ../core/dist/native.js
3347
+ function registerNativeCapletsProcessCleanup(service, options = {}) {
3348
+ let closed = false;
3349
+ const close = async () => {
3350
+ if (closed) return;
3351
+ closed = true;
3352
+ try {
3353
+ await service.close();
3354
+ } catch (error) {
3355
+ options.writeErr?.(`Failed to close Caplets service: ${errorMessage(error)}\n`);
3356
+ process.exitCode = 1;
3357
+ }
3358
+ };
3359
+ const closeBeforeExit = () => {
3360
+ close();
3361
+ };
3362
+ const closeAndExit = () => {
3363
+ close().finally(() => {
3364
+ process.exit(process.exitCode ?? 0);
3365
+ });
3366
+ };
3367
+ process.once("beforeExit", closeBeforeExit);
3368
+ process.once("SIGINT", closeAndExit);
3369
+ process.once("SIGTERM", closeAndExit);
3370
+ }
3371
+ function errorMessage(error) {
3372
+ return error instanceof Error ? error.message : String(error);
3373
+ }
3344
3374
  //#endregion
3345
3375
  //#region src/index.ts
3346
3376
  function createCapletsPiExtension(options) {
@@ -3466,7 +3496,7 @@ function parsePiNativeOptions(value, writeWarning, path = "settings.caplets") {
3466
3496
  const result = {};
3467
3497
  const mode = value.mode;
3468
3498
  if (mode !== void 0) {
3469
- if (mode !== "auto" && mode !== "local" && mode !== "remote") return void 0;
3499
+ if (mode !== "auto" && mode !== "local" && mode !== "remote" && mode !== "cloud") return;
3470
3500
  result.mode = mode;
3471
3501
  }
3472
3502
  const statusWidget = value.statusWidget;
@@ -3534,7 +3564,7 @@ function nativeServiceOptions(options) {
3534
3564
  function shouldShowStatusWidget(options, statusWidget) {
3535
3565
  if (statusWidget === false) return false;
3536
3566
  if (options.mode === "local") return false;
3537
- return options.mode === "remote" || !!options.server?.url || process.env.CAPLETS_SERVER_URL !== void 0;
3567
+ return options.mode === "remote" || options.mode === "cloud" || !!options.server?.url || process.env.CAPLETS_SERVER_URL !== void 0;
3538
3568
  }
3539
3569
  async function readFileUtf8(path) {
3540
3570
  return readFile(path, "utf8");
@@ -3696,6 +3726,8 @@ function serializeResult(result) {
3696
3726
  }
3697
3727
  }
3698
3728
  function agentContent(result) {
3729
+ const codeModeContent = codeModeAgentContent(result);
3730
+ if (codeModeContent) return codeModeContent;
3699
3731
  const content = arrayProperty(result, "content").filter((item) => stringProperty(item, "type") === "text").map((item) => ({
3700
3732
  type: "text",
3701
3733
  text: stringProperty(item, "text")
@@ -3706,6 +3738,120 @@ function agentContent(result) {
3706
3738
  text: JSON.stringify(result, null, 2) ?? "null"
3707
3739
  }];
3708
3740
  }
3741
+ function codeModeAgentContent(result) {
3742
+ if (!isCodeModeRunEnvelope(result)) return void 0;
3743
+ const ok = Boolean(result.ok);
3744
+ const diagnostics = arrayProperty(result, "diagnostics");
3745
+ const logs = objectProperty(result, "logs");
3746
+ const meta = objectProperty(result, "meta");
3747
+ const value = result.value;
3748
+ const compact = {
3749
+ ok,
3750
+ ...ok ? { value: compactCodeModeAgentValue(value) } : { error: result.error }
3751
+ };
3752
+ if (diagnostics.length > 0) compact.diagnostics = diagnostics;
3753
+ const logSummary = codeModeLogSummary(logs);
3754
+ if (logSummary) compact.logs = logSummary;
3755
+ const durationMs = meta?.durationMs;
3756
+ if (typeof durationMs === "number") compact.durationMs = durationMs;
3757
+ return [{
3758
+ type: "text",
3759
+ text: JSON.stringify(compact) ?? "null"
3760
+ }];
3761
+ }
3762
+ function compactCodeModeAgentValue(value, depth = 0) {
3763
+ if (depth > 16) return "[Max depth reached]";
3764
+ if (Array.isArray(value)) {
3765
+ const items = value.slice(0, 40).map((item) => compactCodeModeAgentValue(item, depth + 1));
3766
+ return value.length > items.length ? [...items, { truncatedItems: value.length - items.length }] : items;
3767
+ }
3768
+ if (!value || typeof value !== "object") return compactCodeModeScalar(value);
3769
+ const record = value;
3770
+ if (isSuccessfulToolCallResultEnvelope(record)) return compactCodeModeAgentValue(record.data, depth + 1);
3771
+ if (isFailedToolCallResultEnvelope(record)) return {
3772
+ ok: false,
3773
+ error: compactCodeModeAgentValue(record.error, depth + 1)
3774
+ };
3775
+ const descriptor = compactCodeModeDescriptor(record, depth);
3776
+ if (descriptor) return descriptor;
3777
+ const entries = Object.entries(record).flatMap(([key, nested]) => {
3778
+ if (isCodeModeAgentNoiseKey(key, nested)) return [];
3779
+ return [[key, compactCodeModeAgentValue(nested, depth + 1)]];
3780
+ });
3781
+ return Object.fromEntries(entries);
3782
+ }
3783
+ function compactCodeModeScalar(value) {
3784
+ if (typeof value !== "string") return value;
3785
+ const collapsed = value.replace(/\s+/gu, " ").trim();
3786
+ return collapsed.length > 1200 ? `${collapsed.slice(0, 1197).trimEnd()}...` : value;
3787
+ }
3788
+ function isSuccessfulToolCallResultEnvelope(record) {
3789
+ return record.ok === true && "data" in record && Object.keys(record).every((key) => [
3790
+ "ok",
3791
+ "data",
3792
+ "meta"
3793
+ ].includes(key)) && isCapletsToolMeta(record.meta);
3794
+ }
3795
+ function isFailedToolCallResultEnvelope(record) {
3796
+ return record.ok === false && "error" in record && Object.keys(record).every((key) => [
3797
+ "ok",
3798
+ "error",
3799
+ "meta"
3800
+ ].includes(key)) && (record.meta === void 0 || isCapletsToolMeta(record.meta));
3801
+ }
3802
+ function isCapletsToolMeta(value) {
3803
+ const meta = value && typeof value === "object" && !Array.isArray(value) ? value : void 0;
3804
+ if (!meta) return false;
3805
+ const record = meta;
3806
+ return Boolean(typeof record.capletId === "string" || typeof record.tool === "string" || typeof record.status === "string" || typeof record.durationMs === "number" || typeof record.elapsedMs === "number");
3807
+ }
3808
+ function compactCodeModeDescriptor(record, depth) {
3809
+ if (!("callSignature" in record || "inputTypeScript" in record || "inputSchema" in record)) return;
3810
+ const compact = {};
3811
+ for (const key of [
3812
+ "id",
3813
+ "name",
3814
+ "title",
3815
+ "description",
3816
+ "callSignature",
3817
+ "inputTypeScript"
3818
+ ]) if (record[key] !== void 0) compact[key] = compactCodeModeAgentValue(record[key], depth + 1);
3819
+ const tool = objectProperty(record, "tool");
3820
+ if (tool) compact.tool = compactCodeModeAgentValue(Object.fromEntries(Object.entries(tool).filter(([key]) => ![
3821
+ "inputSchema",
3822
+ "outputSchema",
3823
+ "annotations"
3824
+ ].includes(key))), depth + 1);
3825
+ return compact;
3826
+ }
3827
+ function isCodeModeAgentNoiseKey(key, value) {
3828
+ if ([
3829
+ "inputSchema",
3830
+ "outputSchema",
3831
+ "outputTypeScript",
3832
+ "observedOutputShape"
3833
+ ].includes(key)) return true;
3834
+ if (key === "examples" && Array.isArray(value)) return value.length > 0;
3835
+ if (key === "fieldSelection") return true;
3836
+ if (key === "meta" && isCapletsToolMeta(value)) return true;
3837
+ return false;
3838
+ }
3839
+ function isCodeModeRunEnvelope(value) {
3840
+ if (!value || typeof value !== "object" || Array.isArray(value)) return false;
3841
+ const record = value;
3842
+ return typeof record.ok === "boolean" && Array.isArray(record.diagnostics) && Boolean(record.logs) && typeof record.logs === "object" && !Array.isArray(record.logs) && Boolean(record.meta) && typeof record.meta === "object" && !Array.isArray(record.meta) && ("value" in record || "error" in record);
3843
+ }
3844
+ function codeModeLogSummary(logs) {
3845
+ if (!logs) return void 0;
3846
+ const entries = arrayProperty(logs, "entries");
3847
+ const truncated = logs.truncated === true;
3848
+ const logRef = stringProperty(logs, "logRef");
3849
+ const summary = {};
3850
+ if (entries.length > 0) summary.entries = entries;
3851
+ if (truncated) summary.truncated = true;
3852
+ if (logRef) summary.logRef = logRef;
3853
+ return Object.keys(summary).length > 0 ? summary : void 0;
3854
+ }
3709
3855
  function compactResultText(result, maxLength = 600) {
3710
3856
  if (!result || typeof result !== "object" || Array.isArray(result)) return compactText(String(result ?? "null"), maxLength);
3711
3857
  const payload = objectProperty(objectProperty(result, "structuredContent"), "result");
@@ -0,0 +1,382 @@
1
+ /*! *****************************************************************************
2
+ Copyright (c) Microsoft Corporation. All rights reserved.
3
+ Licensed under the Apache License, Version 2.0 (the "License"); you may not use
4
+ this file except in compliance with the License. You may obtain a copy of the
5
+ License at http://www.apache.org/licenses/LICENSE-2.0
6
+
7
+ THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
8
+ KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
9
+ WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
10
+ MERCHANTABILITY OR NON-INFRINGEMENT.
11
+
12
+ See the Apache Version 2.0 License for specific language governing permissions
13
+ and limitations under the License.
14
+ ***************************************************************************** */
15
+
16
+
17
+ /**
18
+ * The decorator context types provided to class element decorators.
19
+ */
20
+ type ClassMemberDecoratorContext =
21
+ | ClassMethodDecoratorContext
22
+ | ClassGetterDecoratorContext
23
+ | ClassSetterDecoratorContext
24
+ | ClassFieldDecoratorContext
25
+ | ClassAccessorDecoratorContext;
26
+
27
+ /**
28
+ * The decorator context types provided to any decorator.
29
+ */
30
+ type DecoratorContext =
31
+ | ClassDecoratorContext
32
+ | ClassMemberDecoratorContext;
33
+
34
+ type DecoratorMetadataObject = Record<PropertyKey, unknown> & object;
35
+
36
+ type DecoratorMetadata = typeof globalThis extends { Symbol: { readonly metadata: symbol; }; } ? DecoratorMetadataObject : DecoratorMetadataObject | undefined;
37
+
38
+ /**
39
+ * Context provided to a class decorator.
40
+ * @template Class The type of the decorated class associated with this context.
41
+ */
42
+ interface ClassDecoratorContext<
43
+ Class extends abstract new (...args: any) => any = abstract new (...args: any) => any,
44
+ > {
45
+ /** The kind of element that was decorated. */
46
+ readonly kind: "class";
47
+
48
+ /** The name of the decorated class. */
49
+ readonly name: string | undefined;
50
+
51
+ /**
52
+ * Adds a callback to be invoked after the class definition has been finalized.
53
+ *
54
+ * @example
55
+ * ```ts
56
+ * function customElement(name: string): ClassDecoratorFunction {
57
+ * return (target, context) => {
58
+ * context.addInitializer(function () {
59
+ * customElements.define(name, this);
60
+ * });
61
+ * }
62
+ * }
63
+ *
64
+ * @customElement("my-element")
65
+ * class MyElement {}
66
+ * ```
67
+ */
68
+ addInitializer(initializer: (this: Class) => void): void;
69
+
70
+ readonly metadata: DecoratorMetadata;
71
+ }
72
+
73
+ /**
74
+ * Context provided to a class method decorator.
75
+ * @template This The type on which the class element will be defined. For a static class element, this will be
76
+ * the type of the constructor. For a non-static class element, this will be the type of the instance.
77
+ * @template Value The type of the decorated class method.
78
+ */
79
+ interface ClassMethodDecoratorContext<
80
+ This = unknown,
81
+ Value extends (this: This, ...args: any) => any = (this: This, ...args: any) => any,
82
+ > {
83
+ /** The kind of class element that was decorated. */
84
+ readonly kind: "method";
85
+
86
+ /** The name of the decorated class element. */
87
+ readonly name: string | symbol;
88
+
89
+ /** A value indicating whether the class element is a static (`true`) or instance (`false`) element. */
90
+ readonly static: boolean;
91
+
92
+ /** A value indicating whether the class element has a private name. */
93
+ readonly private: boolean;
94
+
95
+ /** An object that can be used to access the current value of the class element at runtime. */
96
+ readonly access: {
97
+ /**
98
+ * Determines whether an object has a property with the same name as the decorated element.
99
+ */
100
+ has(object: This): boolean;
101
+ /**
102
+ * Gets the current value of the method from the provided object.
103
+ *
104
+ * @example
105
+ * let fn = context.access.get(instance);
106
+ */
107
+ get(object: This): Value;
108
+ };
109
+
110
+ /**
111
+ * Adds a callback to be invoked either after static methods are defined but before
112
+ * static initializers are run (when decorating a `static` element), or before instance
113
+ * initializers are run (when decorating a non-`static` element).
114
+ *
115
+ * @example
116
+ * ```ts
117
+ * const bound: ClassMethodDecoratorFunction = (value, context) {
118
+ * if (context.private) throw new TypeError("Not supported on private methods.");
119
+ * context.addInitializer(function () {
120
+ * this[context.name] = this[context.name].bind(this);
121
+ * });
122
+ * }
123
+ *
124
+ * class C {
125
+ * message = "Hello";
126
+ *
127
+ * @bound
128
+ * m() {
129
+ * console.log(this.message);
130
+ * }
131
+ * }
132
+ * ```
133
+ */
134
+ addInitializer(initializer: (this: This) => void): void;
135
+
136
+ readonly metadata: DecoratorMetadata;
137
+ }
138
+
139
+ /**
140
+ * Context provided to a class getter decorator.
141
+ * @template This The type on which the class element will be defined. For a static class element, this will be
142
+ * the type of the constructor. For a non-static class element, this will be the type of the instance.
143
+ * @template Value The property type of the decorated class getter.
144
+ */
145
+ interface ClassGetterDecoratorContext<
146
+ This = unknown,
147
+ Value = unknown,
148
+ > {
149
+ /** The kind of class element that was decorated. */
150
+ readonly kind: "getter";
151
+
152
+ /** The name of the decorated class element. */
153
+ readonly name: string | symbol;
154
+
155
+ /** A value indicating whether the class element is a static (`true`) or instance (`false`) element. */
156
+ readonly static: boolean;
157
+
158
+ /** A value indicating whether the class element has a private name. */
159
+ readonly private: boolean;
160
+
161
+ /** An object that can be used to access the current value of the class element at runtime. */
162
+ readonly access: {
163
+ /**
164
+ * Determines whether an object has a property with the same name as the decorated element.
165
+ */
166
+ has(object: This): boolean;
167
+ /**
168
+ * Invokes the getter on the provided object.
169
+ *
170
+ * @example
171
+ * let value = context.access.get(instance);
172
+ */
173
+ get(object: This): Value;
174
+ };
175
+
176
+ /**
177
+ * Adds a callback to be invoked either after static methods are defined but before
178
+ * static initializers are run (when decorating a `static` element), or before instance
179
+ * initializers are run (when decorating a non-`static` element).
180
+ */
181
+ addInitializer(initializer: (this: This) => void): void;
182
+
183
+ readonly metadata: DecoratorMetadata;
184
+ }
185
+
186
+ /**
187
+ * Context provided to a class setter decorator.
188
+ * @template This The type on which the class element will be defined. For a static class element, this will be
189
+ * the type of the constructor. For a non-static class element, this will be the type of the instance.
190
+ * @template Value The type of the decorated class setter.
191
+ */
192
+ interface ClassSetterDecoratorContext<
193
+ This = unknown,
194
+ Value = unknown,
195
+ > {
196
+ /** The kind of class element that was decorated. */
197
+ readonly kind: "setter";
198
+
199
+ /** The name of the decorated class element. */
200
+ readonly name: string | symbol;
201
+
202
+ /** A value indicating whether the class element is a static (`true`) or instance (`false`) element. */
203
+ readonly static: boolean;
204
+
205
+ /** A value indicating whether the class element has a private name. */
206
+ readonly private: boolean;
207
+
208
+ /** An object that can be used to access the current value of the class element at runtime. */
209
+ readonly access: {
210
+ /**
211
+ * Determines whether an object has a property with the same name as the decorated element.
212
+ */
213
+ has(object: This): boolean;
214
+ /**
215
+ * Invokes the setter on the provided object.
216
+ *
217
+ * @example
218
+ * context.access.set(instance, value);
219
+ */
220
+ set(object: This, value: Value): void;
221
+ };
222
+
223
+ /**
224
+ * Adds a callback to be invoked either after static methods are defined but before
225
+ * static initializers are run (when decorating a `static` element), or before instance
226
+ * initializers are run (when decorating a non-`static` element).
227
+ */
228
+ addInitializer(initializer: (this: This) => void): void;
229
+
230
+ readonly metadata: DecoratorMetadata;
231
+ }
232
+
233
+ /**
234
+ * Context provided to a class `accessor` field decorator.
235
+ * @template This The type on which the class element will be defined. For a static class element, this will be
236
+ * the type of the constructor. For a non-static class element, this will be the type of the instance.
237
+ * @template Value The type of decorated class field.
238
+ */
239
+ interface ClassAccessorDecoratorContext<
240
+ This = unknown,
241
+ Value = unknown,
242
+ > {
243
+ /** The kind of class element that was decorated. */
244
+ readonly kind: "accessor";
245
+
246
+ /** The name of the decorated class element. */
247
+ readonly name: string | symbol;
248
+
249
+ /** A value indicating whether the class element is a static (`true`) or instance (`false`) element. */
250
+ readonly static: boolean;
251
+
252
+ /** A value indicating whether the class element has a private name. */
253
+ readonly private: boolean;
254
+
255
+ /** An object that can be used to access the current value of the class element at runtime. */
256
+ readonly access: {
257
+ /**
258
+ * Determines whether an object has a property with the same name as the decorated element.
259
+ */
260
+ has(object: This): boolean;
261
+
262
+ /**
263
+ * Invokes the getter on the provided object.
264
+ *
265
+ * @example
266
+ * let value = context.access.get(instance);
267
+ */
268
+ get(object: This): Value;
269
+
270
+ /**
271
+ * Invokes the setter on the provided object.
272
+ *
273
+ * @example
274
+ * context.access.set(instance, value);
275
+ */
276
+ set(object: This, value: Value): void;
277
+ };
278
+
279
+ /**
280
+ * Adds a callback to be invoked immediately after the auto `accessor` being
281
+ * decorated is initialized (regardless if the `accessor` is `static` or not).
282
+ */
283
+ addInitializer(initializer: (this: This) => void): void;
284
+
285
+ readonly metadata: DecoratorMetadata;
286
+ }
287
+
288
+ /**
289
+ * Describes the target provided to class `accessor` field decorators.
290
+ * @template This The `this` type to which the target applies.
291
+ * @template Value The property type for the class `accessor` field.
292
+ */
293
+ interface ClassAccessorDecoratorTarget<This, Value> {
294
+ /**
295
+ * Invokes the getter that was defined prior to decorator application.
296
+ *
297
+ * @example
298
+ * let value = target.get.call(instance);
299
+ */
300
+ get(this: This): Value;
301
+
302
+ /**
303
+ * Invokes the setter that was defined prior to decorator application.
304
+ *
305
+ * @example
306
+ * target.set.call(instance, value);
307
+ */
308
+ set(this: This, value: Value): void;
309
+ }
310
+
311
+ /**
312
+ * Describes the allowed return value from a class `accessor` field decorator.
313
+ * @template This The `this` type to which the target applies.
314
+ * @template Value The property type for the class `accessor` field.
315
+ */
316
+ interface ClassAccessorDecoratorResult<This, Value> {
317
+ /**
318
+ * An optional replacement getter function. If not provided, the existing getter function is used instead.
319
+ */
320
+ get?(this: This): Value;
321
+
322
+ /**
323
+ * An optional replacement setter function. If not provided, the existing setter function is used instead.
324
+ */
325
+ set?(this: This, value: Value): void;
326
+
327
+ /**
328
+ * An optional initializer mutator that is invoked when the underlying field initializer is evaluated.
329
+ * @param value The incoming initializer value.
330
+ * @returns The replacement initializer value.
331
+ */
332
+ init?(this: This, value: Value): Value;
333
+ }
334
+
335
+ /**
336
+ * Context provided to a class field decorator.
337
+ * @template This The type on which the class element will be defined. For a static class element, this will be
338
+ * the type of the constructor. For a non-static class element, this will be the type of the instance.
339
+ * @template Value The type of the decorated class field.
340
+ */
341
+ interface ClassFieldDecoratorContext<
342
+ This = unknown,
343
+ Value = unknown,
344
+ > {
345
+ /** The kind of class element that was decorated. */
346
+ readonly kind: "field";
347
+
348
+ /** The name of the decorated class element. */
349
+ readonly name: string | symbol;
350
+
351
+ /** A value indicating whether the class element is a static (`true`) or instance (`false`) element. */
352
+ readonly static: boolean;
353
+
354
+ /** A value indicating whether the class element has a private name. */
355
+ readonly private: boolean;
356
+
357
+ /** An object that can be used to access the current value of the class element at runtime. */
358
+ readonly access: {
359
+ /**
360
+ * Determines whether an object has a property with the same name as the decorated element.
361
+ */
362
+ has(object: This): boolean;
363
+
364
+ /**
365
+ * Gets the value of the field on the provided object.
366
+ */
367
+ get(object: This): Value;
368
+
369
+ /**
370
+ * Sets the value of the field on the provided object.
371
+ */
372
+ set(object: This, value: Value): void;
373
+ };
374
+
375
+ /**
376
+ * Adds a callback to be invoked immediately after the field being decorated
377
+ * is initialized (regardless if the field is `static` or not).
378
+ */
379
+ addInitializer(initializer: (this: This) => void): void;
380
+
381
+ readonly metadata: DecoratorMetadata;
382
+ }