@nomux-sh/extension 0.1.2 → 0.1.3
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 +9 -1
- package/dist/api-version.d.ts +9 -2
- package/dist/api-version.js +14 -3
- package/dist/extension.d.ts +15 -0
- package/dist/extension.js +22 -1
- package/dist/handshake.d.ts +6 -2
- package/dist/handshake.js +2 -2
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -130,7 +130,15 @@ To examine a package before the installation, run `nomux ext validate <directory
|
|
|
130
130
|
|
|
131
131
|
## Version rule
|
|
132
132
|
|
|
133
|
-
The version of this package is
|
|
133
|
+
The version of this package is not the extension API version. `API_VERSION` is the extension API version that the package implements: 0.1.1. It changes only when the protocol or the manifest format changes.
|
|
134
|
+
|
|
135
|
+
An extension asks the host for `^` and the lowest version that it needs. By default, this is `MINIMUM_API_VERSION`: 0.1.0. Thus an extension built with a new release of the package also runs on an earlier host. If the extension uses a feature of a later version, state the version, and give `api` in `extension.toml` the same minimum:
|
|
136
|
+
|
|
137
|
+
```ts
|
|
138
|
+
new Extension("nomux.agent-tool", "0.1.0").requiresApi({ major: 0, minor: 1, patch: 1 }); // api = "^0.1.1"
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
The [version rule](https://github.com/nomux-sh/extension-api/blob/main/spec/extension-protocol.md#version-rule) of the protocol applies.
|
|
134
142
|
|
|
135
143
|
## License
|
|
136
144
|
|
package/dist/api-version.d.ts
CHANGED
|
@@ -1,10 +1,17 @@
|
|
|
1
1
|
import type { ApiVersion } from "./generated/nomux/extension/v1/handshake.js";
|
|
2
2
|
export type { ApiVersion };
|
|
3
3
|
/**
|
|
4
|
-
* The extension API version that this package implements.
|
|
5
|
-
*
|
|
4
|
+
* The extension API version that this package implements. The extension sends
|
|
5
|
+
* it in `Welcome`. It changes only when the protocol or the manifest format
|
|
6
|
+
* changes. It is not the version of the package.
|
|
6
7
|
*/
|
|
7
8
|
export declare const API_VERSION: Readonly<ApiVersion>;
|
|
9
|
+
/**
|
|
10
|
+
* The lowest extension API version that has each feature that the SDK uses.
|
|
11
|
+
* An extension asks the host for this version, unless it states a later
|
|
12
|
+
* version with `Extension.requiresApi`.
|
|
13
|
+
*/
|
|
14
|
+
export declare const MINIMUM_API_VERSION: Readonly<ApiVersion>;
|
|
8
15
|
/** Formats a version as `major.minor.patch`. */
|
|
9
16
|
export declare function formatVersion(version: ApiVersion): string;
|
|
10
17
|
/**
|
package/dist/api-version.js
CHANGED
|
@@ -1,11 +1,22 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* The extension API version that this package implements.
|
|
3
|
-
*
|
|
2
|
+
* The extension API version that this package implements. The extension sends
|
|
3
|
+
* it in `Welcome`. It changes only when the protocol or the manifest format
|
|
4
|
+
* changes. It is not the version of the package.
|
|
4
5
|
*/
|
|
5
6
|
export const API_VERSION = Object.freeze({
|
|
6
7
|
major: 0,
|
|
7
8
|
minor: 1,
|
|
8
|
-
patch:
|
|
9
|
+
patch: 1,
|
|
10
|
+
});
|
|
11
|
+
/**
|
|
12
|
+
* The lowest extension API version that has each feature that the SDK uses.
|
|
13
|
+
* An extension asks the host for this version, unless it states a later
|
|
14
|
+
* version with `Extension.requiresApi`.
|
|
15
|
+
*/
|
|
16
|
+
export const MINIMUM_API_VERSION = Object.freeze({
|
|
17
|
+
major: 0,
|
|
18
|
+
minor: 1,
|
|
19
|
+
patch: 0,
|
|
9
20
|
});
|
|
10
21
|
/** Formats a version as `major.minor.patch`. */
|
|
11
22
|
export function formatVersion(version) {
|
package/dist/extension.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { Readable, Writable } from "node:stream";
|
|
2
|
+
import type { ApiVersion } from "./api-version.js";
|
|
2
3
|
import type { Call } from "./call.js";
|
|
3
4
|
import type { MethodCodecs } from "./codec.js";
|
|
4
5
|
import type { Host } from "./host.js";
|
|
@@ -23,6 +24,7 @@ type Initialize = (host: Host) => void | Promise<void>;
|
|
|
23
24
|
export declare class Extension {
|
|
24
25
|
private readonly id;
|
|
25
26
|
private readonly version;
|
|
27
|
+
private api;
|
|
26
28
|
private readonly methods;
|
|
27
29
|
private initializer;
|
|
28
30
|
private isInitialized;
|
|
@@ -34,6 +36,19 @@ export declare class Extension {
|
|
|
34
36
|
* from its manifest.
|
|
35
37
|
*/
|
|
36
38
|
constructor(id: string, version: string);
|
|
39
|
+
/**
|
|
40
|
+
* States the lowest extension API version that the extension needs. The
|
|
41
|
+
* default is {@link MINIMUM_API_VERSION}. State a later version only if the
|
|
42
|
+
* extension uses a feature of that version, and give `api` in
|
|
43
|
+
* `extension.toml` the same minimum: version 0.1.1 and `api = "^0.1.1"`.
|
|
44
|
+
*
|
|
45
|
+
* The extension refuses a host whose version does not match the caret
|
|
46
|
+
* requirement of `version`.
|
|
47
|
+
*
|
|
48
|
+
* Throws if the SDK does not implement `version`: if the caret requirement
|
|
49
|
+
* of `version` does not match {@link API_VERSION}.
|
|
50
|
+
*/
|
|
51
|
+
requiresApi(version: ApiVersion): this;
|
|
37
52
|
/**
|
|
38
53
|
* Adds a method that the host can call.
|
|
39
54
|
*
|
package/dist/extension.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import process from "node:process";
|
|
2
|
+
import { API_VERSION, MINIMUM_API_VERSION, formatVersion, isCompatible } from "./api-version.js";
|
|
2
3
|
import { Connection } from "./connection.js";
|
|
3
4
|
import { CallError, ErrorCode } from "./error.js";
|
|
4
5
|
import { decode } from "./host.js";
|
|
@@ -16,6 +17,7 @@ import { decode } from "./host.js";
|
|
|
16
17
|
export class Extension {
|
|
17
18
|
id;
|
|
18
19
|
version;
|
|
20
|
+
api = MINIMUM_API_VERSION;
|
|
19
21
|
methods = new Map();
|
|
20
22
|
initializer;
|
|
21
23
|
isInitialized = false;
|
|
@@ -30,6 +32,25 @@ export class Extension {
|
|
|
30
32
|
this.id = id;
|
|
31
33
|
this.version = version;
|
|
32
34
|
}
|
|
35
|
+
/**
|
|
36
|
+
* States the lowest extension API version that the extension needs. The
|
|
37
|
+
* default is {@link MINIMUM_API_VERSION}. State a later version only if the
|
|
38
|
+
* extension uses a feature of that version, and give `api` in
|
|
39
|
+
* `extension.toml` the same minimum: version 0.1.1 and `api = "^0.1.1"`.
|
|
40
|
+
*
|
|
41
|
+
* The extension refuses a host whose version does not match the caret
|
|
42
|
+
* requirement of `version`.
|
|
43
|
+
*
|
|
44
|
+
* Throws if the SDK does not implement `version`: if the caret requirement
|
|
45
|
+
* of `version` does not match {@link API_VERSION}.
|
|
46
|
+
*/
|
|
47
|
+
requiresApi(version) {
|
|
48
|
+
if (!isCompatible(version, API_VERSION)) {
|
|
49
|
+
throw new Error(`the SDK implements the extension API version ${formatVersion(API_VERSION)}, not ${formatVersion(version)}`);
|
|
50
|
+
}
|
|
51
|
+
this.api = { ...version };
|
|
52
|
+
return this;
|
|
53
|
+
}
|
|
33
54
|
/**
|
|
34
55
|
* Adds a method that the host can call.
|
|
35
56
|
*
|
|
@@ -78,7 +99,7 @@ export class Extension {
|
|
|
78
99
|
* request. Use it to test an extension in the process of the test.
|
|
79
100
|
*/
|
|
80
101
|
serve(input, output) {
|
|
81
|
-
const identity = { id: this.id, version: this.version };
|
|
102
|
+
const identity = { id: this.id, version: this.version, api: this.api };
|
|
82
103
|
return new Connection(input, output, identity, (work, call) => this.answer(work, call)).run();
|
|
83
104
|
}
|
|
84
105
|
async answer(work, call) {
|
package/dist/handshake.d.ts
CHANGED
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
import { RunError } from "./error.js";
|
|
2
2
|
import type { Envelope, Response } from "./generated/nomux/extension/v1/envelope.js";
|
|
3
|
-
import type { Permissions } from "./generated/nomux/extension/v1/handshake.js";
|
|
4
|
-
/**
|
|
3
|
+
import type { ApiVersion, Permissions } from "./generated/nomux/extension/v1/handshake.js";
|
|
4
|
+
/**
|
|
5
|
+
* The identifier and the version of the extension, and the lowest extension
|
|
6
|
+
* API version that it needs.
|
|
7
|
+
*/
|
|
5
8
|
export interface Identity {
|
|
6
9
|
readonly id: string;
|
|
7
10
|
readonly version: string;
|
|
11
|
+
readonly api: ApiVersion;
|
|
8
12
|
}
|
|
9
13
|
/** The answer to the first message of the host. */
|
|
10
14
|
export interface HandshakeAnswer {
|
package/dist/handshake.js
CHANGED
|
@@ -11,8 +11,8 @@ export function answerHello(envelope, identity) {
|
|
|
11
11
|
}
|
|
12
12
|
const hello = request.body.value;
|
|
13
13
|
const host = hello.apiVersion ?? { major: 0, minor: 0, patch: 0 };
|
|
14
|
-
if (!isCompatible(
|
|
15
|
-
const message = `the extension needs the extension API version ^${formatVersion(
|
|
14
|
+
if (!isCompatible(identity.api, host)) {
|
|
15
|
+
const message = `the extension needs the extension API version ^${formatVersion(identity.api)}, but the host supplies ${formatVersion(host)}`;
|
|
16
16
|
return {
|
|
17
17
|
response: {
|
|
18
18
|
id: request.id,
|
package/dist/index.d.ts
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
*
|
|
9
9
|
* @packageDocumentation
|
|
10
10
|
*/
|
|
11
|
-
export { API_VERSION, isCompatible } from "./api-version.js";
|
|
11
|
+
export { API_VERSION, MINIMUM_API_VERSION, isCompatible } from "./api-version.js";
|
|
12
12
|
export type { ApiVersion } from "./api-version.js";
|
|
13
13
|
export type { Call } from "./call.js";
|
|
14
14
|
export { bytes } from "./codec.js";
|
package/dist/index.js
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
*
|
|
9
9
|
* @packageDocumentation
|
|
10
10
|
*/
|
|
11
|
-
export { API_VERSION, isCompatible } from "./api-version.js";
|
|
11
|
+
export { API_VERSION, MINIMUM_API_VERSION, isCompatible } from "./api-version.js";
|
|
12
12
|
export { bytes } from "./codec.js";
|
|
13
13
|
export { CallError, ErrorCode, RunError } from "./error.js";
|
|
14
14
|
export { Extension } from "./extension.js";
|