maka-agent 0.2.0-dev.11.20260831 → 0.2.0-dev.14.20260902

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 (226) hide show
  1. package/LICENSE +2 -2
  2. package/RUNTIME_HOST_PEER_DEPENDENCIES.rust.tsv +70 -0
  3. package/RUNTIME_HOST_PEER_THIRD_PARTY_NOTICES.txt +1839 -140
  4. package/THIRD_PARTY_NOTICES.txt +2 -2
  5. package/dist/acp/maka-acp-agent.js +6 -3
  6. package/dist/acp/session-registry.js +307 -0
  7. package/dist/acp/stdio-server.js +20 -1
  8. package/dist/cli-core.js +40 -3
  9. package/dist/mcp-capability-provider.js +1 -1
  10. package/dist/onboarding-catalog.js +3 -5
  11. package/dist/pi-transcript.js +21 -17
  12. package/dist/pi-tui-layout.js +4 -2
  13. package/dist/pi-tui-mcp-status.js +44 -130
  14. package/dist/pi-tui-pickers.js +11 -5
  15. package/dist/pi-tui-runner.js +133 -102
  16. package/dist/runtime-host-access-command.js +37 -4
  17. package/dist/runtime-host-capability-provider-command.js +16 -2
  18. package/dist/runtime-host-cli-context.js +73 -3
  19. package/dist/runtime-host-cli.js +187 -10
  20. package/dist/runtime-host-lifecycle-transaction.js +5 -2
  21. package/dist/runtime-host-managed-lifecycle-manager.js +1 -0
  22. package/dist/runtime-host-onboarding.js +12 -16
  23. package/dist/runtime-host-peer-management-command.js +16 -4
  24. package/dist/runtime-host-plugin-command.js +101 -0
  25. package/dist/runtime-host-run-command.js +8 -2
  26. package/dist/runtime-host-service-management-command.js +2 -1
  27. package/dist/runtime-host-setup-command.js +1 -0
  28. package/dist/runtime-host-task-readiness.js +2 -3
  29. package/dist/runtime-host-tui-command.js +1 -1
  30. package/dist/runtime-host-tui-context.js +18 -5
  31. package/dist/runtime-host-update-command.js +71 -35
  32. package/dist/runtime-host-update-discovery.js +1 -0
  33. package/dist/tui-clipboard.js +86 -0
  34. package/dist/tui-copy-catalog.js +248 -0
  35. package/dist/tui-copy-command.js +103 -0
  36. package/native/runtime-host-peer/prebuilds/darwin-arm64/maka_runtime_host_peer.node +0 -0
  37. package/native/runtime-host-peer/prebuilds/linux-arm64/maka_runtime_host_peer.node +0 -0
  38. package/native/runtime-host-peer/prebuilds/linux-x64/maka_runtime_host_peer.node +0 -0
  39. package/native/runtime-host-peer/prebuilds/win32-x64/maka_runtime_host_peer.node +0 -0
  40. package/node_modules/@maka/core/dist/attachments.js +92 -1
  41. package/node_modules/@maka/core/dist/bounded-response.js +71 -0
  42. package/node_modules/@maka/core/dist/chat-model-choice.js +8 -33
  43. package/node_modules/@maka/core/dist/client-capability-grant.js +149 -0
  44. package/node_modules/@maka/core/dist/connection-error-copy.js +17 -34
  45. package/node_modules/@maka/core/dist/connection-readiness.js +3 -31
  46. package/node_modules/@maka/core/dist/deep-research.js +1 -20
  47. package/node_modules/@maka/core/dist/events.js +22 -14
  48. package/node_modules/@maka/core/dist/foreign-session.js +2 -2
  49. package/node_modules/@maka/core/dist/interaction.js +49 -2
  50. package/node_modules/@maka/core/dist/llm-connections.js +74 -82
  51. package/node_modules/@maka/core/dist/maka-wordmark.js +23 -0
  52. package/node_modules/@maka/core/dist/model-catalog.js +242 -315
  53. package/node_modules/@maka/core/dist/model-facts.js +13 -19
  54. package/node_modules/@maka/core/dist/model-metadata.generated.js +1907 -1872
  55. package/node_modules/@maka/core/dist/model-metadata.js +184 -199
  56. package/node_modules/@maka/core/dist/model-thinking.js +1 -1
  57. package/node_modules/@maka/core/dist/models-dev-projection.js +302 -0
  58. package/node_modules/@maka/core/dist/models-dev-refresh.js +55 -0
  59. package/node_modules/@maka/core/dist/onboarding.js +2 -1
  60. package/node_modules/@maka/core/dist/provider-auth.js +47 -291
  61. package/node_modules/@maka/core/dist/provider-registry.js +68 -357
  62. package/node_modules/@maka/core/dist/runtime-event.js +5 -0
  63. package/node_modules/@maka/core/dist/runtime-policy/connection-catalog-codec.js +83 -18
  64. package/node_modules/@maka/core/dist/runtime-policy/credential-vault-codec.js +9 -1
  65. package/node_modules/@maka/core/dist/runtime-policy/model-catalog-entry-codec.js +84 -0
  66. package/node_modules/@maka/core/dist/runtime-policy/policy-codec.js +75 -0
  67. package/node_modules/@maka/core/dist/runtime-policy.js +5 -2
  68. package/node_modules/@maka/core/dist/session-send-projection.js +2 -1
  69. package/node_modules/@maka/core/dist/session-start-mode.js +42 -0
  70. package/node_modules/@maka/core/dist/session.js +120 -5
  71. package/node_modules/@maka/core/dist/settings.js +10 -2
  72. package/node_modules/@maka/core/dist/slash-command-catalog.js +1 -0
  73. package/node_modules/@maka/core/dist/task-submission-readiness.js +2 -1
  74. package/node_modules/@maka/core/dist/usage-record-schema.js +11 -1
  75. package/node_modules/@maka/core/dist/workhub-creation-intent.js +896 -0
  76. package/node_modules/@maka/core/package.json +8 -2
  77. package/node_modules/@maka/mcp/dist/index.js +1 -0
  78. package/node_modules/@maka/runtime/dist/agent-run.js +7 -0
  79. package/node_modules/@maka/runtime/dist/ai-sdk-backend.js +55 -82
  80. package/node_modules/@maka/runtime/dist/ai-sdk-compaction.js +178 -140
  81. package/node_modules/@maka/runtime/dist/archive-read-tool.js +26 -5
  82. package/node_modules/@maka/runtime/dist/builtin-tools.js +27 -2
  83. package/node_modules/@maka/runtime/dist/context-budget-policy.js +0 -12
  84. package/node_modules/@maka/runtime/dist/conversation-copy.js +66 -43
  85. package/node_modules/@maka/runtime/dist/durable-tool-result-projection.js +31 -0
  86. package/node_modules/@maka/runtime/dist/history-compact-error.js +10 -2
  87. package/node_modules/@maka/runtime/dist/history-compact-input-fit.js +7 -1
  88. package/node_modules/@maka/runtime/dist/history-compaction.js +13 -22
  89. package/node_modules/@maka/runtime/dist/image-file.js +5 -20
  90. package/node_modules/@maka/runtime/dist/local-web-fetch.js +2 -43
  91. package/node_modules/@maka/runtime/dist/mcp-tools.js +28 -0
  92. package/node_modules/@maka/runtime/dist/model-fetcher.js +15 -8
  93. package/node_modules/@maka/runtime/dist/model-history.js +59 -17
  94. package/node_modules/@maka/runtime/dist/model-runtime.js +2 -2
  95. package/node_modules/@maka/runtime/dist/plugin-composition-loader.js +173 -20
  96. package/node_modules/@maka/runtime/dist/plugin-runtime.js +219 -0
  97. package/node_modules/@maka/runtime/dist/provider-image-overflow-recovery.js +12 -31
  98. package/node_modules/@maka/runtime/dist/quiescent-session-snapshot.js +78 -0
  99. package/node_modules/@maka/runtime/dist/runtime-event-backfill.js +6 -0
  100. package/node_modules/@maka/runtime/dist/runtime-event-read-model.js +14 -2
  101. package/node_modules/@maka/runtime/dist/session-event-runtime-mapper.js +11 -10
  102. package/node_modules/@maka/runtime/dist/shell-tools.js +77 -1
  103. package/node_modules/@maka/runtime/dist/telemetry/model-pricing.generated.js +93 -83
  104. package/node_modules/@maka/runtime/dist/test-connection.js +6 -6
  105. package/node_modules/@maka/runtime/dist/tool-availability.js +74 -5
  106. package/node_modules/@maka/runtime/dist/tool-result-archive-resource.js +333 -52
  107. package/node_modules/@maka/runtime/dist/tool-result-archive-transition.js +34 -3
  108. package/node_modules/@maka/runtime/dist/tool-runtime.js +62 -6
  109. package/node_modules/@maka/runtime/dist/workers/filesystem-worker.js +39 -16
  110. package/node_modules/@maka/runtime/package.json +1 -0
  111. package/node_modules/@maka/runtime-host/dist/adapter/session-projector.js +10 -3
  112. package/node_modules/@maka/runtime-host/dist/client/catalog-reader.js +59 -18
  113. package/node_modules/@maka/runtime-host/dist/client/client-capability-channel.js +3 -2
  114. package/node_modules/@maka/runtime-host/dist/client/connection.js +72 -31
  115. package/node_modules/@maka/runtime-host/dist/client/host-profile.js +49 -4
  116. package/node_modules/@maka/runtime-host/dist/client/index.js +3 -2
  117. package/node_modules/@maka/runtime-host/dist/client/oauth-presentation.js +1 -1
  118. package/node_modules/@maka/runtime-host/dist/client/owner-connection-code.js +32 -1
  119. package/node_modules/@maka/runtime-host/dist/client/peer-client.js +26 -4
  120. package/node_modules/@maka/runtime-host/dist/client/reconnecting-connection.js +8 -0
  121. package/node_modules/@maka/runtime-host/dist/operator/access-management-frame.js +10 -1
  122. package/node_modules/@maka/runtime-host/dist/operator/index.js +2 -1
  123. package/node_modules/@maka/runtime-host/dist/operator/managed-deployment.js +2 -0
  124. package/node_modules/@maka/runtime-host/dist/operator/peer-management-frame.js +2 -0
  125. package/node_modules/@maka/runtime-host/dist/operator/service-management-frame.js +2 -0
  126. package/node_modules/@maka/runtime-host/dist/peer-mesh/node.js +56 -12
  127. package/node_modules/@maka/runtime-host/dist/peer-mesh/owner.js +4 -0
  128. package/node_modules/@maka/runtime-host/dist/protocol/client-capability.js +22 -1
  129. package/node_modules/@maka/runtime-host/dist/protocol/configuration.js +55 -9
  130. package/node_modules/@maka/{storage/dist/task-ledger-store-internal.js → runtime-host/dist/protocol/connection-catalog-change.js} +7 -13
  131. package/node_modules/@maka/runtime-host/dist/protocol/host-status.js +37 -0
  132. package/node_modules/@maka/runtime-host/dist/protocol/index.js +49 -1
  133. package/node_modules/@maka/runtime-host/dist/protocol/network-proxy.js +1 -7
  134. package/node_modules/@maka/runtime-host/dist/protocol/operations.js +5 -1
  135. package/node_modules/@maka/runtime-host/dist/protocol/plugin-platform.js +512 -0
  136. package/node_modules/@maka/runtime-host/dist/protocol/runtime-policy.js +72 -61
  137. package/node_modules/@maka/runtime-host/dist/protocol/session-catalog.js +1 -1
  138. package/node_modules/@maka/runtime-host/dist/protocol/session-collaboration.js +4 -2
  139. package/node_modules/@maka/runtime-host/dist/protocol/turn.js +5 -12
  140. package/node_modules/@maka/runtime-host/dist/protocol/workhub-coordination.js +92 -4
  141. package/node_modules/@maka/runtime-host/dist/server/access-authority.js +17 -14
  142. package/node_modules/@maka/runtime-host/dist/server/access-credential-metadata.js +4 -2
  143. package/node_modules/@maka/runtime-host/dist/server/access-credential-store.js +119 -47
  144. package/node_modules/@maka/runtime-host/dist/server/agent-graph-execution-coordinator.js +1 -2
  145. package/node_modules/@maka/runtime-host/dist/server/bootstrap-runtime-policy.js +10 -4
  146. package/node_modules/@maka/runtime-host/dist/server/canonical-turn-snapshot.js +0 -9
  147. package/node_modules/@maka/runtime-host/dist/server/client-capability-coordinator.js +192 -18
  148. package/node_modules/@maka/runtime-host/dist/server/client-capability-invocation-broker.js +122 -48
  149. package/node_modules/@maka/runtime-host/dist/server/client-capability-provider-id.js +31 -0
  150. package/node_modules/@maka/runtime-host/dist/server/configuration-coordinator.js +20 -1
  151. package/node_modules/@maka/runtime-host/dist/server/connection-effect-coordinator.js +5 -5
  152. package/node_modules/@maka/runtime-host/dist/server/connection-session.js +1 -0
  153. package/node_modules/@maka/runtime-host/dist/server/execution-composition.js +163 -28
  154. package/node_modules/@maka/runtime-host/dist/server/execution-model-authority.js +2 -2
  155. package/node_modules/@maka/runtime-host/dist/server/execution-service.js +4 -1
  156. package/node_modules/@maka/runtime-host/dist/server/extension-bundle.js +249 -0
  157. package/node_modules/@maka/runtime-host/dist/server/extension-package-manifest.js +262 -0
  158. package/node_modules/@maka/runtime-host/dist/server/host-change-feed.js +11 -0
  159. package/node_modules/@maka/runtime-host/dist/server/host-kernel.js +15 -0
  160. package/node_modules/@maka/runtime-host/dist/server/index.js +5 -0
  161. package/node_modules/@maka/runtime-host/dist/server/interaction-coordinator.js +181 -13
  162. package/node_modules/@maka/runtime-host/dist/server/interaction-projection.js +6 -0
  163. package/node_modules/@maka/runtime-host/dist/server/listener-set.js +8 -4
  164. package/node_modules/@maka/runtime-host/dist/server/message-coordinator.js +88 -22
  165. package/node_modules/@maka/runtime-host/dist/server/model-metadata-refresh.js +96 -0
  166. package/node_modules/@maka/runtime-host/dist/server/network-proxy-coordinator.js +0 -1
  167. package/node_modules/@maka/runtime-host/dist/server/operation-dispatcher.js +43 -118
  168. package/node_modules/@maka/runtime-host/dist/server/peer-listener.js +3 -0
  169. package/node_modules/@maka/runtime-host/dist/server/plugin-composition-patch.js +58 -0
  170. package/node_modules/@maka/runtime-host/dist/server/plugin-composition-store.js +141 -0
  171. package/node_modules/@maka/runtime-host/dist/server/plugin-package-loader.js +130 -0
  172. package/node_modules/@maka/runtime-host/dist/server/plugin-package-store.js +528 -0
  173. package/node_modules/@maka/runtime-host/dist/server/plugin-platform-coordinator.js +249 -0
  174. package/node_modules/@maka/runtime-host/dist/server/plugin-platform.js +1130 -0
  175. package/node_modules/@maka/runtime-host/dist/server/root-admission-owner.js +4 -0
  176. package/node_modules/@maka/runtime-host/dist/server/root-turn-coordinator.js +24 -5
  177. package/node_modules/@maka/runtime-host/dist/server/runtime-policy-coordinator.js +57 -5
  178. package/node_modules/@maka/runtime-host/dist/server/session-catalog-coordinator.js +2 -1
  179. package/node_modules/@maka/runtime-host/dist/server/session-retirement-coordinator.js +3 -3
  180. package/node_modules/@maka/runtime-host/dist/server/session-revision-coordinator.js +35 -3
  181. package/node_modules/@maka/runtime-host/dist/server/session-sidecar-purge.js +16 -0
  182. package/node_modules/@maka/runtime-host/dist/server/session-transcript-pager.js +10 -2
  183. package/node_modules/@maka/runtime-host/dist/server/web-fetch-tool.js +1 -1
  184. package/node_modules/@maka/runtime-host/dist/server/workhub-coordination-action-gate.js +276 -3
  185. package/node_modules/@maka/runtime-host/dist/server/workhub-coordination-coordinator.js +101 -1
  186. package/node_modules/@maka/runtime-host/dist/transport/peer-native.js +1 -0
  187. package/node_modules/@maka/runtime-host/dist/webrtc-stun-policy.js +114 -0
  188. package/node_modules/@maka/runtime-host/package.json +2 -0
  189. package/node_modules/@maka/storage/dist/agent-run-store.js +4 -0
  190. package/node_modules/@maka/storage/dist/artifact-store.js +7 -23
  191. package/node_modules/@maka/storage/dist/conversation-operational-state.js +3 -0
  192. package/node_modules/@maka/storage/dist/execution-stores.js +3 -0
  193. package/node_modules/@maka/storage/dist/interaction-store-public.js +1 -1
  194. package/node_modules/@maka/storage/dist/interaction-store.js +173 -0
  195. package/node_modules/@maka/storage/dist/production-session-snapshot.js +761 -0
  196. package/node_modules/@maka/storage/dist/quiescent-session-snapshot.js +1 -1
  197. package/node_modules/@maka/storage/dist/runtime-policy/connection-catalog-document.js +19 -22
  198. package/node_modules/@maka/storage/dist/runtime-policy/coordinator.js +205 -42
  199. package/node_modules/@maka/storage/dist/runtime-policy/onboarding-transaction.js +2 -2
  200. package/node_modules/@maka/storage/dist/runtime-policy-stores.js +5 -2
  201. package/node_modules/@maka/storage/dist/session-message-projection.js +1 -1
  202. package/node_modules/@maka/storage/dist/session-store.js +32 -6
  203. package/node_modules/@maka/storage/dist/session-todo-store.js +6 -68
  204. package/node_modules/@maka/storage/dist/settings-store.js +16 -25
  205. package/node_modules/@maka/storage/dist/sqlite-core-execution-schema.js +19 -0
  206. package/node_modules/@maka/storage/dist/sqlite-session-metadata-schema.js +10 -1
  207. package/node_modules/@maka/storage/dist/sqlite-session-metadata-store.js +73 -3
  208. package/node_modules/@maka/storage/dist/sqlite-workflow-schema.js +2 -10
  209. package/node_modules/@maka/storage/package.json +2 -0
  210. package/node_modules/fast-uri/index.js +215 -47
  211. package/node_modules/fast-uri/lib/schemes.js +9 -4
  212. package/node_modules/fast-uri/lib/utils.js +396 -92
  213. package/node_modules/fast-uri/package.json +1 -1
  214. package/node_modules/qs/.github/THREAT_MODEL.md +3 -3
  215. package/node_modules/qs/CHANGELOG.md +15 -0
  216. package/node_modules/qs/README.md +19 -1
  217. package/node_modules/qs/dist/qs.js +21 -21
  218. package/node_modules/qs/eslint.config.mjs +1 -1
  219. package/node_modules/qs/lib/parse.js +3 -4
  220. package/node_modules/qs/lib/stringify.js +23 -8
  221. package/node_modules/qs/lib/utils.js +10 -3
  222. package/node_modules/qs/package.json +4 -4
  223. package/package.json +1 -1
  224. package/node_modules/@maka/core/dist/task-ledger.js +0 -669
  225. package/node_modules/@maka/storage/dist/task-ledger-authority.js +0 -121
  226. package/node_modules/@maka/storage/dist/task-ledger-store.js +0 -663
