@inquir/compute 0.3.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. package/README.md +161 -6
  2. package/dist/app-observability.d.ts +69 -0
  3. package/dist/app-observability.d.ts.map +1 -0
  4. package/dist/app-observability.js +65 -0
  5. package/dist/app-observability.js.map +1 -0
  6. package/dist/app-observability.types.d.ts +358 -0
  7. package/dist/app-observability.types.d.ts.map +1 -0
  8. package/dist/app-observability.types.js +2 -0
  9. package/dist/app-observability.types.js.map +1 -0
  10. package/dist/apps.d.ts +73 -1
  11. package/dist/apps.d.ts.map +1 -1
  12. package/dist/apps.js +16 -0
  13. package/dist/apps.js.map +1 -1
  14. package/dist/build-timeout-policy.d.ts +13 -0
  15. package/dist/build-timeout-policy.d.ts.map +1 -0
  16. package/dist/build-timeout-policy.js +11 -0
  17. package/dist/build-timeout-policy.js.map +1 -0
  18. package/dist/index.d.ts +6 -0
  19. package/dist/index.d.ts.map +1 -1
  20. package/dist/index.js +5 -0
  21. package/dist/index.js.map +1 -1
  22. package/dist/invocation-observation.d.ts +23 -0
  23. package/dist/invocation-observation.d.ts.map +1 -0
  24. package/dist/invocation-observation.js +79 -0
  25. package/dist/invocation-observation.js.map +1 -0
  26. package/dist/projects.d.ts +10 -1
  27. package/dist/projects.d.ts.map +1 -1
  28. package/dist/projects.js +13 -1
  29. package/dist/projects.js.map +1 -1
  30. package/dist/release-commands.d.ts +80 -0
  31. package/dist/release-commands.d.ts.map +1 -0
  32. package/dist/release-commands.js +147 -0
  33. package/dist/release-commands.js.map +1 -0
  34. package/dist/source-command-http.d.ts +7 -0
  35. package/dist/source-command-http.d.ts.map +1 -0
  36. package/dist/source-command-http.js +87 -0
  37. package/dist/source-command-http.js.map +1 -0
  38. package/dist/source-command-protocol.d.ts +137 -0
  39. package/dist/source-command-protocol.d.ts.map +1 -0
  40. package/dist/source-command-protocol.js +311 -0
  41. package/dist/source-command-protocol.js.map +1 -0
  42. package/dist/source-commands.d.ts +33 -0
  43. package/dist/source-commands.d.ts.map +1 -0
  44. package/dist/source-commands.js +116 -0
  45. package/dist/source-commands.js.map +1 -0
  46. package/dist/transport.d.ts +27 -2
  47. package/dist/transport.d.ts.map +1 -1
  48. package/dist/transport.js +56 -7
  49. package/dist/transport.js.map +1 -1
  50. package/package.json +10 -10
package/README.md CHANGED
@@ -2,14 +2,18 @@
2
2
 
3
3
  Workspace-first SDK for defining, discovering, generating, and running Inquir Compute assets.
4
4
 
5
- ## Install
6
-
7
- Requires Node.js 22 or newer. Version 0.3 groups only long-lived container applications in projects; functions and pipelines remain separate assets.
5
+ ## Install
6
+
7
+ Requires Node.js 22 or newer. Version 0.3 groups only long-lived container applications in projects; functions and pipelines remain separate assets.
8
8
 
9
9
  ```bash
10
- npm install @inquir/compute zod@^3.23.8
10
+ npm install @inquir/compute zod@^3.23.8
11
11
  ```
12
12
 
13
+ > Release order: publish this SDK before the CLI that depends on it. CLI 0.4.0
14
+ > needs SDK 0.4.0 (`isPromoteAccepted`, `getApplicationRollout`); see
15
+ > `packages/cli/README.md`, "Publishing to npm".
16
+
13
17
  ## What It Includes
14
18
 
15
19
  - `defineFunction()` and `definePipeline()` for code-first assets.
@@ -17,8 +21,82 @@ npm install @inquir/compute zod@^3.23.8
17
21
  - `discoverAssets()` for workspace asset scanning.
