@mlightcad/cad-llm-plugin 0.0.0-stage → 1.8.0-preview.5

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 (123) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +70 -2
  3. package/dist/cad-llm-plugin-register.js +613 -0
  4. package/dist/cad-llm-plugin-register.umd.cjs +1 -0
  5. package/dist/cad-llm-plugin.js +21481 -0
  6. package/dist/cad-llm-plugin.umd.cjs +514 -0
  7. package/lib/AcApLlmPlugin.d.ts +39 -0
  8. package/lib/AcApLlmPlugin.d.ts.map +1 -0
  9. package/lib/AcApLlmPlugin.js +119 -0
  10. package/lib/AcApLlmPlugin.js.map +1 -0
  11. package/lib/AcApLlmTextRecognizer.d.ts +43 -0
  12. package/lib/AcApLlmTextRecognizer.d.ts.map +1 -0
  13. package/lib/AcApLlmTextRecognizer.js +303 -0
  14. package/lib/AcApLlmTextRecognizer.js.map +1 -0
  15. package/lib/command/AcApLlmSettingsCmd.d.ts +16 -0
  16. package/lib/command/AcApLlmSettingsCmd.d.ts.map +1 -0
  17. package/lib/command/AcApLlmSettingsCmd.js +114 -0
  18. package/lib/command/AcApLlmSettingsCmd.js.map +1 -0
  19. package/lib/constants.d.ts +7 -0
  20. package/lib/constants.d.ts.map +1 -0
  21. package/lib/constants.js +7 -0
  22. package/lib/constants.js.map +1 -0
  23. package/lib/i18n/ar.d.ts +77 -0
  24. package/lib/i18n/ar.d.ts.map +1 -0
  25. package/lib/i18n/ar.js +77 -0
  26. package/lib/i18n/ar.js.map +1 -0
  27. package/lib/i18n/command.d.ts +30 -0
  28. package/lib/i18n/command.d.ts.map +1 -0
  29. package/lib/i18n/command.js +30 -0
  30. package/lib/i18n/command.js.map +1 -0
  31. package/lib/i18n/cs.d.ts +77 -0
  32. package/lib/i18n/cs.d.ts.map +1 -0
  33. package/lib/i18n/cs.js +77 -0
  34. package/lib/i18n/cs.js.map +1 -0
  35. package/lib/i18n/en.d.ts +82 -0
  36. package/lib/i18n/en.d.ts.map +1 -0
  37. package/lib/i18n/en.js +82 -0
  38. package/lib/i18n/en.js.map +1 -0
  39. package/lib/i18n/index.d.ts +29 -0
  40. package/lib/i18n/index.d.ts.map +1 -0
  41. package/lib/i18n/index.js +142 -0
  42. package/lib/i18n/index.js.map +1 -0
  43. package/lib/i18n/ja.d.ts +77 -0
  44. package/lib/i18n/ja.d.ts.map +1 -0
  45. package/lib/i18n/ja.js +77 -0
  46. package/lib/i18n/ja.js.map +1 -0
  47. package/lib/i18n/ko.d.ts +77 -0
  48. package/lib/i18n/ko.d.ts.map +1 -0
  49. package/lib/i18n/ko.js +77 -0
  50. package/lib/i18n/ko.js.map +1 -0
  51. package/lib/i18n/tr.d.ts +77 -0
  52. package/lib/i18n/tr.d.ts.map +1 -0
  53. package/lib/i18n/tr.js +77 -0
  54. package/lib/i18n/tr.js.map +1 -0
  55. package/lib/i18n/zh.d.ts +77 -0
  56. package/lib/i18n/zh.d.ts.map +1 -0
  57. package/lib/i18n/zh.js +77 -0
  58. package/lib/i18n/zh.js.map +1 -0
  59. package/lib/index.d.ts +25 -0
  60. package/lib/index.d.ts.map +1 -0
  61. package/lib/index.js +25 -0
  62. package/lib/index.js.map +1 -0
  63. package/lib/model/AcApLlmModelFactory.d.ts +14 -0
  64. package/lib/model/AcApLlmModelFactory.d.ts.map +1 -0
  65. package/lib/model/AcApLlmModelFactory.js +46 -0
  66. package/lib/model/AcApLlmModelFactory.js.map +1 -0
  67. package/lib/model/AcApLlmModelListing.d.ts +67 -0
  68. package/lib/model/AcApLlmModelListing.d.ts.map +1 -0
  69. package/lib/model/AcApLlmModelListing.js +275 -0
  70. package/lib/model/AcApLlmModelListing.js.map +1 -0
  71. package/lib/model/anthropicBrowserAccess.d.ts +8 -0
  72. package/lib/model/anthropicBrowserAccess.d.ts.map +1 -0
  73. package/lib/model/anthropicBrowserAccess.js +8 -0
  74. package/lib/model/anthropicBrowserAccess.js.map +1 -0
  75. package/lib/model/normalizeLlmBaseUrl.d.ts +17 -0
  76. package/lib/model/normalizeLlmBaseUrl.d.ts.map +1 -0
  77. package/lib/model/normalizeLlmBaseUrl.js +31 -0
  78. package/lib/model/normalizeLlmBaseUrl.js.map +1 -0
  79. package/lib/model/openAiCompatibleFetch.d.ts +11 -0
  80. package/lib/model/openAiCompatibleFetch.d.ts.map +1 -0
  81. package/lib/model/openAiCompatibleFetch.js +122 -0
  82. package/lib/model/openAiCompatibleFetch.js.map +1 -0
  83. package/lib/model/skipDataUrlDownload.d.ts +12 -0
  84. package/lib/model/skipDataUrlDownload.d.ts.map +1 -0
  85. package/lib/model/skipDataUrlDownload.js +58 -0
  86. package/lib/model/skipDataUrlDownload.js.map +1 -0
  87. package/lib/register.d.ts +20 -0
  88. package/lib/register.d.ts.map +1 -0
  89. package/lib/register.js +139 -0
  90. package/lib/register.js.map +1 -0
  91. package/lib/storage/AcApLlmConfigStore.d.ts +218 -0
  92. package/lib/storage/AcApLlmConfigStore.d.ts.map +1 -0
  93. package/lib/storage/AcApLlmConfigStore.js +637 -0
  94. package/lib/storage/AcApLlmConfigStore.js.map +1 -0
  95. package/lib/storage/AcApLlmModelCatalog.d.ts +68 -0
  96. package/lib/storage/AcApLlmModelCatalog.d.ts.map +1 -0
  97. package/lib/storage/AcApLlmModelCatalog.js +141 -0
  98. package/lib/storage/AcApLlmModelCatalog.js.map +1 -0
  99. package/lib/storage/apiKeyCrypto.d.ts +28 -0
  100. package/lib/storage/apiKeyCrypto.d.ts.map +1 -0
  101. package/lib/storage/apiKeyCrypto.js +214 -0
  102. package/lib/storage/apiKeyCrypto.js.map +1 -0
  103. package/lib/storage/settingsEquality.d.ts +10 -0
  104. package/lib/storage/settingsEquality.d.ts.map +1 -0
  105. package/lib/storage/settingsEquality.js +36 -0
  106. package/lib/storage/settingsEquality.js.map +1 -0
  107. package/lib/ui/AcApLlmModelChoices.d.ts +31 -0
  108. package/lib/ui/AcApLlmModelChoices.d.ts.map +1 -0
  109. package/lib/ui/AcApLlmModelChoices.js +68 -0
  110. package/lib/ui/AcApLlmModelChoices.js.map +1 -0
  111. package/lib/ui/AcApLlmProviderLabels.d.ts +19 -0
  112. package/lib/ui/AcApLlmProviderLabels.d.ts.map +1 -0
  113. package/lib/ui/AcApLlmProviderLabels.js +34 -0
  114. package/lib/ui/AcApLlmProviderLabels.js.map +1 -0
  115. package/lib/ui/AcUiLlmSettingsDialog.d.ts +125 -0
  116. package/lib/ui/AcUiLlmSettingsDialog.d.ts.map +1 -0
  117. package/lib/ui/AcUiLlmSettingsDialog.js +1218 -0
  118. package/lib/ui/AcUiLlmSettingsDialog.js.map +1 -0
  119. package/lib/ui/llmSettingsStyles.d.ts +6 -0
  120. package/lib/ui/llmSettingsStyles.d.ts.map +1 -0
  121. package/lib/ui/llmSettingsStyles.js +6 -0
  122. package/lib/ui/llmSettingsStyles.js.map +1 -0
  123. package/package.json +54 -3
