@vymalo/opencode-browser 0.12.0 → 0.14.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.
- package/dist/agent-client.d.ts +36 -36
- package/dist/agent-client.js +201 -189
- package/dist/agent-client.js.map +1 -1
- package/dist/broker.d.ts +85 -87
- package/dist/broker.js +614 -599
- package/dist/broker.js.map +1 -1
- package/dist/catalog.d.ts +76 -76
- package/dist/catalog.js +826 -596
- package/dist/catalog.js.map +1 -1
- package/dist/endpoint.d.ts +42 -42
- package/dist/endpoint.js +132 -131
- package/dist/endpoint.js.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/lib.js +1 -0
- package/dist/lib.js.map +1 -1
- package/dist/logging.d.ts +6 -6
- package/dist/logging.js +60 -63
- package/dist/logging.js.map +1 -1
- package/dist/node-transport.d.ts +6 -6
- package/dist/node-transport.js +48 -44
- package/dist/node-transport.js.map +1 -1
- package/dist/opencode.d.ts +10 -10
- package/dist/opencode.js +143 -146
- package/dist/opencode.js.map +1 -1
- package/dist/protocol.d.ts +127 -127
- package/dist/protocol.js +148 -128
- package/dist/protocol.js.map +1 -1
- package/dist/schema.d.ts +32 -32
- package/dist/schema.js +39 -44
- package/dist/schema.js.map +1 -1
- package/dist/token-file.d.ts +4 -4
- package/dist/token-file.js +68 -60
- package/dist/token-file.js.map +1 -1
- package/dist/tools.d.ts +11 -11
- package/dist/tools.js +128 -123
- package/dist/tools.js.map +1 -1
- package/dist/transport.d.ts +17 -17
- package/dist/transport.js +3 -9
- package/dist/transport.js.map +1 -1
- package/dist/types.d.ts +61 -61
- package/dist/types.js +1 -0
- package/dist/types.js.map +1 -1
- package/package.json +3 -3
package/dist/protocol.js
CHANGED
|
@@ -1,159 +1,179 @@
|
|
|
1
1
|
/**
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
2
|
+
* Wire protocol shared by the OpenCode plugin (the bridge **server**) and the
|
|
3
|
+
* browser extension (the **client**). This module is intentionally
|
|
4
|
+
* dependency-free and runtime-agnostic so the extension can mirror it verbatim
|
|
5
|
+
* into a browser bundle without pulling in any Bun/Node code.
|
|
6
|
+
*
|
|
7
|
+
* Canonical copy lives here (`packages/opencode-browser/src/protocol.ts`); the
|
|
8
|
+
* extension keeps a byte-for-byte copy at
|
|
9
|
+
* `apps/browser-extension/src/shared/protocol.ts`. Keep them in sync.
|
|
10
|
+
*
|
|
11
|
+
* Topology: extensions cannot host servers, so the plugin opens the WebSocket
|
|
12
|
+
* server on 127.0.0.1 and the extension's background worker dials out to it.
|
|
13
|
+
* The extension authenticates with a `hello`; the server replies `ready`. From
|
|
14
|
+
* then on the server issues `command` frames and the extension answers with a
|
|
15
|
+
* matching `result` frame (correlated by `id`). The extension may also push
|
|
16
|
+
* unsolicited `event` frames. Heartbeats use `ping`/`pong`.
|
|
17
|
+
*/
|
|
18
18
|
/** Bump when the frame shapes change incompatibly. */
|
|
19
19
|
export const PROTOCOL_VERSION = 1;
|
|
20
20
|
export const BROWSER_ACTIONS = [
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
21
|
+
"open",
|
|
22
|
+
"navigate",
|
|
23
|
+
"click",
|
|
24
|
+
"double_click",
|
|
25
|
+
"type",
|
|
26
|
+
"fill",
|
|
27
|
+
"select",
|
|
28
|
+
"scroll",
|
|
29
|
+
"press_key",
|
|
30
|
+
"screenshot",
|
|
31
|
+
"snapshot",
|
|
32
|
+
"get_text",
|
|
33
|
+
"wait",
|
|
34
|
+
"tabs",
|
|
35
|
+
"close",
|
|
36
|
+
"back",
|
|
37
|
+
"forward",
|
|
38
|
+
"reload",
|
|
39
|
+
"hover",
|
|
40
|
+
"activate",
|
|
41
|
+
"drag",
|
|
42
|
+
"upload",
|
|
43
|
+
"get_html",
|
|
44
|
+
"get_attribute",
|
|
45
|
+
"query",
|
|
46
|
+
"eval",
|
|
47
|
+
"console",
|
|
48
|
+
"network",
|
|
49
|
+
"handle_dialog",
|
|
50
|
+
"set_viewport",
|
|
51
|
+
"cookies",
|
|
52
|
+
"targets",
|
|
53
|
+
"release",
|
|
54
|
+
"request_feedback"
|
|
55
55
|
];
|
|
56
56
|
/** Serialize a frame for the wire. */
|
|
57
57
|
export function encodeFrame(frame) {
|
|
58
|
-
|
|
58
|
+
return JSON.stringify(frame);
|
|
59
59
|
}
|
|
60
60
|
function isRecord(value) {
|
|
61
|
-
|
|
61
|
+
return typeof value === "object" && value !== null;
|
|
62
62
|
}
|
|
63
63
|
/**
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
64
|
+
* Parse and shape-check an inbound frame. Returns the typed frame, or `null` if
|
|
65
|
+
* the payload is not a recognizable frame (caller decides whether to drop or
|
|
66
|
+
* log). Validation is deliberately lightweight — both ends are trusted once the
|
|
67
|
+
* token handshake succeeds; this guards against malformed JSON and version skew,
|
|
68
|
+
* not a hostile peer.
|
|
69
|
+
*/
|
|
70
70
|
export function decodeFrame(raw) {
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
case "rejected":
|
|
103
|
-
return typeof parsed.reason === "string" ? parsed : null;
|
|
104
|
-
case "ping":
|
|
105
|
-
return { v: PROTOCOL_VERSION, type: "ping" };
|
|
106
|
-
case "pong":
|
|
107
|
-
return { v: PROTOCOL_VERSION, type: "pong" };
|
|
108
|
-
default:
|
|
109
|
-
return null;
|
|
110
|
-
}
|
|
71
|
+
let parsed;
|
|
72
|
+
try {
|
|
73
|
+
parsed = JSON.parse(raw);
|
|
74
|
+
} catch {
|
|
75
|
+
return null;
|
|
76
|
+
}
|
|
77
|
+
if (!isRecord(parsed) || typeof parsed.type !== "string") {
|
|
78
|
+
return null;
|
|
79
|
+
}
|
|
80
|
+
switch (parsed.type) {
|
|
81
|
+
case "hello": return typeof parsed.token === "string" ? parsed : null;
|
|
82
|
+
case "ready": return parsed;
|
|
83
|
+
case "command": return typeof parsed.id === "string" && typeof parsed.action === "string" && typeof parsed.group === "string" ? parsed : null;
|
|
84
|
+
case "result": return typeof parsed.id === "string" && typeof parsed.ok === "boolean" ? parsed : null;
|
|
85
|
+
case "event": return typeof parsed.name === "string" ? parsed : null;
|
|
86
|
+
case "release": return {
|
|
87
|
+
v: PROTOCOL_VERSION,
|
|
88
|
+
type: "release"
|
|
89
|
+
};
|
|
90
|
+
case "cancel": return typeof parsed.id === "string" ? parsed : null;
|
|
91
|
+
case "rejected": return typeof parsed.reason === "string" ? parsed : null;
|
|
92
|
+
case "ping": return {
|
|
93
|
+
v: PROTOCOL_VERSION,
|
|
94
|
+
type: "ping"
|
|
95
|
+
};
|
|
96
|
+
case "pong": return {
|
|
97
|
+
v: PROTOCOL_VERSION,
|
|
98
|
+
type: "pong"
|
|
99
|
+
};
|
|
100
|
+
default: return null;
|
|
101
|
+
}
|
|
111
102
|
}
|
|
112
103
|
let idCounter = 0;
|
|
113
104
|
/**
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
105
|
+
* Monotonic correlation id for command frames. Process-local and collision-free
|
|
106
|
+
* within a single bridge instance, which is all that's required (the server is
|
|
107
|
+
* the only id minter).
|
|
108
|
+
*/
|
|
118
109
|
export function nextId() {
|
|
119
|
-
|
|
120
|
-
|
|
110
|
+
idCounter = (idCounter + 1) % Number.MAX_SAFE_INTEGER;
|
|
111
|
+
return `c${idCounter.toString(36)}`;
|
|
121
112
|
}
|
|
122
113
|
export function helloFrame(token, opts = {}) {
|
|
123
|
-
|
|
114
|
+
return {
|
|
115
|
+
v: PROTOCOL_VERSION,
|
|
116
|
+
type: "hello",
|
|
117
|
+
token,
|
|
118
|
+
...opts
|
|
119
|
+
};
|
|
124
120
|
}
|
|
125
121
|
export function resultFrame(id, data) {
|
|
126
|
-
|
|
122
|
+
return {
|
|
123
|
+
v: PROTOCOL_VERSION,
|
|
124
|
+
type: "result",
|
|
125
|
+
id,
|
|
126
|
+
ok: true,
|
|
127
|
+
data
|
|
128
|
+
};
|
|
127
129
|
}
|
|
128
130
|
export function errorFrame(id, message, code) {
|
|
129
|
-
|
|
131
|
+
return {
|
|
132
|
+
v: PROTOCOL_VERSION,
|
|
133
|
+
type: "result",
|
|
134
|
+
id,
|
|
135
|
+
ok: false,
|
|
136
|
+
error: {
|
|
137
|
+
message,
|
|
138
|
+
code
|
|
139
|
+
}
|
|
140
|
+
};
|
|
130
141
|
}
|
|
131
142
|
export function rejectedFrame(reason) {
|
|
132
|
-
|
|
143
|
+
return {
|
|
144
|
+
v: PROTOCOL_VERSION,
|
|
145
|
+
type: "rejected",
|
|
146
|
+
reason
|
|
147
|
+
};
|
|
133
148
|
}
|
|
134
149
|
/**
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
150
|
+
* A short, **non-secret** fingerprint of a bridge token, safe to log. It never
|
|
151
|
+
* reveals the token: just its length plus a base36 digest, so two sides can log
|
|
152
|
+
* `tokenFingerprint(...)` and a human can see at a glance whether the executor's
|
|
153
|
+
* token matches the broker's — the whole point when debugging `bad_token`.
|
|
154
|
+
*/
|
|
140
155
|
export function tokenFingerprint(token) {
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
156
|
+
// Defensive: this is logged from a connection handler, so never throw on a
|
|
157
|
+
// non-string slipping through (a malformed/forged frame) — a crash there is
|
|
158
|
+
// worse than a vague fingerprint.
|
|
159
|
+
if (typeof token !== "string") {
|
|
160
|
+
return "invalid";
|
|
161
|
+
}
|
|
162
|
+
// djb2 — tiny, dependency-free, stable. Collisions are irrelevant: this is a
|
|
163
|
+
// visual match aid, not a security primitive.
|
|
164
|
+
let hash = 5381;
|
|
165
|
+
for (let i = 0; i < token.length; i++) {
|
|
166
|
+
hash = hash * 33 ^ token.charCodeAt(i);
|
|
167
|
+
}
|
|
168
|
+
const digest = (hash >>> 0).toString(36);
|
|
169
|
+
return token.length === 0 ? "empty" : `len${token.length}.${digest}`;
|
|
155
170
|
}
|
|
156
171
|
export function cancelFrame(id) {
|
|
157
|
-
|
|
172
|
+
return {
|
|
173
|
+
v: PROTOCOL_VERSION,
|
|
174
|
+
type: "cancel",
|
|
175
|
+
id
|
|
176
|
+
};
|
|
158
177
|
}
|
|
178
|
+
|
|
159
179
|
//# sourceMappingURL=protocol.js.map
|
package/dist/protocol.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
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|
-
|
|
11
|
-
|
|
2
|
+
* A tiny, neutral schema vocabulary for tool arguments. The tool catalog
|
|
3
|
+
* (`catalog.ts`) is the single source of truth; each adapter turns these specs
|
|
4
|
+
* into its own format:
|
|
5
|
+
* - the OpenCode plugin builds a zod shape (see `inputToZodShape` in tools.ts),
|
|
6
|
+
* - the MCP server emits standard JSON Schema via `toJsonSchema` below.
|
|
7
|
+
*
|
|
8
|
+
* Keeping the vocabulary small (string/number/boolean/array/object + enum +
|
|
9
|
+
* optional + description) avoids dragging a specific zod version across the
|
|
10
|
+
* package boundary while still covering every tool's args.
|
|
11
|
+
*/
|
|
12
12
|
export type ToolGroup = "page" | "control" | "debug" | "interactive";
|
|
13
13
|
export interface StringField {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
14
|
+
type: "string";
|
|
15
|
+
description?: string;
|
|
16
|
+
optional?: boolean;
|
|
17
|
+
enum?: readonly string[];
|
|
18
18
|
}
|
|
19
19
|
export interface NumberField {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
20
|
+
type: "number";
|
|
21
|
+
description?: string;
|
|
22
|
+
optional?: boolean;
|
|
23
23
|
}
|
|
24
24
|
export interface BooleanField {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
25
|
+
type: "boolean";
|
|
26
|
+
description?: string;
|
|
27
|
+
optional?: boolean;
|
|
28
28
|
}
|
|
29
29
|
export interface ArrayField {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
30
|
+
type: "array";
|
|
31
|
+
description?: string;
|
|
32
|
+
optional?: boolean;
|
|
33
|
+
items: Field;
|
|
34
34
|
}
|
|
35
35
|
export interface ObjectField {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
36
|
+
type: "object";
|
|
37
|
+
description?: string;
|
|
38
|
+
optional?: boolean;
|
|
39
|
+
properties: Record<string, Field>;
|
|
40
40
|
}
|
|
41
41
|
export type Field = StringField | NumberField | BooleanField | ArrayField | ObjectField;
|
|
42
42
|
/** Top-level argument map for a tool. */
|
|
43
43
|
export type JsonInput = Record<string, Field>;
|
|
44
44
|
export interface JsonSchema {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
45
|
+
type: "object";
|
|
46
|
+
properties: Record<string, unknown>;
|
|
47
|
+
required: string[];
|
|
48
|
+
additionalProperties: false;
|
|
49
49
|
}
|
|
50
50
|
/** Convert a tool's input spec to a standard JSON Schema object (for MCP). */
|
|
51
51
|
export declare function toJsonSchema(input: JsonInput): JsonSchema;
|
package/dist/schema.js
CHANGED
|
@@ -1,50 +1,45 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* A tiny, neutral schema vocabulary for tool arguments. The tool catalog
|
|
3
|
-
* (`catalog.ts`) is the single source of truth; each adapter turns these specs
|
|
4
|
-
* into its own format:
|
|
5
|
-
* - the OpenCode plugin builds a zod shape (see `inputToZodShape` in tools.ts),
|
|
6
|
-
* - the MCP server emits standard JSON Schema via `toJsonSchema` below.
|
|
7
|
-
*
|
|
8
|
-
* Keeping the vocabulary small (string/number/boolean/array/object + enum +
|
|
9
|
-
* optional + description) avoids dragging a specific zod version across the
|
|
10
|
-
* package boundary while still covering every tool's args.
|
|
11
|
-
*/
|
|
12
1
|
function fieldToJsonSchema(field) {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
2
|
+
const out = { type: field.type };
|
|
3
|
+
if (field.description) {
|
|
4
|
+
out.description = field.description;
|
|
5
|
+
}
|
|
6
|
+
if (field.type === "string" && field.enum) {
|
|
7
|
+
out.enum = [...field.enum];
|
|
8
|
+
}
|
|
9
|
+
if (field.type === "array") {
|
|
10
|
+
out.items = fieldToJsonSchema(field.items);
|
|
11
|
+
}
|
|
12
|
+
if (field.type === "object") {
|
|
13
|
+
const properties = {};
|
|
14
|
+
const required = [];
|
|
15
|
+
for (const [key, value] of Object.entries(field.properties)) {
|
|
16
|
+
properties[key] = fieldToJsonSchema(value);
|
|
17
|
+
if (!value.optional) {
|
|
18
|
+
required.push(key);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
out.properties = properties;
|
|
22
|
+
out.required = required;
|
|
23
|
+
out.additionalProperties = false;
|
|
24
|
+
}
|
|
25
|
+
return out;
|
|
37
26
|
}
|
|
38
27
|
/** Convert a tool's input spec to a standard JSON Schema object (for MCP). */
|
|
39
28
|
export function toJsonSchema(input) {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
29
|
+
const properties = {};
|
|
30
|
+
const required = [];
|
|
31
|
+
for (const [key, field] of Object.entries(input)) {
|
|
32
|
+
properties[key] = fieldToJsonSchema(field);
|
|
33
|
+
if (!field.optional) {
|
|
34
|
+
required.push(key);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
return {
|
|
38
|
+
type: "object",
|
|
39
|
+
properties,
|
|
40
|
+
required,
|
|
41
|
+
additionalProperties: false
|
|
42
|
+
};
|
|
49
43
|
}
|
|
44
|
+
|
|
50
45
|
//# sourceMappingURL=schema.js.map
|
package/dist/schema.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"
|
|
1
|
+
{"mappings":"AAsDA,SAAS,kBAAkB,OAAuC;CAChE,MAAM,MAA+B,EAAE,MAAM,MAAM,KAAK;CACxD,IAAI,MAAM,aAAa;EACrB,IAAI,cAAc,MAAM;CAC1B;CACA,IAAI,MAAM,SAAS,YAAY,MAAM,MAAM;EACzC,IAAI,OAAO,CAAC,GAAG,MAAM,IAAI;CAC3B;CACA,IAAI,MAAM,SAAS,SAAS;EAC1B,IAAI,QAAQ,kBAAkB,MAAM,KAAK;CAC3C;CACA,IAAI,MAAM,SAAS,UAAU;EAC3B,MAAM,aAAsC,CAAC;EAC7C,MAAM,WAAqB,CAAC;EAC5B,KAAK,MAAM,CAAC,KAAK,UAAU,OAAO,QAAQ,MAAM,UAAU,GAAG;GAC3D,WAAW,OAAO,kBAAkB,KAAK;GACzC,IAAI,CAAC,MAAM,UAAU;IACnB,SAAS,KAAK,GAAG;GACnB;EACF;EACA,IAAI,aAAa;EACjB,IAAI,WAAW;EACf,IAAI,uBAAuB;CAC7B;CACA,OAAO;AACT;;AAGA,OAAO,SAAS,aAAa,OAA8B;CACzD,MAAM,aAAsC,CAAC;CAC7C,MAAM,WAAqB,CAAC;CAC5B,KAAK,MAAM,CAAC,KAAK,UAAU,OAAO,QAAQ,KAAK,GAAG;EAChD,WAAW,OAAO,kBAAkB,KAAK;EACzC,IAAI,CAAC,MAAM,UAAU;GACnB,SAAS,KAAK,GAAG;EACnB;CACF;CACA,OAAO;EAAE,MAAM;EAAU;EAAY;EAAU,sBAAsB;CAAM;AAC7E","names":[],"sources":["../src/schema.ts"],"version":3,"file":"schema.js","sourceRoot":""}
|
package/dist/token-file.d.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
export interface BridgeFile {
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
port?: number;
|
|
3
|
+
token?: string;
|
|
4
4
|
}
|
|
5
5
|
export declare function readBridgeFile(): BridgeFile | null;
|
|
6
6
|
export declare function writeBridgeFile(port: number, token: string): void;
|
|
7
7
|
export type TokenSource = "explicit" | "file" | "generated";
|
|
8
8
|
/** Resolve the bridge token: explicit option wins, else a shared file, else generate. */
|
|
9
9
|
export declare function resolveSharedToken(port: number, explicit: string | undefined, generate: () => string): {
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
token: string;
|
|
11
|
+
source: TokenSource;
|
|
12
12
|
};
|