18
22
  - `generateCodegenArtifacts()` / `generateAndWriteCodegenArtifacts()` for typed client + `registry.json`.
19
23
  - `runLocally()` for local function execution/debug harness.
20
- - HTTP transport helpers (`createClient`, `invokeRemote`, deploy/list helpers).
21
- - Application project helpers (`listProjects`, `createProject`, `getProject`, `addProjectResource`) group long-lived containers: web services, APIs, databases, and workers. Project members use `kind: 'application'`; serverless functions are managed separately. `createApplication` accepts `projectId` (ID or slug); omitting it creates a project named after the application.
24
+ - HTTP transport helpers (`createClient`, `invokeRemote`, deploy/list helpers).
25
+ - Application project helpers (`listProjects`, `createProject`, `getProject`, `addProjectResource`) group long-lived containers: web services, APIs, databases, and workers. Project members use `kind: 'application'`; serverless functions are managed separately. `createApplication` accepts `projectId` (ID or slug); omitting it creates a project named after the application. Archiving a project also archives all its applications, including an application shared with another project. Removing a membership leaves it running. Project lifecycle actions require `projects:write` and `apps:promote`.
26
+
27
+ ## Pending synchronous invocations
28
+
29
+ When the server admits a finite cold invocation, `invokeRemote()` submits once
30
+ and follows only the authenticated invocation's `/resume` endpoint. Hot
31
+ invocations keep their existing path. Save each handle from `onPending` if the
32
+ caller must survive a restart:
33
+
34
+ ```ts
35
+ import { invokeRemote, resumeRemoteInvocation, cancelRemoteInvocation,
36
+ RemoteInvocationObservationEndedError } from '@inquir/compute';
37
+
38
+ try {
39
+ const result = await invokeRemote(client, 'my-function', event, {
40
+ timeoutMs: 120_000, signal, onPending: saveHandle,
41
+ });
42
+ } catch (error) {
43
+ if (error instanceof RemoteInvocationObservationEndedError) {
44
+ saveHandle(error.pending); // PENDING/RECOVERY_HELD is not FAILED.
45
+ // Later: await resumeRemoteInvocation(client, error.pending);
46
+ // Explicit intent: await cancelRemoteInvocation(client, error.pending);
47
+ } else throw error;
48
+ }
49
+ ```
50
+
51
+ Abort/timeout stops observation, not execution. A cancellation receipt records
52
+ intent, not a terminal outcome. If the initial POST reply is lost before a handle
53
+ arrives, this adapter cannot recover an unknown server ID and never repeats that
54
+ POST. Server admission remains independently gated; this client does not enable
55
+ gateway, pipeline, durable or streaming finite execution.
56
+
57
+ ## Durable source commands
58
+
59
+ Source execution uses an explicit operation instead of synchronous writable
60
+ `/exec`. Save a lowercase UUID v4 before preparing, and atomically retain every
61
+ record supplied by the callback in private storage. Records contain command/env
62
+ secrets; they contain a credential hash rather than the credential itself.
63
+
64
+ ```ts
65
+ import { createClient, prepareSourceCommand, restoreSourceCommand } from '@inquir/compute';
66
+
67
+ const client = createClient({ baseUrl: apiUrl, apiKey, workspaceId });
68
+ const operation = await prepareSourceCommand(client, {
69
+ function: 'my-function', requestId: savedUuid,
70
+ input: { command: 'npm install', timeoutMs: 60_000 },
71
+ retain: savePrivateRecordAtomically,
72
+ });
73
+ await operation.submit(); // no automatic POST retry
74
+ const state = await operation.status(); // GET only
75
+ const publication = await operation.reconcile(); // explicit source publication
76
+ // await operation.cancel(); // explicit cancellation intent
77
+ const restored = await restoreSourceCommand(client, savedRecord, {
78
+ retain: savePrivateRecordAtomically,
79
+ }); // no HTTP or submission
80
+ ```
81
+
82
+ The retained API, credential hash, original workspace selector and resolved
83
+ workspace/function IDs must match on restore. Later actions stay pinned to those
84
+ IDs even if the client changes. A lost response keeps the same operation UUID;
85
+ inspect status or explicitly retry the same action. Poll timeout/abort stops
86
+ observation and does not cancel or publish. `EXITED` and `CANCEL_REQUESTED` do not
87
+ prove physical removal or capacity release. A GET with `publication: null` does
88
+ not prove that an earlier explicit publication never happened.
89
+
90
+ Acceptance identity is retained before an action returns and after each poll
91
+ response. If storage fails, further HTTP is blocked until the pending record is
92
+ saved; `operation.persist()` retries storage without HTTP. Keep the updated
93
+ record returned by `record()` for reloads. The server must enable the source
94
+ command API after its activation gates; a 503 never falls back to writable exec.
95
+
96
+ `result.logFailure` and `sourcePublicationState(outcome) === 'CAPTURE_FAILED'`
97
+ mark unavailable log capture, preserving the real termination and exit code.
98
+ Blank Base64 fields then mean unavailable capture rather than successful empty
99
+ logs; workspace output is absent and cannot be published.
22
100
 
