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.
- package/LICENSE +2 -2
- package/RUNTIME_HOST_PEER_DEPENDENCIES.rust.tsv +70 -0
- package/RUNTIME_HOST_PEER_THIRD_PARTY_NOTICES.txt +1839 -140
- package/THIRD_PARTY_NOTICES.txt +2 -2
- package/dist/acp/maka-acp-agent.js +6 -3
- package/dist/acp/session-registry.js +307 -0
- package/dist/acp/stdio-server.js +20 -1
- package/dist/cli-core.js +40 -3
- package/dist/mcp-capability-provider.js +1 -1
- package/dist/onboarding-catalog.js +3 -5
- package/dist/pi-transcript.js +21 -17
- package/dist/pi-tui-layout.js +4 -2
- package/dist/pi-tui-mcp-status.js +44 -130
- package/dist/pi-tui-pickers.js +11 -5
- package/dist/pi-tui-runner.js +133 -102
- package/dist/runtime-host-access-command.js +37 -4
- package/dist/runtime-host-capability-provider-command.js +16 -2
- package/dist/runtime-host-cli-context.js +73 -3
- package/dist/runtime-host-cli.js +187 -10
- package/dist/runtime-host-lifecycle-transaction.js +5 -2
- package/dist/runtime-host-managed-lifecycle-manager.js +1 -0
- package/dist/runtime-host-onboarding.js +12 -16
- package/dist/runtime-host-peer-management-command.js +16 -4
- package/dist/runtime-host-plugin-command.js +101 -0
- package/dist/runtime-host-run-command.js +8 -2
- package/dist/runtime-host-service-management-command.js +2 -1
- package/dist/runtime-host-setup-command.js +1 -0
- package/dist/runtime-host-task-readiness.js +2 -3
- package/dist/runtime-host-tui-command.js +1 -1
- package/dist/runtime-host-tui-context.js +18 -5
- package/dist/runtime-host-update-command.js +71 -35
- package/dist/runtime-host-update-discovery.js +1 -0
- package/dist/tui-clipboard.js +86 -0
- package/dist/tui-copy-catalog.js +248 -0
- package/dist/tui-copy-command.js +103 -0
- package/native/runtime-host-peer/prebuilds/darwin-arm64/maka_runtime_host_peer.node +0 -0
- package/native/runtime-host-peer/prebuilds/linux-arm64/maka_runtime_host_peer.node +0 -0
- package/native/runtime-host-peer/prebuilds/linux-x64/maka_runtime_host_peer.node +0 -0
- package/native/runtime-host-peer/prebuilds/win32-x64/maka_runtime_host_peer.node +0 -0
- package/node_modules/@maka/core/dist/attachments.js +92 -1
- package/node_modules/@maka/core/dist/bounded-response.js +71 -0
- package/node_modules/@maka/core/dist/chat-model-choice.js +8 -33
- package/node_modules/@maka/core/dist/client-capability-grant.js +149 -0
- package/node_modules/@maka/core/dist/connection-error-copy.js +17 -34
- package/node_modules/@maka/core/dist/connection-readiness.js +3 -31
- package/node_modules/@maka/core/dist/deep-research.js +1 -20
- package/node_modules/@maka/core/dist/events.js +22 -14
- package/node_modules/@maka/core/dist/foreign-session.js +2 -2
- package/node_modules/@maka/core/dist/interaction.js +49 -2
- package/node_modules/@maka/core/dist/llm-connections.js +74 -82
- package/node_modules/@maka/core/dist/maka-wordmark.js +23 -0
- package/node_modules/@maka/core/dist/model-catalog.js +242 -315
- package/node_modules/@maka/core/dist/model-facts.js +13 -19
- package/node_modules/@maka/core/dist/model-metadata.generated.js +1907 -1872
- package/node_modules/@maka/core/dist/model-metadata.js +184 -199
- package/node_modules/@maka/core/dist/model-thinking.js +1 -1
- package/node_modules/@maka/core/dist/models-dev-projection.js +302 -0
- package/node_modules/@maka/core/dist/models-dev-refresh.js +55 -0
- package/node_modules/@maka/core/dist/onboarding.js +2 -1
- package/node_modules/@maka/core/dist/provider-auth.js +47 -291
- package/node_modules/@maka/core/dist/provider-registry.js +68 -357
- package/node_modules/@maka/core/dist/runtime-event.js +5 -0
- package/node_modules/@maka/core/dist/runtime-policy/connection-catalog-codec.js +83 -18
- package/node_modules/@maka/core/dist/runtime-policy/credential-vault-codec.js +9 -1
- package/node_modules/@maka/core/dist/runtime-policy/model-catalog-entry-codec.js +84 -0
- package/node_modules/@maka/core/dist/runtime-policy/policy-codec.js +75 -0
- package/node_modules/@maka/core/dist/runtime-policy.js +5 -2
- package/node_modules/@maka/core/dist/session-send-projection.js +2 -1
- package/node_modules/@maka/core/dist/session-start-mode.js +42 -0
- package/node_modules/@maka/core/dist/session.js +120 -5
- package/node_modules/@maka/core/dist/settings.js +10 -2
- package/node_modules/@maka/core/dist/slash-command-catalog.js +1 -0
- package/node_modules/@maka/core/dist/task-submission-readiness.js +2 -1
- package/node_modules/@maka/core/dist/usage-record-schema.js +11 -1
- package/node_modules/@maka/core/dist/workhub-creation-intent.js +896 -0
- package/node_modules/@maka/core/package.json +8 -2
- package/node_modules/@maka/mcp/dist/index.js +1 -0
- package/node_modules/@maka/runtime/dist/agent-run.js +7 -0
- package/node_modules/@maka/runtime/dist/ai-sdk-backend.js +55 -82
- package/node_modules/@maka/runtime/dist/ai-sdk-compaction.js +178 -140
- package/node_modules/@maka/runtime/dist/archive-read-tool.js +26 -5
- package/node_modules/@maka/runtime/dist/builtin-tools.js +27 -2
- package/node_modules/@maka/runtime/dist/context-budget-policy.js +0 -12
- package/node_modules/@maka/runtime/dist/conversation-copy.js +66 -43
- package/node_modules/@maka/runtime/dist/durable-tool-result-projection.js +31 -0
- package/node_modules/@maka/runtime/dist/history-compact-error.js +10 -2
- package/node_modules/@maka/runtime/dist/history-compact-input-fit.js +7 -1
- package/node_modules/@maka/runtime/dist/history-compaction.js +13 -22
- package/node_modules/@maka/runtime/dist/image-file.js +5 -20
- package/node_modules/@maka/runtime/dist/local-web-fetch.js +2 -43
- package/node_modules/@maka/runtime/dist/mcp-tools.js +28 -0
- package/node_modules/@maka/runtime/dist/model-fetcher.js +15 -8
- package/node_modules/@maka/runtime/dist/model-history.js +59 -17
- package/node_modules/@maka/runtime/dist/model-runtime.js +2 -2
- package/node_modules/@maka/runtime/dist/plugin-composition-loader.js +173 -20
- package/node_modules/@maka/runtime/dist/plugin-runtime.js +219 -0
- package/node_modules/@maka/runtime/dist/provider-image-overflow-recovery.js +12 -31
- package/node_modules/@maka/runtime/dist/quiescent-session-snapshot.js +78 -0
- package/node_modules/@maka/runtime/dist/runtime-event-backfill.js +6 -0
- package/node_modules/@maka/runtime/dist/runtime-event-read-model.js +14 -2
- package/node_modules/@maka/runtime/dist/session-event-runtime-mapper.js +11 -10
- package/node_modules/@maka/runtime/dist/shell-tools.js +77 -1
- package/node_modules/@maka/runtime/dist/telemetry/model-pricing.generated.js +93 -83
- package/node_modules/@maka/runtime/dist/test-connection.js +6 -6
- package/node_modules/@maka/runtime/dist/tool-availability.js +74 -5
- package/node_modules/@maka/runtime/dist/tool-result-archive-resource.js +333 -52
- package/node_modules/@maka/runtime/dist/tool-result-archive-transition.js +34 -3
- package/node_modules/@maka/runtime/dist/tool-runtime.js +62 -6
- package/node_modules/@maka/runtime/dist/workers/filesystem-worker.js +39 -16
- package/node_modules/@maka/runtime/package.json +1 -0
- package/node_modules/@maka/runtime-host/dist/adapter/session-projector.js +10 -3
- package/node_modules/@maka/runtime-host/dist/client/catalog-reader.js +59 -18
- package/node_modules/@maka/runtime-host/dist/client/client-capability-channel.js +3 -2
- package/node_modules/@maka/runtime-host/dist/client/connection.js +72 -31
- package/node_modules/@maka/runtime-host/dist/client/host-profile.js +49 -4
- package/node_modules/@maka/runtime-host/dist/client/index.js +3 -2
- package/node_modules/@maka/runtime-host/dist/client/oauth-presentation.js +1 -1
- package/node_modules/@maka/runtime-host/dist/client/owner-connection-code.js +32 -1
- package/node_modules/@maka/runtime-host/dist/client/peer-client.js +26 -4
- package/node_modules/@maka/runtime-host/dist/client/reconnecting-connection.js +8 -0
- package/node_modules/@maka/runtime-host/dist/operator/access-management-frame.js +10 -1
- package/node_modules/@maka/runtime-host/dist/operator/index.js +2 -1
- package/node_modules/@maka/runtime-host/dist/operator/managed-deployment.js +2 -0
- package/node_modules/@maka/runtime-host/dist/operator/peer-management-frame.js +2 -0
- package/node_modules/@maka/runtime-host/dist/operator/service-management-frame.js +2 -0
- package/node_modules/@maka/runtime-host/dist/peer-mesh/node.js +56 -12
- package/node_modules/@maka/runtime-host/dist/peer-mesh/owner.js +4 -0
- package/node_modules/@maka/runtime-host/dist/protocol/client-capability.js +22 -1
- package/node_modules/@maka/runtime-host/dist/protocol/configuration.js +55 -9
- package/node_modules/@maka/{storage/dist/task-ledger-store-internal.js → runtime-host/dist/protocol/connection-catalog-change.js} +7 -13
- package/node_modules/@maka/runtime-host/dist/protocol/host-status.js +37 -0
- package/node_modules/@maka/runtime-host/dist/protocol/index.js +49 -1
- package/node_modules/@maka/runtime-host/dist/protocol/network-proxy.js +1 -7
- package/node_modules/@maka/runtime-host/dist/protocol/operations.js +5 -1
- package/node_modules/@maka/runtime-host/dist/protocol/plugin-platform.js +512 -0
- package/node_modules/@maka/runtime-host/dist/protocol/runtime-policy.js +72 -61
- package/node_modules/@maka/runtime-host/dist/protocol/session-catalog.js +1 -1
- package/node_modules/@maka/runtime-host/dist/protocol/session-collaboration.js +4 -2
- package/node_modules/@maka/runtime-host/dist/protocol/turn.js +5 -12
- package/node_modules/@maka/runtime-host/dist/protocol/workhub-coordination.js +92 -4
- package/node_modules/@maka/runtime-host/dist/server/access-authority.js +17 -14
- package/node_modules/@maka/runtime-host/dist/server/access-credential-metadata.js +4 -2
- package/node_modules/@maka/runtime-host/dist/server/access-credential-store.js +119 -47
- package/node_modules/@maka/runtime-host/dist/server/agent-graph-execution-coordinator.js +1 -2
- package/node_modules/@maka/runtime-host/dist/server/bootstrap-runtime-policy.js +10 -4
- package/node_modules/@maka/runtime-host/dist/server/canonical-turn-snapshot.js +0 -9
- package/node_modules/@maka/runtime-host/dist/server/client-capability-coordinator.js +192 -18
- package/node_modules/@maka/runtime-host/dist/server/client-capability-invocation-broker.js +122 -48
- package/node_modules/@maka/runtime-host/dist/server/client-capability-provider-id.js +31 -0
- package/node_modules/@maka/runtime-host/dist/server/configuration-coordinator.js +20 -1
- package/node_modules/@maka/runtime-host/dist/server/connection-effect-coordinator.js +5 -5
- package/node_modules/@maka/runtime-host/dist/server/connection-session.js +1 -0
- package/node_modules/@maka/runtime-host/dist/server/execution-composition.js +163 -28
- package/node_modules/@maka/runtime-host/dist/server/execution-model-authority.js +2 -2
- package/node_modules/@maka/runtime-host/dist/server/execution-service.js +4 -1
- package/node_modules/@maka/runtime-host/dist/server/extension-bundle.js +249 -0
- package/node_modules/@maka/runtime-host/dist/server/extension-package-manifest.js +262 -0
- package/node_modules/@maka/runtime-host/dist/server/host-change-feed.js +11 -0
- package/node_modules/@maka/runtime-host/dist/server/host-kernel.js +15 -0
- package/node_modules/@maka/runtime-host/dist/server/index.js +5 -0
- package/node_modules/@maka/runtime-host/dist/server/interaction-coordinator.js +181 -13
- package/node_modules/@maka/runtime-host/dist/server/interaction-projection.js +6 -0
- package/node_modules/@maka/runtime-host/dist/server/listener-set.js +8 -4
- package/node_modules/@maka/runtime-host/dist/server/message-coordinator.js +88 -22
- package/node_modules/@maka/runtime-host/dist/server/model-metadata-refresh.js +96 -0
- package/node_modules/@maka/runtime-host/dist/server/network-proxy-coordinator.js +0 -1
- package/node_modules/@maka/runtime-host/dist/server/operation-dispatcher.js +43 -118
- package/node_modules/@maka/runtime-host/dist/server/peer-listener.js +3 -0
- package/node_modules/@maka/runtime-host/dist/server/plugin-composition-patch.js +58 -0
- package/node_modules/@maka/runtime-host/dist/server/plugin-composition-store.js +141 -0
- package/node_modules/@maka/runtime-host/dist/server/plugin-package-loader.js +130 -0
- package/node_modules/@maka/runtime-host/dist/server/plugin-package-store.js +528 -0
- package/node_modules/@maka/runtime-host/dist/server/plugin-platform-coordinator.js +249 -0
- package/node_modules/@maka/runtime-host/dist/server/plugin-platform.js +1130 -0
- package/node_modules/@maka/runtime-host/dist/server/root-admission-owner.js +4 -0
- package/node_modules/@maka/runtime-host/dist/server/root-turn-coordinator.js +24 -5
- package/node_modules/@maka/runtime-host/dist/server/runtime-policy-coordinator.js +57 -5
- package/node_modules/@maka/runtime-host/dist/server/session-catalog-coordinator.js +2 -1
- package/node_modules/@maka/runtime-host/dist/server/session-retirement-coordinator.js +3 -3
- package/node_modules/@maka/runtime-host/dist/server/session-revision-coordinator.js +35 -3
- package/node_modules/@maka/runtime-host/dist/server/session-sidecar-purge.js +16 -0
- package/node_modules/@maka/runtime-host/dist/server/session-transcript-pager.js +10 -2
- package/node_modules/@maka/runtime-host/dist/server/web-fetch-tool.js +1 -1
- package/node_modules/@maka/runtime-host/dist/server/workhub-coordination-action-gate.js +276 -3
- package/node_modules/@maka/runtime-host/dist/server/workhub-coordination-coordinator.js +101 -1
- package/node_modules/@maka/runtime-host/dist/transport/peer-native.js +1 -0
- package/node_modules/@maka/runtime-host/dist/webrtc-stun-policy.js +114 -0
- package/node_modules/@maka/runtime-host/package.json +2 -0
- package/node_modules/@maka/storage/dist/agent-run-store.js +4 -0
- package/node_modules/@maka/storage/dist/artifact-store.js +7 -23
- package/node_modules/@maka/storage/dist/conversation-operational-state.js +3 -0
- package/node_modules/@maka/storage/dist/execution-stores.js +3 -0
- package/node_modules/@maka/storage/dist/interaction-store-public.js +1 -1
- package/node_modules/@maka/storage/dist/interaction-store.js +173 -0
- package/node_modules/@maka/storage/dist/production-session-snapshot.js +761 -0
- package/node_modules/@maka/storage/dist/quiescent-session-snapshot.js +1 -1
- package/node_modules/@maka/storage/dist/runtime-policy/connection-catalog-document.js +19 -22
- package/node_modules/@maka/storage/dist/runtime-policy/coordinator.js +205 -42
- package/node_modules/@maka/storage/dist/runtime-policy/onboarding-transaction.js +2 -2
- package/node_modules/@maka/storage/dist/runtime-policy-stores.js +5 -2
- package/node_modules/@maka/storage/dist/session-message-projection.js +1 -1
- package/node_modules/@maka/storage/dist/session-store.js +32 -6
- package/node_modules/@maka/storage/dist/session-todo-store.js +6 -68
- package/node_modules/@maka/storage/dist/settings-store.js +16 -25
- package/node_modules/@maka/storage/dist/sqlite-core-execution-schema.js +19 -0
- package/node_modules/@maka/storage/dist/sqlite-session-metadata-schema.js +10 -1
- package/node_modules/@maka/storage/dist/sqlite-session-metadata-store.js +73 -3
- package/node_modules/@maka/storage/dist/sqlite-workflow-schema.js +2 -10
- package/node_modules/@maka/storage/package.json +2 -0
- package/node_modules/fast-uri/index.js +215 -47
- package/node_modules/fast-uri/lib/schemes.js +9 -4
- package/node_modules/fast-uri/lib/utils.js +396 -92
- package/node_modules/fast-uri/package.json +1 -1
- package/node_modules/qs/.github/THREAT_MODEL.md +3 -3
- package/node_modules/qs/CHANGELOG.md +15 -0
- package/node_modules/qs/README.md +19 -1
- package/node_modules/qs/dist/qs.js +21 -21
- package/node_modules/qs/eslint.config.mjs +1 -1
- package/node_modules/qs/lib/parse.js +3 -4
- package/node_modules/qs/lib/stringify.js +23 -8
- package/node_modules/qs/lib/utils.js +10 -3
- package/node_modules/qs/package.json +4 -4
- package/package.json +1 -1
- package/node_modules/@maka/core/dist/task-ledger.js +0 -669
- package/node_modules/@maka/storage/dist/task-ledger-authority.js +0 -121
- 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
|
+
}
|