@openvcs/sdk 0.2.3 → 0.2.4
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/README.md +30 -1
- package/lib/init.d.ts +2 -0
- package/lib/init.js +6 -3
- package/lib/runtime/contracts.d.ts +45 -0
- package/lib/runtime/contracts.js +4 -0
- package/lib/runtime/dispatcher.d.ts +16 -0
- package/lib/runtime/dispatcher.js +133 -0
- package/lib/runtime/errors.d.ts +5 -0
- package/lib/runtime/errors.js +26 -0
- package/lib/runtime/host.d.ts +10 -0
- package/lib/runtime/host.js +48 -0
- package/lib/runtime/index.d.ts +9 -0
- package/lib/runtime/index.js +166 -0
- package/lib/runtime/transport.d.ts +14 -0
- package/lib/runtime/transport.js +72 -0
- package/lib/types/host.d.ts +57 -0
- package/lib/types/host.js +4 -0
- package/lib/types/index.d.ts +4 -0
- package/lib/types/index.js +22 -0
- package/lib/types/plugin.d.ts +56 -0
- package/lib/types/plugin.js +4 -0
- package/lib/types/protocol.d.ts +77 -0
- package/lib/types/protocol.js +13 -0
- package/lib/types/vcs.d.ts +459 -0
- package/lib/types/vcs.js +4 -0
- package/package.json +14 -1
- package/src/lib/init.ts +6 -3
- package/src/lib/runtime/contracts.ts +52 -0
- package/src/lib/runtime/dispatcher.ts +185 -0
- package/src/lib/runtime/errors.ts +27 -0
- package/src/lib/runtime/host.ts +72 -0
- package/src/lib/runtime/index.ts +201 -0
- package/src/lib/runtime/transport.ts +93 -0
- package/src/lib/types/host.ts +71 -0
- package/src/lib/types/index.ts +7 -0
- package/src/lib/types/plugin.ts +110 -0
- package/src/lib/types/protocol.ts +97 -0
- package/src/lib/types/vcs.ts +579 -0
- package/test/init.test.js +25 -0
- package/test/runtime.test.js +118 -0
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
// Copyright © 2025-2026 OpenVCS Contributors
|
|
2
|
+
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
3
|
+
|
|
4
|
+
import type { RequestParams, RpcMethodHandler } from './protocol';
|
|
5
|
+
|
|
6
|
+
/** Describes the capability flags reported during plugin initialization. */
|
|
7
|
+
export interface PluginImplements {
|
|
8
|
+
/** Indicates whether the plugin responds to `plugin.*` methods. */
|
|
9
|
+
plugin: boolean;
|
|
10
|
+
/** Indicates whether the plugin responds to `vcs.*` methods. */
|
|
11
|
+
vcs: boolean;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/** Describes the handshake payload returned from `plugin.initialize`. */
|
|
15
|
+
export interface PluginInitializeResult {
|
|
16
|
+
/** Stores the SDK protocol version mirrored from the host. */
|
|
17
|
+
protocol_version: number;
|
|
18
|
+
/** Stores the feature groups implemented by the plugin. */
|
|
19
|
+
implements: PluginImplements;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/** Describes one optional override returned by a custom initialize handler. */
|
|
23
|
+
export type PluginInitializeOverride = Partial<PluginInitializeResult>;
|
|
24
|
+
|
|
25
|
+
/** Describes one plugin-contributed menu definition. */
|
|
26
|
+
export type PluginMenuDefinition = Record<string, unknown>;
|
|
27
|
+
|
|
28
|
+
/** Describes one plugin settings value payload. */
|
|
29
|
+
export type PluginSettingsValue = Record<string, unknown>;
|
|
30
|
+
|
|
31
|
+
/** Describes the params shape for plugin action handling. */
|
|
32
|
+
export interface PluginHandleActionParams extends RequestParams {
|
|
33
|
+
/** Stores the action id selected by the user. */
|
|
34
|
+
action_id?: string;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** Describes the params shape for plugin settings callbacks. */
|
|
38
|
+
export interface PluginSettingsValuesParams extends RequestParams {
|
|
39
|
+
/** Stores the list of values supplied by the host. */
|
|
40
|
+
values?: unknown[];
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** Enumerates all host `plugin.*` method names. */
|
|
44
|
+
export type PluginMethodName =
|
|
45
|
+
| 'plugin.initialize'
|
|
46
|
+
| 'plugin.init'
|
|
47
|
+
| 'plugin.deinit'
|
|
48
|
+
| 'plugin.get_menus'
|
|
49
|
+
| 'plugin.handle_action'
|
|
50
|
+
| 'plugin.settings.defaults'
|
|
51
|
+
| 'plugin.settings.on_load'
|
|
52
|
+
| 'plugin.settings.on_apply'
|
|
53
|
+
| 'plugin.settings.on_save'
|
|
54
|
+
| 'plugin.settings.on_reset';
|
|
55
|
+
|
|
56
|
+
/** Describes the delegate map supported by the SDK runtime for `plugin.*`. */
|
|
57
|
+
export interface PluginDelegates<TContext = unknown> {
|
|
58
|
+
/** Overrides the default handshake payload returned by `plugin.initialize`. */
|
|
59
|
+
'plugin.initialize'?: RpcMethodHandler<
|
|
60
|
+
RequestParams,
|
|
61
|
+
PluginInitializeOverride,
|
|
62
|
+
TContext
|
|
63
|
+
>;
|
|
64
|
+
/** Handles plugin startup work. */
|
|
65
|
+
'plugin.init'?: RpcMethodHandler<RequestParams, null, TContext>;
|
|
66
|
+
/** Handles plugin shutdown work. */
|
|
67
|
+
'plugin.deinit'?: RpcMethodHandler<RequestParams, null, TContext>;
|
|
68
|
+
/** Returns plugin-contributed menus. */
|
|
69
|
+
'plugin.get_menus'?: RpcMethodHandler<
|
|
70
|
+
RequestParams,
|
|
71
|
+
PluginMenuDefinition[],
|
|
72
|
+
TContext
|
|
73
|
+
>;
|
|
74
|
+
/** Handles a contributed plugin action. */
|
|
75
|
+
'plugin.handle_action'?: RpcMethodHandler<
|
|
76
|
+
PluginHandleActionParams,
|
|
77
|
+
null,
|
|
78
|
+
TContext
|
|
79
|
+
>;
|
|
80
|
+
/** Returns the default settings values for the plugin. */
|
|
81
|
+
'plugin.settings.defaults'?: RpcMethodHandler<
|
|
82
|
+
RequestParams,
|
|
83
|
+
PluginSettingsValue[],
|
|
84
|
+
TContext
|
|
85
|
+
>;
|
|
86
|
+
/** Transforms settings values when they are loaded. */
|
|
87
|
+
'plugin.settings.on_load'?: RpcMethodHandler<
|
|
88
|
+
PluginSettingsValuesParams,
|
|
89
|
+
unknown[],
|
|
90
|
+
TContext
|
|
91
|
+
>;
|
|
92
|
+
/** Applies settings values to the running plugin. */
|
|
93
|
+
'plugin.settings.on_apply'?: RpcMethodHandler<
|
|
94
|
+
PluginSettingsValuesParams,
|
|
95
|
+
null,
|
|
96
|
+
TContext
|
|
97
|
+
>;
|
|
98
|
+
/** Transforms settings values before they are saved. */
|
|
99
|
+
'plugin.settings.on_save'?: RpcMethodHandler<
|
|
100
|
+
PluginSettingsValuesParams,
|
|
101
|
+
unknown[],
|
|
102
|
+
TContext
|
|
103
|
+
>;
|
|
104
|
+
/** Resets plugin settings state. */
|
|
105
|
+
'plugin.settings.on_reset'?: RpcMethodHandler<
|
|
106
|
+
PluginSettingsValuesParams,
|
|
107
|
+
null,
|
|
108
|
+
TContext
|
|
109
|
+
>;
|
|
110
|
+
}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
// Copyright © 2025-2026 OpenVCS Contributors
|
|
2
|
+
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
3
|
+
|
|
4
|
+
/** Stores the protocol version mirrored from the backend host contract. */
|
|
5
|
+
export const PROTOCOL_VERSION = 1;
|
|
6
|
+
|
|
7
|
+
/** Stores the reserved JSON-RPC error code used for plugin failures. */
|
|
8
|
+
export const PLUGIN_FAILURE_CODE = -32001;
|
|
9
|
+
|
|
10
|
+
/** Stores the reserved JSON-RPC error code used for uncaught plugin errors. */
|
|
11
|
+
export const PLUGIN_INTERNAL_ERROR_CODE = -32002;
|
|
12
|
+
|
|
13
|
+
/** Stores the reserved JSON-RPC error code used for protocol version mismatches. */
|
|
14
|
+
export const PROTOCOL_VERSION_MISMATCH_CODE = -32003;
|
|
15
|
+
|
|
16
|
+
/** Represents a JSON-RPC request identifier. */
|
|
17
|
+
export type JsonRpcId = number | string;
|
|
18
|
+
|
|
19
|
+
/** Represents an untyped JSON-RPC parameter object. */
|
|
20
|
+
export type RequestParams = Record<string, unknown>;
|
|
21
|
+
|
|
22
|
+
/** Describes one JSON-RPC error payload. */
|
|
23
|
+
export interface JsonRpcError {
|
|
24
|
+
/** Stores the machine-readable error code. */
|
|
25
|
+
code: number;
|
|
26
|
+
/** Stores the human-readable error message. */
|
|
27
|
+
message: string;
|
|
28
|
+
/** Stores optional structured error details. */
|
|
29
|
+
data?: unknown;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** Describes one JSON-RPC request received from the host. */
|
|
33
|
+
export interface JsonRpcRequest {
|
|
34
|
+
/** Stores the JSON-RPC protocol marker when present. */
|
|
35
|
+
jsonrpc?: string;
|
|
36
|
+
/** Stores the request identifier used to match responses. */
|
|
37
|
+
id?: JsonRpcId;
|
|
38
|
+
/** Stores the requested method name. */
|
|
39
|
+
method?: unknown;
|
|
40
|
+
/** Stores the untyped parameter payload. */
|
|
41
|
+
params?: unknown;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** Describes one JSON-RPC notification emitted without an id. */
|
|
45
|
+
export interface JsonRpcNotification {
|
|
46
|
+
/** Stores the JSON-RPC protocol marker. */
|
|
47
|
+
jsonrpc: '2.0';
|
|
48
|
+
/** Stores the notification method name. */
|
|
49
|
+
method: string;
|
|
50
|
+
/** Stores the notification payload. */
|
|
51
|
+
params?: unknown;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/** Describes one JSON-RPC success response. */
|
|
55
|
+
export interface JsonRpcSuccessResponse<TResult = unknown> {
|
|
56
|
+
/** Stores the JSON-RPC protocol marker. */
|
|
57
|
+
jsonrpc: '2.0';
|
|
58
|
+
/** Stores the request identifier being answered. */
|
|
59
|
+
id: JsonRpcId;
|
|
60
|
+
/** Stores the successful result payload. */
|
|
61
|
+
result: TResult;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/** Describes one JSON-RPC error response. */
|
|
65
|
+
export interface JsonRpcErrorResponse {
|
|
66
|
+
/** Stores the JSON-RPC protocol marker. */
|
|
67
|
+
jsonrpc: '2.0';
|
|
68
|
+
/** Stores the request identifier being answered. */
|
|
69
|
+
id: JsonRpcId;
|
|
70
|
+
/** Stores the structured error payload. */
|
|
71
|
+
error: JsonRpcError;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/** Describes one plugin-specific failure payload surfaced to the host. */
|
|
75
|
+
export interface PluginFailure {
|
|
76
|
+
/** Stores the reserved JSON-RPC error code for plugin failures. */
|
|
77
|
+
code: typeof PLUGIN_FAILURE_CODE;
|
|
78
|
+
/** Stores the top-level failure message. */
|
|
79
|
+
message: string;
|
|
80
|
+
/** Stores nested plugin-specific failure details. */
|
|
81
|
+
data: PluginFailureData;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/** Describes the structured data embedded in a plugin failure. */
|
|
85
|
+
export interface PluginFailureData {
|
|
86
|
+
/** Stores the stable plugin-specific error code. */
|
|
87
|
+
code: string;
|
|
88
|
+
/** Stores the user-facing failure message. */
|
|
89
|
+
message: string;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/** Describes one method handler used by the SDK delegate runtime. */
|
|
93
|
+
export type RpcMethodHandler<
|
|
94
|
+
TParams extends RequestParams = RequestParams,
|
|
95
|
+
TResult = unknown,
|
|
96
|
+
TContext = unknown,
|
|
97
|
+
> = (params: TParams, context: TContext) => TResult | Promise<TResult>;
|