23
101
  ## Concepts
24
102
 
@@ -98,3 +176,80 @@ const client = createClient({ baseUrl: 'http://localhost:3000', apiKey: process.
98
176
  const response = await invokeRemote(client, 'hello', { name: 'World' });
99
177
  ```
100
178
 
179
+ ## Readonly published-release commands (scoped rollout)
180
+
181
+ `prepareReleaseCommand` retains the caller's original UUID, workspace and command
182
+ before the first HTTP submission. It uses the dedicated readonly release API;
183
+ it does not invoke the writable source-command API or a function handler.
184
+
185
+ ```ts
186
+ import { randomUUID } from 'node:crypto';
187
+ import { prepareReleaseCommand, restoreReleaseCommand } from '@inquir/compute';
188
+
189
+ const operation = await prepareReleaseCommand(client, {
190
+ functionId,
191
+ requestId: randomUUID(),
192
+ input: { command: 'cat package.json', timeoutMs: 60_000 },
193
+ retain: async record => saveCommandRecord(record), // Durable caller storage.
194
+ });
195
+ const first = await operation.submit(); // Submit once. Keep the retained record on a lost reply.
196
+ const outcome = first.state === 'PENDING' || first.state === 'RECOVERY_HELD'
197
+ ? await restoreReleaseCommand(client, operation.record()).observe()
198
+ : first;
199
+ ```
200
+
201
+ Observation resumes the same ID and never repeats the initial POST. An expired
202
+ or aborted observer keeps that handle; `operation.cancel()` separately requests
203
+ durable cancellation. Cancellation acknowledgement is an intent, while `REMOVED`
204
+ is a validated terminal result after physical task/container cleanup. Scope or
205
+ artifact uncertainty remains held rather than becoming a fabricated failure.
206
+ `CANCELLED_WITHOUT_CONTAINER` separately proves an admitted reservation was
207
+ cancelled and physically retired before CREATE; its `result` is `null` because
208
+ no shell ran. `CANCELLED_BEFORE_ADMISSION` has no reservation to retire.
209
+
210
+ This path is disabled by default. Each exact runtime image, readonly process,
211
+ source/input mount, resource and network profile must receive native
212
+ qualification before its scoped operator approval and rollout switches enable
213
+ admission. The initial source tests do not constitute that qualification.
214
+
215
+ ## Application observability
216
+
217
+ The SDK exposes resource and HTTP history, persisted runtime/HTTP logs and configurable app alerts. Every helper uses the client's credentials and workspace selector:
218
+
219
+ ```ts
220
+ import {
221
+ createClient, getAppMetrics, getAppHttpMetrics, getAppLogHistory,
222
+ createAppAlertRule, updateAppAlertRule, listAppAlertIncidents,
223
+ } from '@inquir/compute';
224
+
225
+ const client = createClient({
226
+ baseUrl: 'https://inquir.org/api',
227
+ apiKey: process.env.INQUIR_TOKEN,
228
+ workspaceId: process.env.INQUIR_WORKSPACE,
229
+ });
230
+ const to = new Date().toISOString();
231
+ const from = new Date(Date.now() - 60 * 60 * 1000).toISOString();
232
+ const resources = await getAppMetrics(client, appId, { from, to });
233
+ const http = await getAppHttpMetrics(client, appId, { from, to });
234
+ const logs = await getAppLogHistory(client, appId, {
235
+ from, to, releaseId, allocationId, allocationFence: 4, level: 'error', limit: 100,
236
+ });
237
+ if (logs.nextCursor) {
238
+ const older = await getAppLogHistory(client, appId, {
239
+ from: logs.from, to: logs.to, releaseId, allocationId, allocationFence: 4,
240
+ level: 'error', limit: 100, cursor: logs.nextCursor,
241
+ });
242
+ }
243
+
244
+ const { rule } = await createAppAlertRule(client, appId, {
245
+ name: 'High RAM', enabled: true, metric: 'memory_percent',
246
+ threshold: 85, forSeconds: 120, recoveryThreshold: 65,
247
+ recoveryForSeconds: 60, noDataSeconds: 180, noData: 'alert', channels: [],
248
+ });
249
+ await updateAppAlertRule(client, appId, rule.id, { threshold: 90 });
250
+ const { incidents } = await listAppAlertIncidents(client, appId, { limit: 25 });
251
+ ```
252
+
253
+ `getAppHttpLogHistory`, `listAppAlertRules` and `deleteAppAlertRule` complete the API. Deletion disables the rule and resolves its active incidents; retained history is still available. Omit `channels` in a patch to preserve existing destinations, or pass an empty array to remove them. `webhook`/`slack` channel URLs are write-only; response types expose only channel id, type and configured status. Never log alert request inputs containing a secret URL.
254
+
255
+ Resource and HTTP retention is 30 days; runtime logs are retained for 7 days. Runtime history is attributed to the exact release, allocation/fence, runner/epoch and container, including replaced containers. Paging is newest-first and requires an unchanged date window and filters. Resource history retains unavailable values as `null`; use `status`, `latestSampleAt` and `truncated` to detect stale or incomplete results. Network and block I/O rates are measured separately; block I/O is not volume space usage. CPU/RAM alert percentages are relative to enforced limits, and the continuous maximum across current production replicas determines threshold firing.
@@ -0,0 +1,69 @@
1
+ import { type TransportClient } from './transport.js';
2
+ import type { AppMetricsHistoryResponse, AppHttpMetricsResponse, AppLogHistoryResponse, AppRuntimeLogEntry, AppHttpLogEntry, AppAlertRuleInput, AppAlertRuleDto, AppAlertIncidentDto, AppResourceRecommendationResponse, AppDescribeResponse } from './app-observability.types.js';
3
+ export * from './app-observability.types.js';
4
+ /** ISO 8601 timestamps. Preserve the same window when following a log cursor. */
5
+ export interface AppObservationRange {
6
+ from?: string;
7
+ to?: string;
8
+ }
9
+ export interface AppRuntimeLogQuery extends AppObservationRange {
10
+ limit?: number;
11
+ cursor?: string;
12
+ releaseId?: string;
13
+ allocationId?: string;
14
+ allocationFence?: number;
15
+ runnerId?: string;
16
+ runnerEpoch?: number;
17
+ containerId?: string;
18
+ stream?: AppRuntimeLogEntry['stream'];
19
+ level?: Exclude<AppRuntimeLogEntry['level'], null>;
20
+ search?: string;
21
+ }
22
+ export interface AppHttpLogQuery extends AppObservationRange {
23
+ limit?: number;
24
+ cursor?: string;
25
+ releaseId?: string;
26
+ statusCode?: number;
27
+ query?: string;
28
+ }
29
+ /** Actual resource history, up to 30 days; CPU/RAM percentages use enforced limits. */
30
+ export declare function getAppMetrics(client: TransportClient, appId: string, range?: AppObservationRange): Promise<AppMetricsHistoryResponse>;
31
+ /**
32
+ * Read-only CPU/RAM right-sizing advice from observed usage over the last
33
+ * `days` days (1 to 7, default 7). Nothing changes until the figures are
34
+ * applied with an application update and a redeploy.
35
+ */
36
+ export declare function getAppResourceRecommendation(client: TransportClient, appId: string, options?: {
37
+ days?: number;
38
+ }): Promise<AppResourceRecommendationResponse>;
39
+ /**
40
+ * Why the application is (not) running: conditions of the application, its
41
+ * releases, replica attempts and runners, the plan capacity and recent events.
42
+ * Read-only.
43
+ */
44
+ export declare function describeApp(client: TransportClient, appId: string): Promise<AppDescribeResponse>;
45
+ /** HTTP gateway observations; private TCP traffic is not HTTP request telemetry. */
46
+ export declare function getAppHttpMetrics(client: TransportClient, appId: string, range?: AppObservationRange): Promise<AppHttpMetricsResponse>;
47
+ /** One descending timestamp/id page of persisted runtime logs (7-day retention). */
48
+ export declare function getAppLogHistory(client: TransportClient, appId: string, query?: AppRuntimeLogQuery): Promise<AppLogHistoryResponse<AppRuntimeLogEntry>>;
49
+ /** One descending timestamp/id page of HTTP access logs (30-day retention). */
50
+ export declare function getAppHttpLogHistory(client: TransportClient, appId: string, query?: AppHttpLogQuery): Promise<AppLogHistoryResponse<AppHttpLogEntry>>;
51
+ export declare function listAppAlertRules(client: TransportClient, appId: string): Promise<{
52
+ rules: AppAlertRuleDto[];
53
+ }>;
54
+ /** URLs are write-only secrets. Returned channels contain only id/type/configured. */
55
+ export declare function createAppAlertRule(client: TransportClient, appId: string, input: AppAlertRuleInput): Promise<{
56
+ rule: AppAlertRuleDto;
57
+ }>;
58
+ /** Omit channels to keep configured destinations; [] removes them. */
59
+ export declare function updateAppAlertRule(client: TransportClient, appId: string, ruleId: string, input: Partial<AppAlertRuleInput>): Promise<{
60
+ rule: AppAlertRuleDto;
61
+ }>;
62
+ /** Disables the rule and resolves its incidents; history is retained. No response body. */
63
+ export declare function deleteAppAlertRule(client: TransportClient, appId: string, ruleId: string): Promise<void>;
64
+ export declare function listAppAlertIncidents(client: TransportClient, appId: string, options?: {
65
+ limit?: number;
66
+ }): Promise<{
67
+ incidents: AppAlertIncidentDto[];
68
+ }>;
69
+ //# sourceMappingURL=app-observability.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"app-observability.d.ts","sourceRoot":"","sources":["../src/app-observability.ts"],"names":[],"mappings":"AAAA,OAAO,EAAc,KAAK,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAClE,OAAO,KAAK,EACV,yBAAyB,EAAE,sBAAsB,EAAE,qBAAqB,EACxE,kBAAkB,EAAE,eAAe,EAAE,iBAAiB,EAAE,eAAe,EAAE,mBAAmB,EAC5F,iCAAiC,EAAE,mBAAmB,EACvD,MAAM,8BAA8B,CAAC;AAEtC,cAAc,8BAA8B,CAAC;AAE7C,iFAAiF;AACjF,MAAM,WAAW,mBAAmB;IAAG,IAAI,CAAC,EAAE,MAAM,CAAC;IAAC,EAAE,CAAC,EAAE,MAAM,CAAA;CAAE;AACnE,MAAM,WAAW,kBAAmB,SAAQ,mBAAmB;IAC7D,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,YAAY,CAAC,EAAE,MAAM,CAAC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';
3
+ function appPath(id, suffix) {
4
+ return `/v1/apps/${encodeURIComponent(id)}/${suffix}`;
5
+ }
6
+ function queryString(options) {
7
+ const query = new URLSearchParams();
8
+ for (const [key, value] of Object.entries(options)) {
9
+ // Zero is significant (notably runner epoch); unknown observations remain null in responses.
10
+ if (value !== undefined)
11
+ query.set(key, String(value));
12
+ }
13
+ return query.size ? `?${query}` : '';
14
+ }
15
+ /** Actual resource history, up to 30 days; CPU/RAM percentages use enforced limits. */
16
+ export function getAppMetrics(client, appId, range = {}) {
17
+ return rawRequest(client, 'GET', appPath(appId, 'metrics') + queryString(range));
18
+ }
19
+ /**
20
+ * Read-only CPU/RAM right-sizing advice from observed usage over the last
21
+ * `days` days (1 to 7, default 7). Nothing changes until the figures are
22
+ * applied with an application update and a redeploy.
23
+ */
24
+ export function getAppResourceRecommendation(client, appId, options = {}) {
25
+ return rawRequest(client, 'GET', appPath(appId, 'resources/recommendation') + queryString(options));
26
+ }
27
+ /**
28
+ * Why the application is (not) running: conditions of the application, its
29
+ * releases, replica attempts and runners, the plan capacity and recent events.
30
+ * Read-only.
31
+ */
32
+ export function describeApp(client, appId) {
33
+ return rawRequest(client, 'GET', appPath(appId, 'describe'));
34
+ }
35
+ /** HTTP gateway observations; private TCP traffic is not HTTP request telemetry. */
36
+ export function getAppHttpMetrics(client, appId, range = {}) {
37
+ return rawRequest(client, 'GET', appPath(appId, 'http-metrics') + queryString(range));
38
+ }
39
+ /** One descending timestamp/id page of persisted runtime logs (7-day retention). */
40
+ export function getAppLogHistory(client, appId, query = {}) {
41
+ return rawRequest(client, 'GET', appPath(appId, 'logs/runtime') + queryString(query));
42
+ }
43
+ /** One descending timestamp/id page of HTTP access logs (30-day retention). */
44
+ export function getAppHttpLogHistory(client, appId, query = {}) {
45
+ return rawRequest(client, 'GET', appPath(appId, 'http-logs') + queryString(query));
46
+ }
47
+ export function listAppAlertRules(client, appId) {
48
+ return rawRequest(client, 'GET', appPath(appId, 'alert-rules'));
49
+ }
50
+ /** URLs are write-only secrets. Returned channels contain only id/type/configured. */
51
+ export function createAppAlertRule(client, appId, input) {
52
+ return rawRequest(client, 'POST', appPath(appId, 'alert-rules'), input);
53
+ }
54
+ /** Omit channels to keep configured destinations; [] removes them. */
55
+ export function updateAppAlertRule(client, appId, ruleId, input) {
56
+ return rawRequest(client, 'PATCH', appPath(appId, `alert-rules/${encodeURIComponent(ruleId)}`), input);
57
+ }
58
+ /** Disables the rule and resolves its incidents; history is retained. No response body. */
59
+ export async function deleteAppAlertRule(client, appId, ruleId) {
60
+ await rawRequest(client, 'DELETE', appPath(appId, `alert-rules/${encodeURIComponent(ruleId)}`));
61
+ }
62
+ export function listAppAlertIncidents(client, appId, options = {}) {
63
+ return rawRequest(client, 'GET', appPath(appId, 'alert-incidents') + queryString(options));
64
+ }
65
+ //# sourceMappingURL=app-observability.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"app-observability.js","sourceRoot":"","sources":["../src/app-observability.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAwB,MAAM,gBAAgB,CAAC;AAOlE,cAAc,8BAA8B,CAAC;AAyB7C,SAAS,OAAO,CAAC,EAAU,EAAE,MAAc;IACzC,OAAO,YAAY,kBAAkB,CAAC,EAAE,CAAC,IAAI,MAAM,EAAE,CAAC;AACxD,CAAC;AACD,SAAS,WAAW,CAAC,OAAe;IAClC,MAAM,KAAK,GAAG,IAAI,eAAe,EAAE,CAAC;IACpC,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC;QACnD,6FAA6F;QAC7F,IAAI,KAAK,KAAK,SAAS;YAAE,KAAK,CAAC,GAAG,CAAC,GAAG,EAAE,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;IACzD,CAAC;IACD,OAAO,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;AACvC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