@@ -0,0 +1,249 @@
1
+ /*
2
+ * Licensed to the Apache Software Foundation (ASF) under one
3
+ * or more contributor license agreements. See the NOTICE file
4
+ * distributed with this work for additional information
5
+ * regarding copyright ownership. The ASF licenses this file
6
+ * to you under the Apache License, Version 2.0 (the
7
+ * "License"); you may not use this file except in compliance
8
+ * with the License. You may obtain a copy of the License at
9
+ *
10
+ * http://www.apache.org/licenses/LICENSE-2.0
11
+ *
12
+ * Unless required by applicable law or agreed to in writing,
13
+ * software distributed under the License is distributed on an
14
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15
+ * KIND, either express or implied. See the License for the
16
+ * specific language governing permissions and limitations
17
+ * under the License.
18
+ */
19
+ import { createHash } from 'node:crypto';
20
+ import { MakaPluginRuntimeError, } from '@maka/runtime/plugin-runtime';
21
+ import { PLUGIN_PLATFORM_QUERY_RESULT_MAX_BYTES } from '../protocol/plugin-platform.js';
22
+ import { ExtensionBundleError } from './extension-bundle.js';
23
+ import { ExtensionPackageManifestError } from './extension-package-manifest.js';
24
+ import { PluginCompositionPatchError } from './plugin-composition-patch.js';
25
+ import { PluginPackageLoaderError } from './plugin-package-loader.js';
26
+ import { PluginPackageStoreError } from './plugin-package-store.js';
27
+ import { HostPluginPlatformError } from './plugin-platform.js';
28
+ export class HostPluginPlatformCoordinator {
29
+ platform;
30
+ handlers = {
31
+ 'plugin.platform.query': (input) => this.#query(input),
32
+ 'plugin.package.install': (input) => this.#install(input),
33
+ 'plugin.package.uninstall': (input) => this.#uninstall(input),
34
+ 'plugin.package.reload': (input) => this.#reload(input),
35
+ 'plugin.package.export': (input) => this.#export(input),
36
+ 'plugin.composition.apply': (input) => this.#apply(input),
37
+ 'plugin.platform.reconcile': () => this.#reconcile(),
38
+ };
39
+ constructor(platform) {
40
+ this.platform = platform;
41
+ }
42
+ async #query(input) {
43
+ try {
44
+ return await this.platform.read(async () => {
45
+ const failures = this.platform.failures();
46
+ if (input.view === 'status') {
47
+ return {
48
+ ok: true,
49
+ result: {
50
+ view: 'status',
51
+ ...(await this.platform.status()),
52
+ },
53
+ };
54
+ }
55
+ if (input.view === 'entries') {
56
+ const inspections = flattenInspections(this.platform.inspect(input.rootId));
57
+ return { ok: true, result: boundedPage('entries', inspections, input) };
58
+ }
59
+ if (input.view === 'failures') {
60
+ return { ok: true, result: boundedPage('failures', failures, input) };
61
+ }
62
+ const packages = await this.platform.packageProjections();
63
+ return {
64
+ ok: true,
65
+ result: boundedPage('packages', packages, input),
66
+ };
67
+ });
68
+ }
69
+ catch (error) {
70
+ return failure(error);
71
+ }
72
+ }
73
+ async #install(input) {
74
+ try {
75
+ return { ok: true, result: await this.platform.installPackage(input.sourcePath) };
76
+ }
77
+ catch (error) {
78
+ return failure(error);
79
+ }
80
+ }
81
+ async #uninstall(input) {
82
+ try {
83
+ return { ok: true, result: await this.platform.uninstallPackage(input.extensionId) };
84
+ }
85
+ catch (error) {
86
+ return failure(error);
87
+ }
88
+ }
89
+ async #reload(input) {
90
+ try {
91
+ return { ok: true, result: await this.platform.reloadPackage(input.extensionId) };
92
+ }
93
+ catch (error) {
94
+ return failure(error);
95
+ }
96
+ }
97
+ async #export(input) {
98
+ try {
99
+ await this.platform.exportPackage(input.extensionId, input.targetPath);
100
+ return { ok: true, result: { targetPath: input.targetPath } };
101
+ }
102
+ catch (error) {
103
+ return failure(error);
104
+ }
105
+ }
106
+ async #apply(input) {
107
+ try {
108
+ return { ok: true, result: await this.platform.apply(input) };
109
+ }
110
+ catch (error) {
111
+ return failure(error);
112
+ }
113
+ }
114
+ async #reconcile() {
115
+ try {
116
+ return { ok: true, result: await this.platform.reconcile() };
117
+ }
118
+ catch (error) {
119
+ return failure(error);
120
+ }
121
+ }
122
+ }
123
+ function flattenInspections(inspections) {
124
+ const flattened = [];
125
+ const visit = (items) => {
126
+ for (const item of items) {
127
+ flattened.push(Object.freeze({ ...item, children: Object.freeze([]) }));
128
+ visit(item.children);
129
+ }
130
+ };
131
+ visit(inspections);
132
+ return Object.freeze(flattened);
133
+ }
134
+ function boundedPage(view, values, input) {
135
+ const digest = pageDigest(view, input.rootId, values);
136
+ const cursor = input.cursor === undefined ? 0 : decodeCursor(input.cursor, view, input.rootId, digest);
137
+ const limit = input.limit ?? 32;
138
+ if (cursor > values.length)
139
+ throw new HostPluginPlatformError('stale_cursor', 'Plugin Platform query cursor is stale');
140
+ const items = [];
141
+ for (let index = cursor; index < values.length && items.length < limit; index += 1) {
142
+ const candidate = [...items, values[index]];
143
+ if (Buffer.byteLength(JSON.stringify({
144
+ view,
145
+ items: candidate,
146
+ nextCursor: encodeCursor(view, input.rootId, digest, index + 1),
147
+ }), 'utf8') > PLUGIN_PLATFORM_QUERY_RESULT_MAX_BYTES) {
148
+ break;
149
+ }
150
+ items.push(values[index]);
151
+ }
152
+ if (cursor < values.length && items.length === 0) {
153
+ throw new MakaPluginRuntimeError('invalid_entry', 'Plugin Platform page item is too large');
154
+ }
155
+ const next = cursor + items.length;
156
+ return Object.freeze({
157
+ view,
158
+ items: Object.freeze(items),
159
+ nextCursor: next < values.length ? encodeCursor(view, input.rootId, digest, next) : null,
160
+ });
161
+ }
162
+ function pageDigest(view, rootId, values) {
163
+ return createHash('sha256')
164
+ .update(JSON.stringify({ view, rootId: rootId ?? null, values }))
165
+ .digest('base64url');
166
+ }
167
+ function encodeCursor(view, rootId, digest, offset) {
168
+ return Buffer.from(JSON.stringify({ version: 1, view, ...(rootId ? { rootId } : {}), digest, offset }), 'utf8').toString('base64url');
169
+ }
170
+ function decodeCursor(encoded, view, rootId, digest) {
171
+ try {
172
+ const cursor = JSON.parse(Buffer.from(encoded, 'base64url').toString('utf8'));
173
+ if (cursor.version !== 1 ||
174
+ cursor.view !== view ||
175
+ cursor.rootId !== rootId ||
176
+ cursor.digest !== digest ||
177
+ !Number.isSafeInteger(cursor.offset) ||
178
+ cursor.offset < 0) {
179
+ throw new Error('mismatch');
180
+ }
181
+ return cursor.offset;
182
+ }
183
+ catch {
184
+ throw new HostPluginPlatformError('stale_cursor', 'Plugin Platform query cursor is stale');
185
+ }
186
+ }
187
+ function failure(error) {
188
+ if (error instanceof HostPluginPlatformError) {
189
+ if (error.code === 'not_ready')
190
+ return failed('host_not_ready', error.message);
191
+ if (error.code === 'stale_cursor')
192
+ return failed('stale_cursor', error.message);
193
+ if (error.code === 'closed')
194
+ return failed('host_draining', error.message);
195
+ if (error.code === 'persistence_failed')
196
+ return failed('persistence_failed', error.message);
197
+ if (error.code === 'recovery_failed')
198
+ return failed('persistence_failed', error.message);
199
+ if (error.code === 'commit_outcome_unknown') {
200
+ return failed('commit_outcome_unknown', error.message);
201
+ }
202
+ if (error.code === 'mutation_failed' && error.cause)
203
+ return failure(error.cause);
204
+ return failed('internal_failure', error.message);
205
+ }
206
+ if (error instanceof PluginPackageStoreError) {
207
+ if (error.code === 'not_found')
208
+ return failed('not_found', error.message);
209
+ if (error.code === 'invalid_package')
210
+ return failed('invalid_request', error.message);
211
+ if (error.code === 'commit_outcome_unknown') {
212
+ return failed('commit_outcome_unknown', error.message);
213
+ }
214
+ return failed('persistence_failed', error.message);
215
+ }
216
+ if (error instanceof PluginPackageLoaderError) {
217
+ if (error.code === 'not_found')
218
+ return failed('not_found', error.message);
219
+ if (error.code === 'invalid_package')
220
+ return failed('invalid_request', error.message);
221
+ return failed('persistence_failed', error.message);
222
+ }
223
+ if (error instanceof ExtensionBundleError ||
224
+ error instanceof ExtensionPackageManifestError ||
225
+ error instanceof PluginCompositionPatchError) {
226
+ return failed('invalid_request', error.message);
227
+ }
228
+ if (error instanceof MakaPluginRuntimeError) {
229
+ switch (error.code) {
230
+ case 'package_not_found':
231
+ case 'entry_not_found':
232
+ return failed('not_found', error.message);
233
+ case 'package_exists':
234
+ case 'package_in_use':
235
+ case 'entry_exists':
236
+ return failed('operation_conflict', error.message);
237
+ case 'invalid_package':
238
+ case 'invalid_entry':
239
+ case 'dependency_cycle':
240
+ return failed('invalid_request', error.message);
241
+ default:
242
+ return failed('internal_failure', error.message);
243
+ }
244
+ }
245
+ return failed('internal_failure', 'Plugin Platform operation failed');
246
+ }
247
+ function failed(code, message) {
248
+ return { ok: false, error: { code, message } };
249
+ }