@@ -0,0 +1,68 @@
1
+ /**
2
+ * Wire protocol a provider speaks. Each provider uses exactly one, so a
3
+ * gateway that serves two protocols is configured as two providers.
4
+ */
5
+ export type AcApLlmApiProtocol = 'openai-chat' | 'openai-responses' | 'anthropic-messages';
6
+ /** Every protocol the settings UI offers, in display order. */
7
+ export declare const ACAP_LLM_API_PROTOCOLS: readonly AcApLlmApiProtocol[];
8
+ /** One model a provider serves, as listed in the model selector. */
9
+ export interface AcApLlmModelEntry {
10
+ /** Model id sent to the provider API. */
11
+ id: string;
12
+ /** Optional human-readable label; the id is shown when absent. */
13
+ name?: string;
14
+ /** Whether the model accepts image input in chat. */
15
+ vision: boolean;
16
+ }
17
+ /** Ids of the providers that ship with the plugin. */
18
+ export type AcApLlmBuiltinProviderId = 'deepseek' | 'deepseek-vl' | 'openai' | 'anthropic';
19
+ /** Static description of a built-in provider. */
20
+ export interface AcApLlmBuiltinProviderInfo {
21
+ /** Protocol the provider speaks. */
22
+ protocol: AcApLlmApiProtocol;
23
+ /** Default REST base URL. */
24
+ baseUrl: string;
25
+ /** Models offered when the user has not customized the catalog. */
26
+ models: readonly AcApLlmModelEntry[];
27
+ }
28
+ /** Built-in providers in the order the provider dropdown lists them. */
29
+ export declare const ACAP_LLM_BUILTIN_PROVIDER_IDS: readonly AcApLlmBuiltinProviderId[];
30
+ /** Registry of built-in providers keyed by {@link AcApLlmBuiltinProviderId}. */
31
+ export declare const ACAP_LLM_BUILTIN_PROVIDERS: Readonly<Record<AcApLlmBuiltinProviderId, AcApLlmBuiltinProviderInfo>>;
32
+ /**
33
+ * Checks whether a provider id names a built-in provider.
34
+ *
35
+ * @param id - Provider id to test.
36
+ * @returns `true` for ids in {@link ACAP_LLM_BUILTIN_PROVIDER_IDS}.
37
+ */
38
+ export declare function acapLlmIsBuiltinProviderId(id: string): id is AcApLlmBuiltinProviderId;
39
+ /**
40
+ * Guesses whether a model accepts image input from its id alone.
41
+ *
42
+ * Used for models the user adds by hand or adopts from a provider listing,
43
+ * which rarely discloses input modalities.
44
+ *
45
+ * @param modelId - Model id to evaluate.
46
+ * @returns `true` when the id matches a known vision model family.
47
+ */
48
+ export declare function acapLlmGuessModelVision(modelId: string): boolean;
49
+ /**
50
+ * Computes a model row's vision flag after its id is edited.
51
+ *
52
+ * While the flag still agrees with the guess for the previous id the user has
53
+ * not overridden it, so it keeps following the id as it is typed; a flag the
54
+ * user set explicitly is left alone.
55
+ *
56
+ * @param previous - Row before the edit.
57
+ * @param id - Edited model id.
58
+ * @returns Vision flag for the edited row.
59
+ */
60
+ export declare function acapLlmVisionAfterIdEdit(previous: AcApLlmModelEntry, id: string): boolean;
61
+ /**
62
+ * Returns the display label of a model entry.
63
+ *
64
+ * @param entry - Model entry.
65
+ * @returns The entry name, or its id when unnamed.
66
+ */
67
+ export declare function acapLlmModelLabel(entry: AcApLlmModelEntry): string;
68
+ //# sourceMappingURL=AcApLlmModelCatalog.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AcApLlmModelCatalog.d.ts","sourceRoot":"","sources":["../../src/storage/AcApLlmModelCatalog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 +1,141 @@
1
+ /** Every protocol the settings UI offers, in display order. */
2
+ export var ACAP_LLM_API_PROTOCOLS = [
3
+ 'openai-chat',
4
+ 'openai-responses',
5
+ 'anthropic-messages'
6
+ ];
7
+ /** Built-in providers in the order the provider dropdown lists them. */
8
+ export var ACAP_LLM_BUILTIN_PROVIDER_IDS = ['deepseek', 'deepseek-vl', 'openai', 'anthropic'];
9
+ var OPENAI_MODELS = [
10
+ { id: 'gpt-5.4-mini', name: 'GPT-5.4 Mini', vision: true },
11
+ { id: 'gpt-5.4', name: 'GPT-5.4', vision: true },
12
+ { id: 'gpt-5.5', name: 'GPT-5.5', vision: true },
13
+ { id: 'gpt-5.6-luna', name: 'GPT-5.6 Luna', vision: true },
14
+ { id: 'gpt-5.6-terra', name: 'GPT-5.6 Terra', vision: true },
15
+ { id: 'gpt-5.6-sol', name: 'GPT-5.6 Sol', vision: true }
16
+ ];
17
+ /** Registry of built-in providers keyed by {@link AcApLlmBuiltinProviderId}. */
18
+ export var ACAP_LLM_BUILTIN_PROVIDERS = {
19
+ deepseek: {
20
+ protocol: 'openai-chat',
21
+ baseUrl: 'https://api.deepseek.com/v1',
22
+ models: [
23
+ { id: 'deepseek-v4-flash', name: 'DeepSeek V4 Flash', vision: false },
24
+ { id: 'deepseek-v4-pro', name: 'DeepSeek V4 Pro', vision: false },
25
+ { id: 'deepseek-chat', name: 'DeepSeek Chat (legacy)', vision: false },
26
+ {
27
+ id: 'deepseek-reasoner',
28
+ name: 'DeepSeek Reasoner (legacy)',
29
+ vision: false
30
+ }
31
+ ]
32
+ },
33
+ 'deepseek-vl': {
34
+ protocol: 'openai-chat',
35
+ baseUrl: 'https://api.siliconflow.cn/v1',
36
+ models: [
37
+ { id: 'deepseek-vl2', name: 'DeepSeek VL2', vision: true },
38
+ {
39
+ id: 'deepseek-ai/deepseek-vl2-small',
40
+ name: 'DeepSeek VL2 Small',
41
+ vision: true
42
+ },
43
+ {
44
+ id: 'deepseek-ai/deepseek-vl2-tiny',
45
+ name: 'DeepSeek VL2 Tiny',
46
+ vision: true
47
+ },
48
+ {
49
+ id: 'deepseek-ai/deepseek-vl2',
50
+ name: 'DeepSeek VL2 (HF)',
51
+ vision: true
52
+ }
53
+ ]
54
+ },
55
+ openai: {
56
+ protocol: 'openai-chat',
57
+ baseUrl: 'https://api.openai.com/v1',
58
+ models: OPENAI_MODELS
59
+ },
60
+ anthropic: {
61
+ protocol: 'anthropic-messages',
62
+ baseUrl: 'https://api.anthropic.com/v1',
63
+ models: [
64
+ { id: 'claude-sonnet-4-6', name: 'Claude Sonnet 4.6', vision: true },
65
+ { id: 'claude-sonnet-5', name: 'Claude Sonnet 5', vision: true },
66
+ { id: 'claude-opus-4-6', name: 'Claude Opus 4.6', vision: true },
67
+ { id: 'claude-opus-4-7', name: 'Claude Opus 4.7', vision: true },
68
+ { id: 'claude-opus-4-8', name: 'Claude Opus 4.8', vision: true },
69
+ { id: 'claude-opus-5', name: 'Claude Opus 5', vision: true },
70
+ { id: 'claude-fable-5', name: 'Claude Fable 5', vision: true }
71
+ ]
72
+ }
73
+ };
74
+ /**
75
+ * Checks whether a provider id names a built-in provider.
76
+ *
77
+ * @param id - Provider id to test.
78
+ * @returns `true` for ids in {@link ACAP_LLM_BUILTIN_PROVIDER_IDS}.
79
+ */
80
+ export function acapLlmIsBuiltinProviderId(id) {
81
+ return ACAP_LLM_BUILTIN_PROVIDER_IDS.includes(id);
82
+ }
83
+ /** Heuristic patterns for vision-capable models not listed in presets. */
84
+ var VISION_MODEL_PATTERNS = [
85
+ /gpt-5/i,
86
+ /gpt-4o/i,
87
+ /gpt-4\.1/i,
88
+ /gpt-4-turbo/i,
89
+ /gpt-4-vision/i,
90
+ /claude-3/i,
91
+ /claude-sonnet/i,
92
+ /claude-opus/i,
93
+ /claude-haiku/i,
94
+ /claude-fable/i,
95
+ /gemini/i,
96
+ /qwen.*vl/i,
97
+ /deepseek-vl/i,
98
+ /glm-4(\.\d+)?v/i,
99
+ /kimi.*(vl|vision)/i,
100
+ /llava/i,
101
+ /pixtral/i
102
+ ];
103
+ /**
104
+ * Guesses whether a model accepts image input from its id alone.
105
+ *
106
+ * Used for models the user adds by hand or adopts from a provider listing,
107
+ * which rarely discloses input modalities.
108
+ *
109
+ * @param modelId - Model id to evaluate.
110
+ * @returns `true` when the id matches a known vision model family.
111
+ */
112
+ export function acapLlmGuessModelVision(modelId) {
113
+ return VISION_MODEL_PATTERNS.some(function (pattern) { return pattern.test(modelId); });
114
+ }
115
+ /**
116
+ * Computes a model row's vision flag after its id is edited.
117
+ *
118
+ * While the flag still agrees with the guess for the previous id the user has
119
+ * not overridden it, so it keeps following the id as it is typed; a flag the
120
+ * user set explicitly is left alone.
121
+ *
122
+ * @param previous - Row before the edit.
123
+ * @param id - Edited model id.
124
+ * @returns Vision flag for the edited row.
125
+ */
126
+ export function acapLlmVisionAfterIdEdit(previous, id) {
127
+ return previous.vision === acapLlmGuessModelVision(previous.id)
128
+ ? acapLlmGuessModelVision(id)
129
+ : previous.vision;
130
+ }
131
+ /**
132
+ * Returns the display label of a model entry.
133
+ *
134
+ * @param entry - Model entry.
135
+ * @returns The entry name, or its id when unnamed.
136
+ */
137
+ export function acapLlmModelLabel(entry) {
138
+ var _a;
139
+ return ((_a = entry.name) === null || _a === void 0 ? void 0 : _a.trim()) || entry.id;
140
+ }
141
+ //# sourceMappingURL=AcApLlmModelCatalog.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AcApLlmModelCatalog.js","sourceRoot":"","sources":["../../src/storage/AcApLlmModelCatalog.ts"],"names":[],"mappings":"AASA,+DAA+D;AAC/D,MAAM,CAAC,IAAM,sBAAsB,GAAkC;IACnE,aAAa;IACb,kBAAkB;IAClB,oBAAoB;CACrB,CAAA;AA6BD,wEAAwE;AACxE,MAAM,CAAC,IAAM,6BAA6B,GACxC,CAAC,UAAU,EAAE,aAAa,EAAE,QAAQ,EAAE,WAAW,CAAC,CAAA;AAEpD,IAAM,aAAa,GAAiC;IAClD,EAAE,EAA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;IACR,SAAS;IACT,WAAW;IACX,cAAc;IACd,eAAe;IACf,WAAW;IACX,gBAAgB;IAChB,cAAc;IACd,eAAe;IACf,eAAe;IACf,SAAS;IACT,WAAW;IACX,cAAc;IACd,iBAAiB;IACjB,oBAAoB;IACpB,QAAQ;IACR,UAAU;CACX,CAAA;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,uBAAuB,CAAC,OAAe;IACrD,OAAO,qBAAqB,CAAC,IAAI,CAAC,UAAA,OAAO,IAAI,OAAA,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,EAArB,CAAqB,CAAC,CAAA;AACrE,CAAC;AAED;;;;;;;;;;GAUG;AACH,MAAM,UAAU,wBAAwB,CACtC,QAA2B,EAC3B,EAAU;IAEV,OAAO,QAAQ,CAAC,MAAM,KAAK,uBAAuB,CAAC,QAAQ,CAAC,EAAE,CAAC;QAC7D,CAAC,CAAC,uBAAuB,CAAC,EAAE,CAAC;QAC7B,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAA;AACrB,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,iBAAiB,CAAC,KAAwB;;IACxD,OAAO,CAAA,MAAA,KAAK,CAAC,IAAI,0CAAE,IAAI,EAAE,KAAI,KAAK,CAAC,EAAE,CAAA;AACvC,CAAC"}
@@ -0,0 +1,28 @@
1
+ /**
2
+ * Prefix that marks an API key value as encrypted in `localStorage`.
3
+ *
4
+ * Payloads use the form `enc:v{version}:{base64(iv + ciphertext)}`.
5
+ */
6
+ export declare const ENCRYPTED_API_KEY_PREFIX = "enc:v1:";
7
+ /**
8
+ * Encrypts an API key for storage in `localStorage`.
9
+ *
10
+ * Uses AES-GCM with a random {@link IV_LENGTH}-byte IV prepended to the ciphertext.
11
+ * Empty input returns an empty string without invoking Web Crypto.
12
+ *
13
+ * @param apiKey - Plaintext provider API key.
14
+ * @returns Encrypted payload prefixed with {@link ENCRYPTED_API_KEY_PREFIX}.
15
+ */
16
+ export declare function encryptApiKey(apiKey: string): Promise<string>;
17
+ /**
18
+ * Decrypts an API key previously stored by {@link encryptApiKey}.
19
+ *
20
+ * Values without {@link ENCRYPTED_API_KEY_PREFIX} are returned unchanged so legacy
21
+ * plaintext entries can be migrated on the next save. Decryption failures yield
22
+ * an empty string.
23
+ *
24
+ * @param encryptedApiKey - Encrypted payload or legacy plaintext value.
25
+ * @returns Plaintext API key, or an empty string when input is empty or decryption fails.
26
+ */
27
+ export declare function decryptApiKey(encryptedApiKey: string): Promise<string>;
28
+ //# sourceMappingURL=apiKeyCrypto.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"apiKeyCrypto.d.ts","sourceRoot":"","sources":["../../src/storage/apiKeyCrypto.ts"],"names":[],"mappings":"AASA;;;;GAIG;AACH,eAAO,MAAM,wBAAwB,YAA4B,CAAA;AA2EjE;;;;;;;;GAQG;AACH,wBAAsB,aAAa,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAmBnE;AAED;;;;;;;;;GASG;AACH,wBAAsB,aAAa,CAAC,eAAe,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAyB5E"}
@@ -0,0 +1,214 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ var __generator = (this && this.__generator) || function (thisArg, body) {
11
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
12
+ return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
13
+ function verb(n) { return function (v) { return step([n, v]); }; }
14
+ function step(op) {
15
+ if (f) throw new TypeError("Generator is already executing.");
16
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
17
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
18
+ if (y = 0, t) op = [op[0] & 2, t.value];
19
+ switch (op[0]) {
20
+ case 0: case 1: t = op; break;
21
+ case 4: _.label++; return { value: op[1], done: false };
22
+ case 5: _.label++; y = op[1]; op = [0]; continue;
23
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
24
+ default:
25
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
26
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
27
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
28
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
29
+ if (t[2]) _.ops.pop();
30
+ _.trys.pop(); continue;
31
+ }
32
+ op = body.call(thisArg, _);
33
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
34
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
35
+ }
36
+ };
37
+ var __values = (this && this.__values) || function(o) {
38
+ var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
39
+ if (m) return m.call(o);
40
+ if (o && typeof o.length === "number") return {
41
+ next: function () {
42
+ if (o && i >= o.length) o = void 0;
43
+ return { value: o && o[i++], done: !o };
44
+ }
45
+ };
46
+ throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
47
+ };
48
+ /** Encryption format version embedded in {@link ENCRYPTED_API_KEY_PREFIX}. */
49
+ var CRYPTO_VERSION = 1;
50
+ /** Application-specific salt used for PBKDF2 key derivation. */
51
+ var SALT = 'cad-agent-plugin-api-key-v1';
52
+ /** AES-GCM initialization vector length in bytes. */
53
+ var IV_LENGTH = 12;
54
+ /**
55
+ * Prefix that marks an API key value as encrypted in `localStorage`.
56
+ *
57
+ * Payloads use the form `enc:v{version}:{base64(iv + ciphertext)}`.
58
+ */
59
+ export var ENCRYPTED_API_KEY_PREFIX = "enc:v".concat(CRYPTO_VERSION, ":");
60
+ /**
61
+ * Builds the password material for PBKDF2 from the page origin and {@link SALT}.
62
+ *
63
+ * @returns A string bound to the current browsing origin (or `file://` when unavailable).
64
+ */
65
+ function getEncryptionMaterial() {
66
+ var _a;
67
+ var origin = typeof ((_a = globalThis.location) === null || _a === void 0 ? void 0 : _a.origin) === 'string'
68
+ ? globalThis.location.origin
69
+ : 'file://';
70
+ return "".concat(origin, ":").concat(SALT);
71
+ }
72
+ /**
73
+ * Derives the AES-GCM key used to encrypt and decrypt stored API keys.
74
+ *
75
+ * Uses PBKDF2 (SHA-256, 100k iterations) over {@link getEncryptionMaterial}.
76
+ *
77
+ * @returns A 256-bit {@link CryptoKey} suitable for AES-GCM.
78
+ */
79
+ function deriveCryptoKey() {
80
+ return __awaiter(this, void 0, void 0, function () {
81
+ var encoder, keyMaterial;
82
+ return __generator(this, function (_a) {
83
+ switch (_a.label) {
84
+ case 0:
85
+ encoder = new TextEncoder();
86
+ return [4 /*yield*/, crypto.subtle.importKey('raw', encoder.encode(getEncryptionMaterial()), 'PBKDF2', false, ['deriveKey'])];
87
+ case 1:
88
+ keyMaterial = _a.sent();
89
+ return [2 /*return*/, crypto.subtle.deriveKey({
90
+ name: 'PBKDF2',
91
+ salt: encoder.encode(SALT),
92
+ iterations: 100000,
93
+ hash: 'SHA-256'
94
+ }, keyMaterial, { name: 'AES-GCM', length: 256 }, false, ['encrypt', 'decrypt'])];
95
+ }
96
+ });
97
+ });
98
+ }
99
+ /**
100
+ * Encodes a byte array as a standard base64 string.
101
+ *
102
+ * @param bytes - Raw bytes to encode.
103
+ * @returns Base64 representation of `bytes`.
104
+ */
105
+ function toBase64(bytes) {
106
+ var e_1, _a;
107
+ var binary = '';
108
+ try {
109
+ for (var bytes_1 = __values(bytes), bytes_1_1 = bytes_1.next(); !bytes_1_1.done; bytes_1_1 = bytes_1.next()) {
110
+ var byte = bytes_1_1.value;
111
+ binary += String.fromCharCode(byte);
112
+ }
113
+ }
114
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
115
+ finally {
116
+ try {
117
+ if (bytes_1_1 && !bytes_1_1.done && (_a = bytes_1.return)) _a.call(bytes_1);
118
+ }
119
+ finally { if (e_1) throw e_1.error; }
120
+ }
121
+ return btoa(binary);
122
+ }
123
+ /**
124
+ * Decodes a standard base64 string into a byte array.
125
+ *
126
+ * @param value - Base64 text to decode.
127
+ * @returns Decoded bytes.
128
+ */
129
+ function fromBase64(value) {
130
+ var binary = atob(value);
131
+ var bytes = new Uint8Array(binary.length);
132
+ for (var index = 0; index < binary.length; index++) {
133
+ bytes[index] = binary.charCodeAt(index);
134
+ }
135
+ return bytes;
136
+ }
137
+ /**
138
+ * Encrypts an API key for storage in `localStorage`.
139
+ *
140
+ * Uses AES-GCM with a random {@link IV_LENGTH}-byte IV prepended to the ciphertext.
141
+ * Empty input returns an empty string without invoking Web Crypto.
142
+ *
143
+ * @param apiKey - Plaintext provider API key.
144
+ * @returns Encrypted payload prefixed with {@link ENCRYPTED_API_KEY_PREFIX}.
145
+ */
146
+ export function encryptApiKey(apiKey) {
147
+ return __awaiter(this, void 0, void 0, function () {
148
+ var key, iv, encoded, cipherText, payload;
149
+ return __generator(this, function (_a) {
150
+ switch (_a.label) {
151
+ case 0:
152
+ if (!apiKey) {
153
+ return [2 /*return*/, ''];
154
+ }
155
+ return [4 /*yield*/, deriveCryptoKey()];
156
+ case 1:
157
+ key = _a.sent();
158
+ iv = crypto.getRandomValues(new Uint8Array(IV_LENGTH));
159
+ encoded = new TextEncoder().encode(apiKey);
160
+ return [4 /*yield*/, crypto.subtle.encrypt({ name: 'AES-GCM', iv: iv }, key, encoded)];
161
+ case 2:
162
+ cipherText = _a.sent();
163
+ payload = new Uint8Array(iv.length + cipherText.byteLength);
164
+ payload.set(iv, 0);
165
+ payload.set(new Uint8Array(cipherText), iv.length);
166
+ return [2 /*return*/, "".concat(ENCRYPTED_API_KEY_PREFIX).concat(toBase64(payload))];
167
+ }
168
+ });
169
+ });
170
+ }
171
+ /**
172
+ * Decrypts an API key previously stored by {@link encryptApiKey}.
173
+ *
174
+ * Values without {@link ENCRYPTED_API_KEY_PREFIX} are returned unchanged so legacy
175
+ * plaintext entries can be migrated on the next save. Decryption failures yield
176
+ * an empty string.
177
+ *
178
+ * @param encryptedApiKey - Encrypted payload or legacy plaintext value.
179
+ * @returns Plaintext API key, or an empty string when input is empty or decryption fails.
180
+ */
181
+ export function decryptApiKey(encryptedApiKey) {
182
+ return __awaiter(this, void 0, void 0, function () {
183
+ var key, payload, iv, cipherText, plainBuffer, _a;
184
+ return __generator(this, function (_b) {
185
+ switch (_b.label) {
186
+ case 0:
187
+ if (!encryptedApiKey) {
188
+ return [2 /*return*/, ''];
189
+ }
190
+ if (!encryptedApiKey.startsWith(ENCRYPTED_API_KEY_PREFIX)) {
191
+ return [2 /*return*/, encryptedApiKey];
192
+ }
193
+ _b.label = 1;
194
+ case 1:
195
+ _b.trys.push([1, 4, , 5]);
196
+ return [4 /*yield*/, deriveCryptoKey()];
197
+ case 2:
198
+ key = _b.sent();
199
+ payload = fromBase64(encryptedApiKey.slice(ENCRYPTED_API_KEY_PREFIX.length));
200
+ iv = payload.slice(0, IV_LENGTH);
201
+ cipherText = payload.slice(IV_LENGTH);
202
+ return [4 /*yield*/, crypto.subtle.decrypt({ name: 'AES-GCM', iv: iv }, key, cipherText)];
203
+ case 3:
204
+ plainBuffer = _b.sent();
205
+ return [2 /*return*/, new TextDecoder().decode(plainBuffer)];
206
+ case 4:
207
+ _a = _b.sent();
208
+ return [2 /*return*/, ''];
209
+ case 5: return [2 /*return*/];
210
+ }
211
+ });
212
+ });
213
+ }
214
+ //# sourceMappingURL=apiKeyCrypto.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"apiKeyCrypto.js","sourceRoot":"","sources":["../../src/storage/apiKeyCrypto.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,8EAA8E;AAC9E,IAAM,cAAc,GAAG,CAAC,CAAA;AAExB,gEAAgE;AAChE,IAAM,IAAI,GAAG,6BAA6B,CAAA;AAE1C,qDAAqD;AACrD,IAAM,SAAS,GAAG,EAAE,CAAA;AAEpB;;;;GAIG;AACH,MAAM,CAAC,IAAM,wBAAwB,GAAG,eAAQ,cAAc,MAAG,CAAA;AAEjE;;;;GAIG;AACH,SAAS,qBAAqB;;IAC5B,IAAM,MAAM,GACV,OAAO,CAAA,MAAA,UAAU,CAAC,QAAQ,0CAAE,MAAM,CAAA,KAAK,QAAQ;QAC7C,CAAC,CAAC,UAAU,CAAC,QAAQ,CAAC,MAAM;QAC5B,CAAC,CAAC,SAAS,CAAA;IACf,OAAO,UAAG,MAAM,cAAI,IAAI,CAAE,CAAA;AAC5B,CAAC;AAED;;;;;;GAMG;AACH,SAAe,eAAe;;;;;;oBACtB,OAAO,GAAG,IAAI,WAAW,EAAE,CAAA;oBACb,qBAAM,MAAM,CAAC,MAAM,CAAC,SAAS,CAC/C,KAAK,EACL,OAAO,CAAC,MAAM,CAAC,qBAAqB,EAAE,CAAC,EACvC,QAAQ,EACR,KAAK,EACL,CAAC,WAAW,CAAC,CACd,EAAA;;oBANK,WAAW,GAAG,SAMnB;oBAED,sBAAO,MAAM,CAAC,MAAM,CAAC,SAAS,CAC5B;4BACE,IAAI,EAAE,QAAQ;4BACd,IAAI,EAAE,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC;4BAC1B,UAAU,EAAE,MAAO;4BACnB,IAAI,EAAE,S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AW,CAAC,EAAA;;;oBAE5C,sBAAO,EAAE,EAAA;;;;;CAEZ"}
@@ -0,0 +1,10 @@
1
+ import type { AcApLlmProviderConfig } from './AcApLlmConfigStore.js';
2
+ /**
3
+ * Compares two provider configs, e.g. a settings draft with its saved copy.
4
+ *
5
+ * @param left - First provider config.
6
+ * @param right - Second provider config.
7
+ * @returns `true` when all persisted fields match.
8
+ */
9
+ export declare function acapLlmAreProvidersEqual(left: AcApLlmProviderConfig, right: AcApLlmProviderConfig): boolean;
10
+ //# sourceMappingURL=settingsEquality.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"settingsEquality.d.ts","sourceRoot":"","sources":["../../src/storage/settingsEquality.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAA;AA0BpE;;;;;;GAMG;AACH,wBAAgB,wBAAwB,CACtC,IAAI,EAAE,qBAAqB,EAC3B,KAAK,EAAE,qBAAqB,GAC3B,OAAO,CAUT"}
@@ -0,0 +1,36 @@
1
+ /**
2
+ * Compares two model catalogs entry by entry.
3
+ *
4
+ * @param left - First catalog (`null` = built-in defaults).
5
+ * @param right - Second catalog.
6
+ * @returns `true` when both hold the same entries in the same order.
7
+ */
8
+ function areModelListsEqual(left, right) {
9
+ if (left === null || right === null)
10
+ return left === right;
11
+ return (left.length === right.length &&
12
+ left.every(function (model, index) {
13
+ var _a, _b;
14
+ return model.id === right[index].id &&
15
+ ((_a = model.name) !== null && _a !== void 0 ? _a : '') === ((_b = right[index].name) !== null && _b !== void 0 ? _b : '') &&
16
+ model.vision === right[index].vision;
17
+ }));
18
+ }
19
+ /**
20
+ * Compares two provider configs, e.g. a settings draft with its saved copy.
21
+ *
22
+ * @param left - First provider config.
23
+ * @param right - Second provider config.
24
+ * @returns `true` when all persisted fields match.
25
+ */
26
+ export function acapLlmAreProvidersEqual(left, right) {
27
+ var _a, _b;
28
+ return (left.id === right.id &&
29
+ left.kind === right.kind &&
30
+ ((_a = left.displayName) !== null && _a !== void 0 ? _a : '') === ((_b = right.displayName) !== null && _b !== void 0 ? _b : '') &&
31
+ left.protocol === right.protocol &&
32
+ left.baseUrl === right.baseUrl &&
33
+ left.apiKey === right.apiKey &&
34
+ areModelListsEqual(left.models, right.models));
35
+ }
36
+ //# sourceMappingURL=settingsEquality.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"settingsEquality.js","sourceRoot":"","sources":["../../src/storage/settingsEquality.ts"],"names":[],"mappings":"AAGA;;;;;;GAMG;AACH,SAAS,kBAAkB,CACzB,IAAyC,EACzC,KAA0C;IAE1C,IAAI,IAAI,KAAK,IAAI,IAAI,KAAK,KAAK,IAAI;QAAE,OAAO,IAAI,KAAK,KAAK,CAAA;IAC1D,OAAO,CACL,IAAI,CAAC,MAAM,KAAK,KAAK,CAAC,MAAM;QAC5B,IAAI,CAAC,KAAK,CACR,UAAC,KAAK,EAAE,KAAK;;YACX,OAAA,KAAK,CAAC,EAAE,KAAK,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE;gBAC5B,CAAC,MAAA,KAAK,CAAC,IAAI,mCAAI,EAAE,CAAC,KAAK,CAAC,MAAA,KAAK,CAAC,KAAK,CAAC,CAAC,IAAI,mCAAI,EAAE,CAAC;gBAChD,KAAK,CAAC,MAAM,KAAK,KAAK,CAAC,KAAK,CAAC,CAAC,MAAM,CAAA;SAAA,CACvC,CACF,CAAA;AACH,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,wBAAwB,CACtC,IAA2B,EAC3B,KAA4B;;IAE5B,OAAO,CACL,IAAI,CAAC,EAAE,KAAK,KAAK,CAAC,EAAE;QACpB,IAAI,CAAC,IAAI,KAAK,KAAK,CAAC,IAAI;QACxB,CAAC,MAAA,IAAI,CAAC,WAAW,mCAAI,EAAE,CAAC,KAAK,CAAC,MAAA,KAAK,CAAC,WAAW,mCAAI,EAAE,CAAC;QACtD,IAAI,CAAC,QAAQ,KAAK,KAAK,CAAC,QAAQ;QAChC,IAAI,CAAC,OAAO,KAAK,KAAK,CAAC,OAAO;QAC9B,IAAI,CAAC,MAAM,KAAK,KAAK,CAAC,MAAM;QAC5B,kBAAkB,CAAC,IAAI,CAAC,MAAM,EAAE,KAAK,CAAC,MAAM,CAAC,CAC9C,CAAA;AACH,CAAC"}
@@ -0,0 +1,31 @@
1
+ import { type AcApLlmConfig } from '../storage/AcApLlmConfigStore.js';
2
+ /** One selectable model in a model picker. */
3
+ export interface AcApLlmModelChoice {
4
+ /** Provider that serves the model. */
5
+ providerId: string;
6
+ /** Model id sent to the provider. */
7
+ modelId: string;
8
+ /** Display label. */
9
+ label: string;
10
+ /** Whether the model accepts image input. */
11
+ vision: boolean;
12
+ }
13
+ /** Models of one provider, for an `<optgroup>`. */
14
+ export interface AcApLlmModelChoiceGroup {
15
+ /** Provider id. */
16
+ providerId: string;
17
+ /** Localized provider name. */
18
+ label: string;
19
+ /** Models in catalog order. */
20
+ options: AcApLlmModelChoice[];
21
+ }
22
+ /**
23
+ * Lists the models a user can switch between: every model of every provider
24
+ * that has a key, plus the active provider, grouped by provider. The active
25
+ * model is listed even when its provider's catalog no longer names it.
26
+ *
27
+ * @param config - Current config.
28
+ * @returns Groups in provider order, active provider first when it has no key.
29
+ */
30
+ export declare function acapLlmModelChoices(config: AcApLlmConfig): AcApLlmModelChoiceGroup[];
31
+ //# sourceMappingURL=AcApLlmModelChoices.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AcApLlmModelChoices.d.ts","sourceRoot":"","sources":["../../src/ui/AcApLlmModelChoices.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,aAAa,EAGnB,MAAM,kCAAkC,CAAA;AAIzC,8CAA8C;AAC9C,MAAM,WAAW,kBAAkB;IACjC,sCAAsC;IACtC,UAAU,EAAE,MAAM,CAAA;IAClB,qCAAqC;IACrC,OAAO,EAAE,MAAM,CAAA;IACf,qBAAqB;IACrB,KAAK,EAAE,MAAM,CAAA;IACb,6CAA6C;IAC7C,MAAM,EAAE,OAAO,CAAA;CAChB;AAED,mDAAmD;AACnD,MAAM,WAAW,uBAAuB;IACtC,mBAAmB;IACnB,UAAU,EAAE,MAAM,CAAA;IAClB,+BAA+B;IAC/B,KAAK,EAAE,MAAM,CAAA;IACb,+BAA+B;IAC/B,OAAO,EAAE,kBAAkB,EAAE,CAAA;CAC9B;AAED;;;;;;;GAOG;AACH,wBAAgB,mBAAmB,CACjC,MAAM,EAAE,aAAa,GACpB,uBAAuB,EAAE,CA+B3B"}
@@ -0,0 +1,68 @@
1
+ var __read = (this && this.__read) || function (o, n) {
2
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
3
+ if (!m) return o;
4
+ var i = m.call(o), r, ar = [], e;
5
+ try {
6
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
7
+ }
8
+ catch (error) { e = { error: error }; }
9
+ finally {
10
+ try {
11
+ if (r && !r.done && (m = i["return"])) m.call(i);
12
+ }
13
+ finally { if (e) throw e.error; }
14
+ }
15
+ return ar;
16
+ };
17
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
18
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
19
+ if (ar || !(i in from)) {
20
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
21
+ ar[i] = from[i];
22
+ }
23
+ }
24
+ return to.concat(ar || Array.prototype.slice.call(from));
25
+ };
26
+ import { acapLlmEffectiveModels, acapLlmFindProvider } from '../storage/AcApLlmConfigStore.js';
27
+ import { acapLlmModelLabel } from '../storage/AcApLlmModelCatalog.js';
28
+ import { acapLlmProviderLabel } from './AcApLlmProviderLabels.js';
29
+ /**
30
+ * Lists the models a user can switch between: every model of every provider
31
+ * that has a key, plus the active provider, grouped by provider. The active
32
+ * model is listed even when its provider's catalog no longer names it.
33
+ *
34
+ * @param config - Current config.
35
+ * @returns Groups in provider order, active provider first when it has no key.
36
+ */
37
+ export function acapLlmModelChoices(config) {
38
+ var activeProviderId = config.activeProviderId, activeModel = config.activeModel;
39
+ var ids = config.providers
40
+ .filter(function (provider) { return provider.apiKey.trim(); })
41
+ .map(function (provider) { return provider.id; });
42
+ if (!ids.includes(activeProviderId))
43
+ ids.unshift(activeProviderId);
44
+ return ids.flatMap(function (id) {
45
+ var provider = acapLlmFindProvider(config, id);
46
+ if (!provider)
47
+ return [];
48
+ var models = __spreadArray([], __read(acapLlmEffectiveModels(provider)), false);
49
+ if (id === activeProviderId &&
50
+ activeModel &&
51
+ !models.some(function (model) { return model.id === activeModel; })) {
52
+ models.push({ id: activeModel, vision: false });
53
+ }
54
+ return [
55
+ {
56
+ providerId: id,
57
+ label: acapLlmProviderLabel(provider),
58
+ options: models.map(function (model) { return ({
59
+ providerId: id,
60
+ modelId: model.id,
61
+ label: acapLlmModelLabel(model),
62
+ vision: model.vision
63
+ }); })
64
+ }
65
+ ];
66
+ });
67
+ }
68
+ //# sourceMappingURL=AcApLlmModelChoices.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AcApLlmModelChoices.js","sourceRoot":"","sources":["../../src/ui/AcApLlmModelChoices.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAAA,OAAO,EAEL,sBAAsB,EACtB,mBAAmB,EACpB,MAAM,kCAAkC,CAAA;AACzC,OAAO,EAAE,iBAAiB,EAAE,MAAM,mCAAmC,CAAA;AACrE,OAAO,EAAE,oBAAoB,EAAE,MAAM,4BAA4B,CAAA;AAwBjE;;;;;;;GAOG;AACH,MAAM,UAAU,mBAAmB,CACjC,MAAqB;IAEb,IAAA,gBAAgB,GAAkB,MAAM,iBAAxB,EAAE,WAAW,GAAK,MAAM,YAAX,CAAW;IAChD,IAAM,GAAG,GAAG,MAAM,CAAC,SAAS;SACzB,MAAM,CAAC,UAAA,QAAQ,IAAI,OAAA,QAAQ,CAAC,MAAM,CAAC,IAAI,EAAE,EAAtB,CAAsB,CAAC;SAC1C,GAAG,CAAC,UAAA,QAAQ,IAAI,OAAA,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