@tooldeck/sdk-node 1.1.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.
@@ -0,0 +1,10 @@
1
+ import type { CommandResult } from "@tooldeck/protocol";
2
+ import type { JsonObject, MaybePromise } from "@tooldeck/shared";
3
+ import type { Disposable } from "./disposable";
4
+ export type CommandInput = JsonObject;
5
+ export type CommandInputMap = object;
6
+ export type CommandHandler<TInput = CommandInput> = (input: TInput) => MaybePromise<CommandResult>;
7
+ export interface CommandRegistry<TCommandInputs extends CommandInputMap = Record<string, CommandInput>> {
8
+ register<TCommandId extends keyof TCommandInputs & string>(commandId: TCommandId, handler: CommandHandler<TCommandInputs[TCommandId]>): Disposable;
9
+ }
10
+ //# sourceMappingURL=commands.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"commands.d.ts","sourceRoot":"","sources":["../src/commands.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACxD,OAAO,KAAK,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAEjE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAE/C,MAAM,MAAM,YAAY,GAAG,UAAU,CAAC;AACtC,MAAM,MAAM,eAAe,GAAG,MAAM,CAAC;AAErC,MAAM,MAAM,cAAc,CAAC,MAAM,GAAG,YAAY,IAAI,CAAC,KAAK,EAAE,MAAM,KAAK,YAAY,CAAC,aAAa,CAAC,CAAC;AAEnG,MAAM,WAAW,eAAe,CAC9B,cAAc,SAAS,eAAe,GAAG,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC;IAErE,QAAQ,CAAC,UAAU,SAAS,MAAM,cAAc,GAAG,MAAM,EACvD,SAAS,EAAE,UAAU,EACrB,OAAO,EAAE,cAAc,CAAC,cAAc,CAAC,UAAU,CAAC,CAAC,GAClD,UAAU,CAAC;CACf"}
@@ -0,0 +1,15 @@
1
+ import type { CommandInput, CommandInputMap, CommandRegistry } from "./commands";
2
+ import type { Disposable } from "./disposable";
3
+ export interface PluginStorage {
4
+ get(key: string): Promise<unknown>;
5
+ set(key: string, value: unknown): Promise<void>;
6
+ delete(key: string): Promise<void>;
7
+ }
8
+ export interface PluginContextV1<TCommandInputs extends CommandInputMap = Record<string, CommandInput>> {
9
+ pluginId: string;
10
+ subscriptions: Disposable[];
11
+ commands: CommandRegistry<TCommandInputs>;
12
+ storage: PluginStorage;
13
+ }
14
+ export type PluginContext<TCommandInputs extends CommandInputMap = Record<string, CommandInput>> = PluginContextV1<TCommandInputs>;
15
+ //# sourceMappingURL=context.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../src/context.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AACjF,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAE/C,MAAM,WAAW,aAAa;IAC5B,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;IACnC,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAChD,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CACpC;AAED,MAAM,WAAW,eAAe,CAC9B,cAAc,SAAS,eAAe,GAAG,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC;IAErE,QAAQ,EAAE,MAAM,CAAC;IACjB,aAAa,EAAE,UAAU,EAAE,CAAC;IAC5B,QAAQ,EAAE,eAAe,CAAC,cAAc,CAAC,CAAC;IAC1C,OAAO,EAAE,aAAa,CAAC;CACxB;AAED,MAAM,MAAM,aAAa,CAAC,cAAc,SAAS,eAAe,GAAG,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,IAC7F,eAAe,CAAC,cAAc,CAAC,CAAC"}
@@ -0,0 +1,6 @@
1
+ import type { MaybePromise } from "@tooldeck/shared";
2
+ export interface Disposable {
3
+ dispose(): MaybePromise<void>;
4
+ }
5
+ export declare function toDisposable(dispose: () => MaybePromise<void>): Disposable;
6
+ //# sourceMappingURL=disposable.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"disposable.d.ts","sourceRoot":"","sources":["../src/disposable.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAErD,MAAM,WAAW,UAAU;IACzB,OAAO,IAAI,YAAY,CAAC,IAAI,CAAC,CAAC;CAC/B;AAED,wBAAgB,YAAY,CAAC,OAAO,EAAE,MAAM,YAAY,CAAC,IAAI,CAAC,GAAG,UAAU,CAE1E"}
@@ -0,0 +1,6 @@
1
+ export * from "./commands";
2
+ export * from "./context";
3
+ export * from "./disposable";
4
+ export * from "./plugin";
5
+ export * from "./results";
6
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,WAAW,CAAC;AAC1B,cAAc,cAAc,CAAC;AAC7B,cAAc,UAAU,CAAC;AACzB,cAAc,WAAW,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,125 @@
1
+ //#region src/disposable.ts
2
+ function toDisposable(dispose) {
3
+ return { dispose };
4
+ }
5
+ //#endregion
6
+ //#region src/plugin.ts
7
+ function definePlugin(input) {
8
+ if (typeof input === "function") return defineBuilderPlugin(input);
9
+ if ("activate" in input && typeof input.activate === "function") return input;
10
+ return defineObjectPlugin(input);
11
+ }
12
+ function defineBuilderPlugin(setup) {
13
+ let definition;
14
+ return {
15
+ async activate(ctx) {
16
+ definition = createNormalizedPluginDefinition();
17
+ await setup(createPluginBuilder(definition));
18
+ await activateDefinition(ctx, definition);
19
+ },
20
+ async deactivate(ctx) {
21
+ if (!definition) return;
22
+ await deactivateDefinition(ctx, definition);
23
+ }
24
+ };
25
+ }
26
+ function defineObjectPlugin(definition) {
27
+ const normalizedDefinition = createNormalizedPluginDefinition(definition);
28
+ return {
29
+ async activate(ctx) {
30
+ await activateDefinition(ctx, normalizedDefinition);
31
+ },
32
+ async deactivate(ctx) {
33
+ await deactivateDefinition(ctx, normalizedDefinition);
34
+ }
35
+ };
36
+ }
37
+ function createPluginBuilder(definition) {
38
+ return {
39
+ command(commandId, handler) {
40
+ definition.commands.push({
41
+ commandId,
42
+ handler
43
+ });
44
+ },
45
+ onActivate(handler) {
46
+ definition.onActivate.push(handler);
47
+ },
48
+ onDeactivate(handler) {
49
+ definition.onDeactivate.push(handler);
50
+ }
51
+ };
52
+ }
53
+ function createNormalizedPluginDefinition(definition) {
54
+ return {
55
+ commands: definition?.commands ? normalizeCommands(definition.commands) : [],
56
+ onActivate: definition?.onActivate ? [definition.onActivate] : [],
57
+ onDeactivate: definition?.onDeactivate ? [definition.onDeactivate] : []
58
+ };
59
+ }
60
+ function normalizeCommands(commands) {
61
+ return Object.entries(commands).map(([commandId, handler]) => ({
62
+ commandId,
63
+ handler
64
+ }));
65
+ }
66
+ async function activateDefinition(ctx, definition) {
67
+ for (const onActivate of definition.onActivate) await onActivate(ctx);
68
+ for (const command of definition.commands) ctx.subscriptions.push(ctx.commands.register(command.commandId, command.handler));
69
+ }
70
+ async function deactivateDefinition(ctx, definition) {
71
+ for (const onDeactivate of definition.onDeactivate.toReversed()) await onDeactivate(ctx);
72
+ }
73
+ //#endregion
74
+ //#region src/results.ts
75
+ function textBlock(text) {
76
+ return {
77
+ type: "text",
78
+ text
79
+ };
80
+ }
81
+ function codeBlock(text, language) {
82
+ return {
83
+ type: "code",
84
+ text,
85
+ ...language === void 0 ? {} : { language }
86
+ };
87
+ }
88
+ function jsonBlock(value) {
89
+ return {
90
+ type: "json",
91
+ value
92
+ };
93
+ }
94
+ function propertiesBlock(items) {
95
+ return {
96
+ type: "properties",
97
+ items
98
+ };
99
+ }
100
+ function ok(blocks) {
101
+ return {
102
+ status: "success",
103
+ blocks
104
+ };
105
+ }
106
+ function okText(text) {
107
+ return ok([textBlock(text)]);
108
+ }
109
+ function fail(code, message, blocks = []) {
110
+ return {
111
+ status: "error",
112
+ blocks,
113
+ error: {
114
+ code,
115
+ message
116
+ }
117
+ };
118
+ }
119
+ function failText(code, message, text) {
120
+ return fail(code, message, text === void 0 ? [] : [textBlock(text)]);
121
+ }
122
+ //#endregion
123
+ export { codeBlock, definePlugin, fail, failText, jsonBlock, ok, okText, propertiesBlock, textBlock, toDisposable };
124
+
125
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","names":[],"sources":["../src/disposable.ts","../src/plugin.ts","../src/results.ts"],"sourcesContent":["import type { MaybePromise } from \"@tooldeck/shared\";\n\nexport interface Disposable {\n dispose(): MaybePromise<void>;\n}\n\nexport function toDisposable(dispose: () => MaybePromise<void>): Disposable {\n return { dispose };\n}\n","import type { MaybePromise } from \"@tooldeck/shared\";\n\nimport type { CommandHandler, CommandInput, CommandInputMap } from \"./commands\";\nimport type { PluginContextV1 } from \"./context\";\nimport type { Disposable } from \"./disposable\";\n\nexport interface ToolboxPluginV1<\n TCommandInputs extends CommandInputMap = Record<string, CommandInput>,\n> {\n activate(ctx: PluginContextV1<TCommandInputs>): MaybePromise<void>;\n deactivate?(ctx: PluginContextV1<TCommandInputs>): MaybePromise<void>;\n}\n\nexport type ToolboxPlugin<TCommandInputs extends CommandInputMap = Record<string, CommandInput>> =\n ToolboxPluginV1<TCommandInputs>;\n\nexport type PluginLifecycleHandler<\n TCommandInputs extends CommandInputMap = Record<string, CommandInput>,\n> = (ctx: PluginContextV1<TCommandInputs>) => MaybePromise<void>;\n\nexport type PluginCommandHandlers<\n TCommandInputs extends CommandInputMap = Record<string, CommandInput>,\n> = Partial<{\n [TCommandId in keyof TCommandInputs & string]: CommandHandler<TCommandInputs[TCommandId]>;\n}>;\n\nexport interface PluginDefinition<\n TCommandInputs extends CommandInputMap = Record<string, CommandInput>,\n> {\n commands?: PluginCommandHandlers<TCommandInputs>;\n onActivate?: PluginLifecycleHandler<TCommandInputs>;\n onDeactivate?: PluginLifecycleHandler<TCommandInputs>;\n}\n\nexport interface PluginBuilder<\n TCommandInputs extends CommandInputMap = Record<string, CommandInput>,\n> {\n command<TCommandId extends keyof TCommandInputs & string>(\n commandId: TCommandId,\n handler: CommandHandler<TCommandInputs[TCommandId]>,\n ): void;\n onActivate(handler: PluginLifecycleHandler<TCommandInputs>): void;\n onDeactivate(handler: PluginLifecycleHandler<TCommandInputs>): void;\n}\n\nexport type PluginSetup<TCommandInputs extends CommandInputMap = Record<string, CommandInput>> = (\n plugin: PluginBuilder<TCommandInputs>,\n) => MaybePromise<void>;\n\ntype RegisteredCommand = {\n commandId: string;\n handler: CommandHandler<CommandInput>;\n};\n\ntype RuntimeCommandRegistry = {\n register(commandId: string, handler: CommandHandler<CommandInput>): Disposable;\n};\n\ntype NormalizedPluginDefinition<\n TCommandInputs extends CommandInputMap = Record<string, CommandInput>,\n> = {\n commands: RegisteredCommand[];\n onActivate: PluginLifecycleHandler<TCommandInputs>[];\n onDeactivate: PluginLifecycleHandler<TCommandInputs>[];\n};\n\nexport function definePlugin<TCommandInputs extends CommandInputMap = Record<string, CommandInput>>(\n setup: PluginSetup<TCommandInputs>,\n): ToolboxPluginV1<TCommandInputs>;\nexport function definePlugin<TCommandInputs extends CommandInputMap = Record<string, CommandInput>>(\n definition: PluginDefinition<TCommandInputs>,\n): ToolboxPluginV1<TCommandInputs>;\nexport function definePlugin<TCommandInputs extends CommandInputMap = Record<string, CommandInput>>(\n plugin: ToolboxPluginV1<TCommandInputs>,\n): ToolboxPluginV1<TCommandInputs>;\nexport function definePlugin<TCommandInputs extends CommandInputMap = Record<string, CommandInput>>(\n input:\n | PluginSetup<TCommandInputs>\n | PluginDefinition<TCommandInputs>\n | ToolboxPluginV1<TCommandInputs>,\n): ToolboxPluginV1<TCommandInputs> {\n if (typeof input === \"function\") {\n return defineBuilderPlugin(input);\n }\n\n if (\"activate\" in input && typeof input.activate === \"function\") {\n return input;\n }\n\n return defineObjectPlugin(input as PluginDefinition<TCommandInputs>);\n}\n\nfunction defineBuilderPlugin<TCommandInputs extends CommandInputMap = Record<string, CommandInput>>(\n setup: PluginSetup<TCommandInputs>,\n): ToolboxPluginV1<TCommandInputs> {\n let definition: NormalizedPluginDefinition<TCommandInputs> | undefined;\n\n return {\n async activate(ctx) {\n definition = createNormalizedPluginDefinition<TCommandInputs>();\n await setup(createPluginBuilder(definition));\n await activateDefinition(ctx, definition);\n },\n async deactivate(ctx) {\n if (!definition) {\n return;\n }\n\n await deactivateDefinition(ctx, definition);\n },\n };\n}\n\nfunction defineObjectPlugin<TCommandInputs extends CommandInputMap = Record<string, CommandInput>>(\n definition: PluginDefinition<TCommandInputs>,\n): ToolboxPluginV1<TCommandInputs> {\n const normalizedDefinition = createNormalizedPluginDefinition(definition);\n\n return {\n async activate(ctx) {\n await activateDefinition(ctx, normalizedDefinition);\n },\n async deactivate(ctx) {\n await deactivateDefinition(ctx, normalizedDefinition);\n },\n };\n}\n\nfunction createPluginBuilder<TCommandInputs extends CommandInputMap = Record<string, CommandInput>>(\n definition: NormalizedPluginDefinition<TCommandInputs>,\n): PluginBuilder<TCommandInputs> {\n return {\n command(commandId, handler) {\n definition.commands.push({\n commandId,\n handler: handler as CommandHandler<CommandInput>,\n });\n },\n onActivate(handler) {\n definition.onActivate.push(handler);\n },\n onDeactivate(handler) {\n definition.onDeactivate.push(handler);\n },\n };\n}\n\nfunction createNormalizedPluginDefinition<\n TCommandInputs extends CommandInputMap = Record<string, CommandInput>,\n>(definition?: PluginDefinition<TCommandInputs>): NormalizedPluginDefinition<TCommandInputs> {\n return {\n commands: definition?.commands ? normalizeCommands(definition.commands) : [],\n onActivate: definition?.onActivate ? [definition.onActivate] : [],\n onDeactivate: definition?.onDeactivate ? [definition.onDeactivate] : [],\n };\n}\n\nfunction normalizeCommands<TCommandInputs extends CommandInputMap = Record<string, CommandInput>>(\n commands: PluginCommandHandlers<TCommandInputs>,\n): RegisteredCommand[] {\n return Object.entries(commands).map(([commandId, handler]) => ({\n commandId,\n handler: handler as CommandHandler<CommandInput>,\n }));\n}\n\nasync function activateDefinition<\n TCommandInputs extends CommandInputMap = Record<string, CommandInput>,\n>(\n ctx: PluginContextV1<TCommandInputs>,\n definition: NormalizedPluginDefinition<TCommandInputs>,\n): Promise<void> {\n for (const onActivate of definition.onActivate) {\n await onActivate(ctx);\n }\n\n for (const command of definition.commands) {\n ctx.subscriptions.push(\n (ctx.commands as RuntimeCommandRegistry).register(command.commandId, command.handler),\n );\n }\n}\n\nasync function deactivateDefinition<\n TCommandInputs extends CommandInputMap = Record<string, CommandInput>,\n>(\n ctx: PluginContextV1<TCommandInputs>,\n definition: NormalizedPluginDefinition<TCommandInputs>,\n): Promise<void> {\n for (const onDeactivate of definition.onDeactivate.toReversed()) {\n await onDeactivate(ctx);\n }\n}\n","import type {\n CodeContentBlock,\n CommandResult,\n ContentBlock,\n JsonContentBlock,\n PropertiesContentBlock,\n PropertyItem,\n TextContentBlock,\n} from \"@tooldeck/protocol\";\nimport type { JsonValue } from \"@tooldeck/shared\";\n\nexport function textBlock(text: string): TextContentBlock {\n return {\n type: \"text\",\n text,\n };\n}\n\nexport function codeBlock(text: string, language?: string): CodeContentBlock {\n return {\n type: \"code\",\n text,\n ...(language === undefined ? {} : { language }),\n };\n}\n\nexport function jsonBlock(value: JsonValue): JsonContentBlock {\n return {\n type: \"json\",\n value,\n };\n}\n\nexport function propertiesBlock(items: PropertyItem[]): PropertiesContentBlock {\n return {\n type: \"properties\",\n items,\n };\n}\n\nexport function ok(blocks: ContentBlock[]): CommandResult {\n return {\n status: \"success\",\n blocks,\n };\n}\n\nexport function okText(text: string): CommandResult {\n return ok([textBlock(text)]);\n}\n\nexport function fail(code: string, message: string, blocks: ContentBlock[] = []): CommandResult {\n return {\n status: \"error\",\n blocks,\n error: {\n code,\n message,\n },\n };\n}\n\nexport function failText(code: string, message: string, text?: string): CommandResult {\n return fail(code, message, text === undefined ? [] : [textBlock(text)]);\n}\n"],"mappings":";AAMA,SAAgB,aAAa,SAA+C;CAC1E,OAAO,EAAE,QAAQ;AACnB;;;ACmEA,SAAgB,aACd,OAIiC;CACjC,IAAI,OAAO,UAAU,YACnB,OAAO,oBAAoB,KAAK;CAGlC,IAAI,cAAc,SAAS,OAAO,MAAM,aAAa,YACnD,OAAO;CAGT,OAAO,mBAAmB,KAAyC;AACrE;AAEA,SAAS,oBACP,OACiC;CACjC,IAAI;CAEJ,OAAO;EACL,MAAM,SAAS,KAAK;GAClB,aAAa,iCAAiD;GAC9D,MAAM,MAAM,oBAAoB,UAAU,CAAC;GAC3C,MAAM,mBAAmB,KAAK,UAAU;EAC1C;EACA,MAAM,WAAW,KAAK;GACpB,IAAI,CAAC,YACH;GAGF,MAAM,qBAAqB,KAAK,UAAU;EAC5C;CACF;AACF;AAEA,SAAS,mBACP,YACiC;CACjC,MAAM,uBAAuB,iCAAiC,UAAU;CAExE,OAAO;EACL,MAAM,SAAS,KAAK;GAClB,MAAM,mBAAmB,KAAK,oBAAoB;EACpD;EACA,MAAM,WAAW,KAAK;GACpB,MAAM,qBAAqB,KAAK,oBAAoB;EACtD;CACF;AACF;AAEA,SAAS,oBACP,YAC+B;CAC/B,OAAO;EACL,QAAQ,WAAW,SAAS;GAC1B,WAAW,SAAS,KAAK;IACvB;IACS;GACX,CAAC;EACH;EACA,WAAW,SAAS;GAClB,WAAW,WAAW,KAAK,OAAO;EACpC;EACA,aAAa,SAAS;GACpB,WAAW,aAAa,KAAK,OAAO;EACtC;CACF;AACF;AAEA,SAAS,iCAEP,YAA2F;CAC3F,OAAO;EACL,UAAU,YAAY,WAAW,kBAAkB,WAAW,QAAQ,IAAI,CAAC;EAC3E,YAAY,YAAY,aAAa,CAAC,WAAW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 -0,0 +1,27 @@
1
+ import type { MaybePromise } from "@tooldeck/shared";
2
+ import type { CommandHandler, CommandInput, CommandInputMap } from "./commands";
3
+ import type { PluginContextV1 } from "./context";
4
+ export interface ToolboxPluginV1<TCommandInputs extends CommandInputMap = Record<string, CommandInput>> {
5
+ activate(ctx: PluginContextV1<TCommandInputs>): MaybePromise<void>;
6
+ deactivate?(ctx: PluginContextV1<TCommandInputs>): MaybePromise<void>;
7
+ }
8
+ export type ToolboxPlugin<TCommandInputs extends CommandInputMap = Record<string, CommandInput>> = ToolboxPluginV1<TCommandInputs>;
9
+ export type PluginLifecycleHandler<TCommandInputs extends CommandInputMap = Record<string, CommandInput>> = (ctx: PluginContextV1<TCommandInputs>) => MaybePromise<void>;
10
+ export type PluginCommandHandlers<TCommandInputs extends CommandInputMap = Record<string, CommandInput>> = Partial<{
11
+ [TCommandId in keyof TCommandInputs & string]: CommandHandler<TCommandInputs[TCommandId]>;
12
+ }>;
13
+ export interface PluginDefinition<TCommandInputs extends CommandInputMap = Record<string, CommandInput>> {
14
+ commands?: PluginCommandHandlers<TCommandInputs>;
15
+ onActivate?: PluginLifecycleHandler<TCommandInputs>;
16
+ onDeactivate?: PluginLifecycleHandler<TCommandInputs>;
17
+ }
18
+ export interface PluginBuilder<TCommandInputs extends CommandInputMap = Record<string, CommandInput>> {
19
+ command<TCommandId extends keyof TCommandInputs & string>(commandId: TCommandId, handler: CommandHandler<TCommandInputs[TCommandId]>): void;
20
+ onActivate(handler: PluginLifecycleHandler<TCommandInputs>): void;
21
+ onDeactivate(handler: PluginLifecycleHandler<TCommandInputs>): void;
22
+ }
23
+ export type PluginSetup<TCommandInputs extends CommandInputMap = Record<string, CommandInput>> = (plugin: PluginBuilder<TCommandInputs>) => MaybePromise<void>;
24
+ export declare function definePlugin<TCommandInputs extends CommandInputMap = Record<string, CommandInput>>(setup: PluginSetup<TCommandInputs>): ToolboxPluginV1<TCommandInputs>;
25
+ export declare function definePlugin<TCommandInputs extends CommandInputMap = Record<string, CommandInput>>(definition: PluginDefinition<TCommandInputs>): ToolboxPluginV1<TCommandInputs>;
26
+ export declare function definePlugin<TCommandInputs extends CommandInputMap = Record<string, CommandInput>>(plugin: ToolboxPluginV1<TCommandInputs>): ToolboxPluginV1<TCommandInputs>;
27
+ //# sourceMappingURL=plugin.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../src/plugin.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAErD,OAAO,KAAK,EAAE,cAAc,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAChF,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AAGjD,MAAM,WAAW,eAAe,CAC9B,cAAc,SAAS,eAAe,GAAG,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC;IAErE,QAAQ,CAAC,GAAG,EAAE,eAAe,CAAC,cAAc,CAAC,GAAG,YAAY,CAAC,IAAI,CAAC,CAAC;IACnE,UAAU,CAAC,CAAC,GAAG,EAAE,eAAe,CAAC,cAAc,CAAC,GAAG,YAAY,CAAC,IAAI,CAAC,CAAC;CACvE;AAED,MAAM,MAAM,aAAa,CAAC,cAAc,SAAS,eAAe,GAAG,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,IAC7F,eAAe,CAAC,cAAc,CAAC,CAAC;AAElC,MAAM,MAAM,sBAAsB,CAChC,cAAc,SAAS,eAAe,GAAG,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,IACnE,CAAC,GAAG,EAAE,eAAe,CAAC,cAAc,CAAC,KAAK,YAAY,CAAC,IAAI,CAAC,CAAC;AAEjE,MAAM,MAAM,qBAAqB,CAC/B,cAAc,SAAS,eAAe,GAAG,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,IACnE,OAAO,CAAC;KACT,UAAU,IAAI,MAAM,cAAc,GAAG,MAAM,GAAG,cAA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,CAAC;AACnC,wBAAgB,YAAY,CAAC,cAAc,SAAS,eAAe,GAAG,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,EAChG,MAAM,EAAE,eAAe,CAAC,cAAc,CAAC,GACtC,eAAe,CAAC,cAAc,CAAC,CAAC"}
@@ -0,0 +1,11 @@
1
+ import type { CodeContentBlock, CommandResult, ContentBlock, JsonContentBlock, PropertiesContentBlock, PropertyItem, TextContentBlock } from "@tooldeck/protocol";
2
+ import type { JsonValue } from "@tooldeck/shared";
3
+ export declare function textBlock(text: string): TextContentBlock;
4
+ export declare function codeBlock(text: string, language?: string): CodeContentBlock;
5
+ export declare function jsonBlock(value: JsonValue): JsonContentBlock;
6
+ export declare function propertiesBlock(items: PropertyItem[]): PropertiesContentBlock;
7
+ export declare function ok(blocks: ContentBlock[]): CommandResult;
8
+ export declare function okText(text: string): CommandResult;
9
+ export declare function fail(code: string, message: string, blocks?: ContentBlock[]): CommandResult;
10
+ export declare function failText(code: string, message: string, text?: string): CommandResult;
11
+ //# sourceMappingURL=results.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"results.d.ts","sourceRoot":"","sources":["../src/results.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,gBAAgB,EAChB,aAAa,EACb,YAAY,EACZ,gBAAgB,EAChB,sBAAsB,EACtB,YAAY,EACZ,gBAAgB,EACjB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAElD,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,gBAAgB,CAKxD;AAED,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,gBAAgB,CAM3E;AAED,wBAAgB,SAAS,CAAC,KAAK,EAAE,SAAS,GAAG,gBAAgB,CAK5D;AAED,wBAAgB,eAAe,CAAC,KAAK,EAAE,YAAY,EAAE,GAAG,sBAAsB,CAK7E;AAED,wBAAgB,EAAE,CAAC,MAAM,EAAE,YAAY,EAAE,GAAG,aAAa,CAKxD;AAED,wBAAgB,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,aAAa,CAElD;AAED,wBAAgB,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,GAAE,YAAY,EAAO,GAAG,aAAa,CAS9F;AAED,wBAAgB,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,GAAG,aAAa,CAEpF"}
package/package.json ADDED
@@ -0,0 +1,30 @@
1
+ {
2
+ "name": "@tooldeck/sdk-node",
3
+ "version": "1.1.0",
4
+ "description": "SDK types and helpers for Tooldeck plugins.",
5
+ "type": "module",
6
+ "types": "./dist/index.d.ts",
7
+ "files": [
8
+ "dist"
9
+ ],
10
+ "exports": {
11
+ ".": {
12
+ "types": "./dist/index.d.ts",
13
+ "import": "./dist/index.js"
14
+ }
15
+ },
16
+ "publishConfig": {
17
+ "access": "public"
18
+ },
19
+ "dependencies": {
20
+ "@tooldeck/protocol": "1.1.0"
21
+ },
22
+ "devDependencies": {
23
+ "@tooldeck/shared": "1.1.0"
24
+ },
25
+ "scripts": {
26
+ "build": "vite build --configLoader runner && tsc -p tsconfig.build.json --emitDeclarationOnly",
27
+ "typecheck": "tsc --noEmit",
28
+ "test": "vitest run"
29
+ }
30
+ }