openrouter-genimage-kote-opencode 0.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.
Files changed (163) hide show
  1. package/.opencode/skills/openrouter-image-generation/SKILL.md +379 -0
  2. package/CHANGELOG.md +10 -0
  3. package/LICENSE +21 -0
  4. package/README.md +229 -0
  5. package/README.ru.md +229 -0
  6. package/SECURITY.md +31 -0
  7. package/THIRD_PARTY_NOTICES.md +16 -0
  8. package/dist/cli.d.ts +20 -0
  9. package/dist/cli.d.ts.map +1 -0
  10. package/dist/cli.js +277 -0
  11. package/dist/cli.js.map +1 -0
  12. package/dist/commands/balance-command.d.ts +5 -0
  13. package/dist/commands/balance-command.d.ts.map +1 -0
  14. package/dist/commands/balance-command.js +20 -0
  15. package/dist/commands/balance-command.js.map +1 -0
  16. package/dist/config/resolve.d.ts +5 -0
  17. package/dist/config/resolve.d.ts.map +1 -0
  18. package/dist/config/resolve.js +113 -0
  19. package/dist/config/resolve.js.map +1 -0
  20. package/dist/config/schema.d.ts +188 -0
  21. package/dist/config/schema.d.ts.map +1 -0
  22. package/dist/config/schema.js +144 -0
  23. package/dist/config/schema.js.map +1 -0
  24. package/dist/config/types.d.ts +75 -0
  25. package/dist/config/types.d.ts.map +1 -0
  26. package/dist/config/types.js +30 -0
  27. package/dist/config/types.js.map +1 -0
  28. package/dist/logging.d.ts +46 -0
  29. package/dist/logging.d.ts.map +1 -0
  30. package/dist/logging.js +58 -0
  31. package/dist/logging.js.map +1 -0
  32. package/dist/openrouter/capabilities.d.ts +22 -0
  33. package/dist/openrouter/capabilities.d.ts.map +1 -0
  34. package/dist/openrouter/capabilities.js +137 -0
  35. package/dist/openrouter/capabilities.js.map +1 -0
  36. package/dist/openrouter/client.d.ts +54 -0
  37. package/dist/openrouter/client.d.ts.map +1 -0
  38. package/dist/openrouter/client.js +440 -0
  39. package/dist/openrouter/client.js.map +1 -0
  40. package/dist/openrouter/errors.d.ts +22 -0
  41. package/dist/openrouter/errors.d.ts.map +1 -0
  42. package/dist/openrouter/errors.js +75 -0
  43. package/dist/openrouter/errors.js.map +1 -0
  44. package/dist/openrouter/models.d.ts +37 -0
  45. package/dist/openrouter/models.d.ts.map +1 -0
  46. package/dist/openrouter/models.js +113 -0
  47. package/dist/openrouter/models.js.map +1 -0
  48. package/dist/openrouter/requests.d.ts +6 -0
  49. package/dist/openrouter/requests.d.ts.map +1 -0
  50. package/dist/openrouter/requests.js +74 -0
  51. package/dist/openrouter/requests.js.map +1 -0
  52. package/dist/openrouter/schemas.d.ts +37 -0
  53. package/dist/openrouter/schemas.d.ts.map +1 -0
  54. package/dist/openrouter/schemas.js +2 -0
  55. package/dist/openrouter/schemas.js.map +1 -0
  56. package/dist/output/attachments.d.ts +10 -0
  57. package/dist/output/attachments.d.ts.map +1 -0
  58. package/dist/output/attachments.js +13 -0
  59. package/dist/output/attachments.js.map +1 -0
  60. package/dist/output/formats.d.ts +42 -0
  61. package/dist/output/formats.d.ts.map +1 -0
  62. package/dist/output/formats.js +126 -0
  63. package/dist/output/formats.js.map +1 -0
  64. package/dist/output/index.d.ts +5 -0
  65. package/dist/output/index.d.ts.map +1 -0
  66. package/dist/output/index.js +5 -0
  67. package/dist/output/index.js.map +1 -0
  68. package/dist/output/paths.d.ts +38 -0
  69. package/dist/output/paths.d.ts.map +1 -0
  70. package/dist/output/paths.js +296 -0
  71. package/dist/output/paths.js.map +1 -0
  72. package/dist/output/writer.d.ts +33 -0
  73. package/dist/output/writer.d.ts.map +1 -0
  74. package/dist/output/writer.js +176 -0
  75. package/dist/output/writer.js.map +1 -0
  76. package/dist/references/attachments.d.ts +82 -0
  77. package/dist/references/attachments.d.ts.map +1 -0
  78. package/dist/references/attachments.js +238 -0
  79. package/dist/references/attachments.js.map +1 -0
  80. package/dist/references/data-url.d.ts +12 -0
  81. package/dist/references/data-url.d.ts.map +1 -0
  82. package/dist/references/data-url.js +75 -0
  83. package/dist/references/data-url.js.map +1 -0
  84. package/dist/references/formats.d.ts +13 -0
  85. package/dist/references/formats.d.ts.map +1 -0
  86. package/dist/references/formats.js +50 -0
  87. package/dist/references/formats.js.map +1 -0
  88. package/dist/references/index.d.ts +7 -0
  89. package/dist/references/index.d.ts.map +1 -0
  90. package/dist/references/index.js +7 -0
  91. package/dist/references/index.js.map +1 -0
  92. package/dist/references/limits.d.ts +15 -0
  93. package/dist/references/limits.d.ts.map +1 -0
  94. package/dist/references/limits.js +62 -0
  95. package/dist/references/limits.js.map +1 -0
  96. package/dist/references/project-files.d.ts +13 -0
  97. package/dist/references/project-files.d.ts.map +1 -0
  98. package/dist/references/project-files.js +148 -0
  99. package/dist/references/project-files.js.map +1 -0
  100. package/dist/references/remote-urls.d.ts +3 -0
  101. package/dist/references/remote-urls.d.ts.map +1 -0
  102. package/dist/references/remote-urls.js +22 -0
  103. package/dist/references/remote-urls.js.map +1 -0
  104. package/dist/server.d.ts +8 -0
  105. package/dist/server.d.ts.map +1 -0
  106. package/dist/server.js +97 -0
  107. package/dist/server.js.map +1 -0
  108. package/dist/tools/balance.d.ts +8 -0
  109. package/dist/tools/balance.d.ts.map +1 -0
  110. package/dist/tools/balance.js +133 -0
  111. package/dist/tools/balance.js.map +1 -0
  112. package/dist/tools/common.d.ts +3 -0
  113. package/dist/tools/common.d.ts.map +1 -0
  114. package/dist/tools/common.js +18 -0
  115. package/dist/tools/common.js.map +1 -0
  116. package/dist/tools/edit-image.d.ts +90 -0
  117. package/dist/tools/edit-image.d.ts.map +1 -0
  118. package/dist/tools/edit-image.js +47 -0
  119. package/dist/tools/edit-image.js.map +1 -0
  120. package/dist/tools/generate-image.d.ts +70 -0
  121. package/dist/tools/generate-image.d.ts.map +1 -0
  122. package/dist/tools/generate-image.js +36 -0
  123. package/dist/tools/generate-image.js.map +1 -0
  124. package/dist/tools/generation.d.ts +19 -0
  125. package/dist/tools/generation.d.ts.map +1 -0
  126. package/dist/tools/generation.js +154 -0
  127. package/dist/tools/generation.js.map +1 -0
  128. package/dist/tools/schema.d.ts +127 -0
  129. package/dist/tools/schema.d.ts.map +1 -0
  130. package/dist/tools/schema.js +47 -0
  131. package/dist/tools/schema.js.map +1 -0
  132. package/dist/tools/types.d.ts +18 -0
  133. package/dist/tools/types.d.ts.map +1 -0
  134. package/dist/tools/types.js +2 -0
  135. package/dist/tools/types.js.map +1 -0
  136. package/dist/transport/direct.d.ts +10 -0
  137. package/dist/transport/direct.d.ts.map +1 -0
  138. package/dist/transport/direct.js +15 -0
  139. package/dist/transport/direct.js.map +1 -0
  140. package/dist/transport/index.d.ts +4 -0
  141. package/dist/transport/index.d.ts.map +1 -0
  142. package/dist/transport/index.js +4 -0
  143. package/dist/transport/index.js.map +1 -0
  144. package/dist/transport/kote-gateway.d.ts +19 -0
  145. package/dist/transport/kote-gateway.d.ts.map +1 -0
  146. package/dist/transport/kote-gateway.js +224 -0
  147. package/dist/transport/kote-gateway.js.map +1 -0
  148. package/dist/transport/types.d.ts +10 -0
  149. package/dist/transport/types.d.ts.map +1 -0
  150. package/dist/transport/types.js +9 -0
  151. package/dist/transport/types.js.map +1 -0
  152. package/dist/utils/abort.d.ts +19 -0
  153. package/dist/utils/abort.d.ts.map +1 -0
  154. package/dist/utils/abort.js +121 -0
  155. package/dist/utils/abort.js.map +1 -0
  156. package/docs/architecture.md +75 -0
  157. package/docs/configuration.md +110 -0
  158. package/docs/image-to-image.md +101 -0
  159. package/docs/security.md +49 -0
  160. package/docs/testing.md +81 -0
  161. package/docs/troubleshooting.md +73 -0
  162. package/package.json +88 -0
  163. package/schema/plugin-options.schema.json +182 -0
@@ -0,0 +1,47 @@
1
+ import { tool } from "@opencode-ai/plugin";
2
+ import { requireResolvedPluginOptions } from "../config/resolve.js";
3
+ import { buildImageToImageRequest } from "../openrouter/requests.js";
4
+ import { resolveImageReferences } from "../references/attachments.js";
5
+ import { runToolOperation } from "./common.js";
6
+ import { finishGeneration, preflightOutput } from "./generation.js";
7
+ import { editToolArgs } from "./schema.js";
8
+ export function createEditImageTool(dependencies) {
9
+ return tool({
10
+ description: `Edit, transform, or create a new raster image from one or more visual references using the OpenRouter image model configured by the user.
11
+
12
+ Use this tool when the user wants to modify an attached image, create a variation, preserve a character or object, transfer a style, or create a new asset based on visual references.
13
+
14
+ The operation may incur OpenRouter charges.`,
15
+ args: editToolArgs,
16
+ async execute(args, context) {
17
+ return runToolOperation(dependencies.logger, async () => {
18
+ const options = requireResolvedPluginOptions(dependencies.configState);
19
+ const runtime = dependencies.getRuntime();
20
+ const { references: referenceArgs, ...generationArgs } = args;
21
+ const references = await resolveImageReferences({
22
+ references: referenceArgs,
23
+ context,
24
+ client: dependencies.messageClient,
25
+ serverUrl: dependencies.serverUrl,
26
+ limits: options.input,
27
+ promptLength: Array.from(args.prompt).length,
28
+ });
29
+ await preflightOutput(runtime, args, context, references.canonicalSourcePaths);
30
+ const request = buildImageToImageRequest(options, generationArgs, references.inputReferences);
31
+ await runtime.capabilities.validate("edit", request, context.abort);
32
+ const response = await runtime.client.generateImage(request, context.abort);
33
+ return finishGeneration({
34
+ operation: "edit",
35
+ args,
36
+ request,
37
+ response,
38
+ runtime,
39
+ dependencies,
40
+ context,
41
+ references,
42
+ });
43
+ });
44
+ },
45
+ });
46
+ }
47
+ //# sourceMappingURL=edit-image.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"edit-image.js","sourceRoot":"","sources":["../../src/tools/edit-image.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,qBAAqB,CAAA;AAE1C,OAAO,EAAE,4BAA4B,EAAE,MAAM,sBAAsB,CAAA;AACnE,OAAO,EAAE,wBAAwB,EAAE,MAAM,2BAA2B,CAAA;AACpE,OAAO,EAAE,sBAAsB,EAAE,MAAM,8BAA8B,CAAA;AACrE,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAA;AAC9C,OAAO,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAA;AACnE,OAAO,EAAE,YAAY,EAAE,MAAM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QAAQ;oBACR,OAAO;oBACP,YAAY;oBACZ,OAAO;oBACP,UAAU;iBACX,CAAC,CAAA;YACJ,CAAC,CAAC,CAAA;QACJ,CAAC;KACF,CAAC,CAAA;AACJ,CAAC"}
@@ -0,0 +1,70 @@
1
+ import type { ToolDependencies } from "./types.js";
2
+ export declare function createGenerateImageTool(dependencies: ToolDependencies): {
3
+ description: string;
4
+ args: {
5
+ prompt: import("zod").ZodString;
6
+ output_path: import("zod").ZodOptional<import("zod").ZodString>;
7
+ aspect_ratio: import("zod").ZodOptional<import("zod").ZodEnum<{
8
+ auto: "auto";
9
+ "1:1": "1:1";
10
+ "1:2": "1:2";
11
+ "1:4": "1:4";
12
+ "1:8": "1:8";
13
+ "2:1": "2:1";
14
+ "2:3": "2:3";
15
+ "3:2": "3:2";
16
+ "3:4": "3:4";
17
+ "4:1": "4:1";
18
+ "4:3": "4:3";
19
+ "4:5": "4:5";
20
+ "5:4": "5:4";
21
+ "8:1": "8:1";
22
+ "9:16": "9:16";
23
+ "16:9": "16:9";
24
+ "9:19.5": "9:19.5";
25
+ "19.5:9": "19.5:9";
26
+ "9:20": "9:20";
27
+ "20:9": "20:9";
28
+ "9:21": "9:21";
29
+ "21:9": "21:9";
30
+ }>>;
31
+ background: import("zod").ZodOptional<import("zod").ZodEnum<{
32
+ transparent: "transparent";
33
+ auto: "auto";
34
+ opaque: "opaque";
35
+ }>>;
36
+ n: import("zod").ZodOptional<import("zod").ZodNumber>;
37
+ output_format: import("zod").ZodOptional<import("zod").ZodEnum<{
38
+ png: "png";
39
+ jpeg: "jpeg";
40
+ webp: "webp";
41
+ }>>;
42
+ output_compression: import("zod").ZodOptional<import("zod").ZodNumber>;
43
+ quality: import("zod").ZodOptional<import("zod").ZodEnum<{
44
+ auto: "auto";
45
+ high: "high";
46
+ low: "low";
47
+ medium: "medium";
48
+ }>>;
49
+ resolution: import("zod").ZodOptional<import("zod").ZodEnum<{
50
+ 512: "512";
51
+ "1K": "1K";
52
+ "2K": "2K";
53
+ "4K": "4K";
54
+ }>>;
55
+ seed: import("zod").ZodOptional<import("zod").ZodNumber>;
56
+ };
57
+ execute(args: {
58
+ prompt: string;
59
+ output_path?: string | undefined;
60
+ aspect_ratio?: "auto" | "1:1" | "1:2" | "1:4" | "1:8" | "2:1" | "2:3" | "3:2" | "3:4" | "4:1" | "4:3" | "4:5" | "5:4" | "8:1" | "9:16" | "16:9" | "9:19.5" | "19.5:9" | "9:20" | "20:9" | "9:21" | "21:9" | undefined;
61
+ background?: "transparent" | "auto" | "opaque" | undefined;
62
+ n?: number | undefined;
63
+ output_format?: "png" | "jpeg" | "webp" | undefined;
64
+ output_compression?: number | undefined;
65
+ quality?: "auto" | "high" | "low" | "medium" | undefined;
66
+ resolution?: "512" | "1K" | "2K" | "4K" | undefined;
67
+ seed?: number | undefined;
68
+ }, context: import("@opencode-ai/plugin").ToolContext): Promise<import("@opencode-ai/plugin").ToolResult>;
69
+ };
70
+ //# sourceMappingURL=generate-image.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generate-image.d.ts","sourceRoot":"","sources":["../../src/tools/generate-image.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAA;AAElD,wBAAgB,uBAAuB,CAAC,YAAY,EAAE,gBAAgB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA6BrE"}
@@ -0,0 +1,36 @@
1
+ import { tool } from "@opencode-ai/plugin";
2
+ import { requireResolvedPluginOptions } from "../config/resolve.js";
3
+ import { buildTextToImageRequest } from "../openrouter/requests.js";
4
+ import { runToolOperation } from "./common.js";
5
+ import { finishGeneration, preflightOutput } from "./generation.js";
6
+ import { generationToolArgs } from "./schema.js";
7
+ export function createGenerateImageTool(dependencies) {
8
+ return tool({
9
+ description: `Generate a completely new raster image from a text prompt using the OpenRouter image model configured by the user.
10
+
11
+ Use this tool only when the user requests a new image or asset and no existing image needs to be preserved or used as a visual reference.
12
+
13
+ The operation may incur OpenRouter charges.`,
14
+ args: generationToolArgs,
15
+ async execute(args, context) {
16
+ return runToolOperation(dependencies.logger, async () => {
17
+ const options = requireResolvedPluginOptions(dependencies.configState);
18
+ const runtime = dependencies.getRuntime();
19
+ const request = buildTextToImageRequest(options, args);
20
+ await preflightOutput(runtime, args, context);
21
+ await runtime.capabilities.validate("generate", request, context.abort);
22
+ const response = await runtime.client.generateImage(request, context.abort);
23
+ return finishGeneration({
24
+ operation: "generate",
25
+ args,
26
+ request,
27
+ response,
28
+ runtime,
29
+ dependencies,
30
+ context,
31
+ });
32
+ });
33
+ },
34
+ });
35
+ }
36
+ //# sourceMappingURL=generate-image.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generate-image.js","sourceRoot":"","sources":["../../src/tools/generate-image.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,qBAAqB,CAAA;AAE1C,OAAO,EAAE,4BAA4B,EAAE,MAAM,sBAAsB,CAAA;AACnE,OAAO,EAAE,uBAAuB,EAAE,MAAM,2BAA2B,CAAA;AACnE,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAA;AAC9C,OAAO,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAA;AACnE,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAA;AAGhD,MAAM,UAAU,uBAAuB,CAAC,YAA8B;IACpE,OAAO,IAAI,CAAC;QACV,WAAW,EAAE;;;;4CAI2B;QACxC,IAAI,EAAE,kBAAkB;QACxB,KAAK,CAAC,OAAO,CAAC,IAAI,EAAE,OAAO;YACzB,OAAO,gBAAgB,CAAC,YAAY,CAAC,MAAM,EAAE,KAAK,IAAI,EAAE;gBACtD,MAAM,OAAO,GAAG,4BAA4B,CAAC,YAAY,CAAC,WAAW,CAAC,CAAA;gBACtE,MAAM,OAAO,GAAG,YAAY,CAAC,UAAU,EAAE,CAAA;gBACzC,MAAM,OAAO,GAAG,uBAAuB,CAAC,OAAO,EAAE,IAAI,CAAC,CAAA;gBAEtD,MAAM,eAAe,CAAC,OAAO,EAAE,IAAI,EAAE,OAAO,CAAC,CAAA;gBAC7C,MAAM,OAAO,CAAC,YAAY,CAAC,QAAQ,CAAC,UAAU,EAAE,OAAO,EAAE,OAAO,CAAC,KAAK,CAAC,CAAA;gBACvE,MAAM,QAAQ,GAAG,MAAM,OAAO,CAAC,MAAM,CAAC,aAAa,CAAC,OAAO,EAAE,OAAO,CAAC,KAAK,CAAC,CAAA;gBAC3E,OAAO,gBAAgB,CAAC;oBACtB,SAAS,EAAE,UAAU;oBACrB,IAAI;oBACJ,OAAO;oBACP,QAAQ;oBACR,OAAO;oBACP,YAAY;oBACZ,OAAO;iBACR,CAAC,CAAA;YACJ,CAAC,CAAC,CAAA;QACJ,CAAC;KACF,CAAC,CAAA;AACJ,CAAC"}
@@ -0,0 +1,19 @@
1
+ import type { ToolContext, ToolResult } from "@opencode-ai/plugin";
2
+ import type { GenerateImageArgs, OpenRouterImageRequest, OpenRouterImageResponse } from "../openrouter/schemas.js";
3
+ import type { ResolvedReferences } from "../references/attachments.js";
4
+ import type { RuntimeServices, ToolDependencies } from "./types.js";
5
+ export type GenerationOperation = "edit" | "generate";
6
+ interface FinishGenerationOptions {
7
+ operation: GenerationOperation;
8
+ args: GenerateImageArgs;
9
+ request: OpenRouterImageRequest;
10
+ response: OpenRouterImageResponse;
11
+ runtime: RuntimeServices;
12
+ dependencies: ToolDependencies;
13
+ context: ToolContext;
14
+ references?: ResolvedReferences;
15
+ }
16
+ export declare function preflightOutput(runtime: RuntimeServices, args: GenerateImageArgs, context: ToolContext, sourcePaths?: ReadonlySet<string>): Promise<void>;
17
+ export declare function finishGeneration(options: FinishGenerationOptions): Promise<ToolResult>;
18
+ export {};
19
+ //# sourceMappingURL=generation.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generation.d.ts","sourceRoot":"","sources":["../../src/tools/generation.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAA;AAIlE,OAAO,KAAK,EACV,iBAAiB,EACjB,sBAAsB,EACtB,uBAAuB,EACxB,MAAM,0BAA0B,CAAA;AAcjC,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,8BAA8B,CAAA;AACtE,OAAO,KAAK,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAA;AAEnE,MAAM,MAAM,mBAAmB,GAAG,MAAM,GAAG,UAAU,CAAA;AAErD,UAAU,uBAAuB;IAC/B,SAAS,EAAE,mBAAmB,CAAA;IAC9B,IAAI,EAAE,iBAAiB,CAAA;IACvB,OAAO,EAAE,sBAAsB,CAAA;IAC/B,QAAQ,EAAE,uBAAuB,CAAA;IACjC,OAAO,EAAE,eAAe,CAAA;IACxB,YAAY,EAAE,gBAAgB,CAAA;IAC9B,OAAO,EAAE,WAAW,CAAA;IACpB,UAAU,CAAC,EAAE,kBAAkB,CAAA;CAChC;AA+DD,wBAAsB,eAAe,CACnC,OAAO,EAAE,eAAe,EACxB,IAAI,EAAE,iBAAiB,EACvB,OAAO,EAAE,WAAW,EACpB,WAAW,GAAE,WAAW,CAAC,MAAM,CAAa,GAC3C,OAAO,CAAC,IAAI,CAAC,CA6Cf;AAiDD,wBAAsB,gBAAgB,CACpC,OAAO,EAAE,uBAAuB,GAC/B,OAAO,CAAC,UAAU,CAAC,CA0DrB"}
@@ -0,0 +1,154 @@
1
+ import { realpath } from "node:fs/promises";
2
+ import path from "node:path";
3
+ import { promptFingerprint } from "../logging.js";
4
+ import { PluginError } from "../openrouter/errors.js";
5
+ import { ImageSaveError, assertOutputParentContained, assertSafeOutputRelativePath, createToolAttachments, decodeOutputImages, saveImages, } from "../output/index.js";
6
+ import { isPathInside, sameCanonicalPath, } from "../references/project-files.js";
7
+ function isMissingPathError(error) {
8
+ return (typeof error === "object" &&
9
+ error !== null &&
10
+ "code" in error &&
11
+ error.code === "ENOENT");
12
+ }
13
+ async function canonicalizeExistingOutput(absolute) {
14
+ try {
15
+ return await realpath(absolute);
16
+ }
17
+ catch (error) {
18
+ if (isMissingPathError(error))
19
+ return undefined;
20
+ throw new PluginError("GENIMAGE_OUTPUT_WRITE_FAILED", "The output path could not be inspected before generation.", { cause: error });
21
+ }
22
+ }
23
+ function isRecord(value) {
24
+ return typeof value === "object" && value !== null && !Array.isArray(value);
25
+ }
26
+ function responseData(response) {
27
+ if (!isRecord(response) || !Array.isArray(response.data) || response.data.length === 0) {
28
+ throw new PluginError("GENIMAGE_RESPONSE_INVALID", "OpenRouter returned no generated images.");
29
+ }
30
+ if (response.data.length > 10) {
31
+ throw new PluginError("GENIMAGE_RESPONSE_INVALID", "OpenRouter returned more than the maximum of 10 images.");
32
+ }
33
+ return response.data;
34
+ }
35
+ function responseCost(response) {
36
+ if (!isRecord(response) || !isRecord(response.usage))
37
+ return undefined;
38
+ const cost = response.usage.cost;
39
+ return typeof cost === "number" && Number.isFinite(cost) && cost >= 0
40
+ ? cost
41
+ : undefined;
42
+ }
43
+ function formatCost(value) {
44
+ if (value === undefined)
45
+ return "not reported";
46
+ if (value !== 0 && value < 0.000001)
47
+ return `$${value.toExponential(6)}`;
48
+ return `$${value.toFixed(6)}`;
49
+ }
50
+ export async function preflightOutput(runtime, args, context, sourcePaths = new Set()) {
51
+ const configuredDirectory = assertSafeOutputRelativePath(runtime.options.outputDirectory, "directory");
52
+ const relative = args.output_path === undefined
53
+ ? configuredDirectory
54
+ : assertSafeOutputRelativePath(args.output_path);
55
+ const canonicalWorktree = await realpath(context.worktree);
56
+ const absolute = path.resolve(canonicalWorktree, relative.replaceAll("/", path.sep));
57
+ await assertOutputParentContained(canonicalWorktree, args.output_path === undefined ? absolute : path.dirname(absolute));
58
+ const canonicalOutput = args.output_path === undefined
59
+ ? undefined
60
+ : await canonicalizeExistingOutput(absolute);
61
+ if (canonicalOutput !== undefined &&
62
+ !isPathInside(canonicalWorktree, canonicalOutput)) {
63
+ throw new PluginError("GENIMAGE_OUTPUT_OUTSIDE_WORKTREE", "The output path resolves outside the OpenCode worktree.");
64
+ }
65
+ if ([...sourcePaths].some((source) => sameCanonicalPath(source, absolute) ||
66
+ (canonicalOutput !== undefined &&
67
+ sameCanonicalPath(source, canonicalOutput)))) {
68
+ throw new PluginError("GENIMAGE_SOURCE_OVERWRITE_FORBIDDEN", "The output path may not overwrite a source image.");
69
+ }
70
+ }
71
+ function toolResult(operation, runtime, saved, requestedCount, referenceCount, costUsd, warnings) {
72
+ const verb = operation === "edit" ? "Edited" : "Generated";
73
+ const lines = [
74
+ `${verb} ${saved.length} image${saved.length === 1 ? "" : "s"}.`,
75
+ "",
76
+ ...saved.map((image) => `- \`${image.relativePath}\``),
77
+ "",
78
+ `Model: ${runtime.options.model}`,
79
+ `Routing: ${runtime.options.routing}`,
80
+ `References: ${referenceCount}`,
81
+ `Requested: ${requestedCount}`,
82
+ `Returned: ${saved.length}`,
83
+ `OpenRouter cost: ${formatCost(costUsd)}`,
84
+ ];
85
+ if (warnings.length > 0) {
86
+ lines.push("", "Warnings:", ...warnings.map((warning) => `- ${warning}`));
87
+ }
88
+ return {
89
+ title: `${verb} ${saved.length} image${saved.length === 1 ? "" : "s"}`,
90
+ output: lines.join("\n"),
91
+ metadata: {
92
+ model: runtime.options.model,
93
+ routing: runtime.options.routing,
94
+ referenceCount,
95
+ requestedCount,
96
+ returnedCount: saved.length,
97
+ ...(costUsd === undefined ? {} : { costUsd }),
98
+ images: saved.map((image) => ({
99
+ path: image.relativePath,
100
+ mime: image.mime,
101
+ bytes: image.bytes,
102
+ })),
103
+ warnings: [...warnings],
104
+ },
105
+ attachments: createToolAttachments(saved),
106
+ };
107
+ }
108
+ export async function finishGeneration(options) {
109
+ const rawImages = responseData(options.response);
110
+ const requestedCount = options.request.n ?? 1;
111
+ const decoded = decodeOutputImages(rawImages, {
112
+ maxDecodedBytes: options.runtime.options.maxDecodedBytes,
113
+ ...(options.request.output_format === undefined
114
+ ? {}
115
+ : { expectedFormat: options.request.output_format }),
116
+ });
117
+ const warnings = [...decoded.warnings];
118
+ if (rawImages.length < requestedCount) {
119
+ warnings.push(`OpenRouter returned ${rawImages.length} image(s), fewer than the ${requestedCount} requested.`);
120
+ }
121
+ let saved;
122
+ try {
123
+ saved = await saveImages({
124
+ images: decoded.images,
125
+ outputDirectory: options.runtime.options.outputDirectory,
126
+ ...(options.args.output_path === undefined
127
+ ? {}
128
+ : { outputPath: options.args.output_path }),
129
+ worktree: options.context.worktree,
130
+ sourcePaths: [...(options.references?.canonicalSourcePaths ?? [])],
131
+ signal: options.context.abort,
132
+ });
133
+ }
134
+ catch (error) {
135
+ if (!(error instanceof ImageSaveError) || error.savedImages.length === 0)
136
+ throw error;
137
+ saved = [...error.savedImages];
138
+ warnings.push(`${saved.length} image(s) were saved before a later output write failed (${error.code}).`);
139
+ }
140
+ warnings.push(...saved.flatMap((image) => image.warnings));
141
+ const uniqueWarnings = [...new Set(warnings)];
142
+ options.dependencies.logger.log("info", "OpenRouter image generation completed.", {
143
+ routing: options.runtime.options.routing,
144
+ model: options.runtime.options.model,
145
+ referenceCount: options.references?.references.length ?? 0,
146
+ inputBytes: options.references?.localBytes ?? 0,
147
+ outputBytes: saved.reduce((total, image) => total + image.bytes, 0),
148
+ requestedCount,
149
+ returnedCount: saved.length,
150
+ ...promptFingerprint(options.args.prompt),
151
+ });
152
+ return toolResult(options.operation, options.runtime, saved, requestedCount, options.references?.references.length ?? 0, responseCost(options.response), uniqueWarnings);
153
+ }
154
+ //# sourceMappingURL=generation.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generation.js","sourceRoot":"","sources":["../../src/tools/generation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAA;AAC3C,OAAO,IAAI,MAAM,WAAW,CAAA;AAG5B,OAAO,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAA;AACjD,OAAO,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AAK,EAAE,CAAC,CAAC;QACnE,cAAc;QACd,aAAa,EAAE,KAAK,CAAC,MAAM;QAC3B,GAAG,iBAAiB,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC;KAC1C,CAAC,CAAA;IAEF,OAAO,UAAU,CACf,OAAO,CAAC,SAAS,EACjB,OAAO,CAAC,OAAO,EACf,KAAK,EACL,cAAc,EACd,OAAO,CAAC,UAAU,EAAE,UAAU,CAAC,MAAM,IAAI,CAAC,EAC1C,YAAY,CAAC,OAAO,CAAC,QAAQ,CAAC,EAC9B,cAAc,CACf,CAAA;AACH,CAAC"}
@@ -0,0 +1,127 @@
1
+ export declare const generationToolArgs: {
2
+ prompt: import("zod").ZodString;
3
+ output_path: import("zod").ZodOptional<import("zod").ZodString>;
4
+ aspect_ratio: import("zod").ZodOptional<import("zod").ZodEnum<{
5
+ auto: "auto";
6
+ "1:1": "1:1";
7
+ "1:2": "1:2";
8
+ "1:4": "1:4";
9
+ "1:8": "1:8";
10
+ "2:1": "2:1";
11
+ "2:3": "2:3";
12
+ "3:2": "3:2";
13
+ "3:4": "3:4";
14
+ "4:1": "4:1";
15
+ "4:3": "4:3";
16
+ "4:5": "4:5";
17
+ "5:4": "5:4";
18
+ "8:1": "8:1";
19
+ "9:16": "9:16";
20
+ "16:9": "16:9";
21
+ "9:19.5": "9:19.5";
22
+ "19.5:9": "19.5:9";
23
+ "9:20": "9:20";
24
+ "20:9": "20:9";
25
+ "9:21": "9:21";
26
+ "21:9": "21:9";
27
+ }>>;
28
+ background: import("zod").ZodOptional<import("zod").ZodEnum<{
29
+ transparent: "transparent";
30
+ auto: "auto";
31
+ opaque: "opaque";
32
+ }>>;
33
+ n: import("zod").ZodOptional<import("zod").ZodNumber>;
34
+ output_format: import("zod").ZodOptional<import("zod").ZodEnum<{
35
+ png: "png";
36
+ jpeg: "jpeg";
37
+ webp: "webp";
38
+ }>>;
39
+ output_compression: import("zod").ZodOptional<import("zod").ZodNumber>;
40
+ quality: import("zod").ZodOptional<import("zod").ZodEnum<{
41
+ auto: "auto";
42
+ high: "high";
43
+ low: "low";
44
+ medium: "medium";
45
+ }>>;
46
+ resolution: import("zod").ZodOptional<import("zod").ZodEnum<{
47
+ 512: "512";
48
+ "1K": "1K";
49
+ "2K": "2K";
50
+ "4K": "4K";
51
+ }>>;
52
+ seed: import("zod").ZodOptional<import("zod").ZodNumber>;
53
+ };
54
+ export declare const imageReferenceSchema: import("zod").ZodDiscriminatedUnion<[import("zod").ZodObject<{
55
+ type: import("zod").ZodLiteral<"message_attachment">;
56
+ index: import("zod").ZodNumber;
57
+ }, import("zod/v4/core").$strict>, import("zod").ZodObject<{
58
+ type: import("zod").ZodLiteral<"project_file">;
59
+ path: import("zod").ZodString;
60
+ }, import("zod/v4/core").$strict>, import("zod").ZodObject<{
61
+ type: import("zod").ZodLiteral<"https_url">;
62
+ url: import("zod").ZodString;
63
+ }, import("zod/v4/core").$strict>], "type">;
64
+ export declare const editToolArgs: {
65
+ references: import("zod").ZodOptional<import("zod").ZodArray<import("zod").ZodDiscriminatedUnion<[import("zod").ZodObject<{
66
+ type: import("zod").ZodLiteral<"message_attachment">;
67
+ index: import("zod").ZodNumber;
68
+ }, import("zod/v4/core").$strict>, import("zod").ZodObject<{
69
+ type: import("zod").ZodLiteral<"project_file">;
70
+ path: import("zod").ZodString;
71
+ }, import("zod/v4/core").$strict>, import("zod").ZodObject<{
72
+ type: import("zod").ZodLiteral<"https_url">;
73
+ url: import("zod").ZodString;
74
+ }, import("zod/v4/core").$strict>], "type">>>;
75
+ prompt: import("zod").ZodString;
76
+ output_path: import("zod").ZodOptional<import("zod").ZodString>;
77
+ aspect_ratio: import("zod").ZodOptional<import("zod").ZodEnum<{
78
+ auto: "auto";
79
+ "1:1": "1:1";
80
+ "1:2": "1:2";
81
+ "1:4": "1:4";
82
+ "1:8": "1:8";
83
+ "2:1": "2:1";
84
+ "2:3": "2:3";
85
+ "3:2": "3:2";
86
+ "3:4": "3:4";
87
+ "4:1": "4:1";
88
+ "4:3": "4:3";
89
+ "4:5": "4:5";
90
+ "5:4": "5:4";
91
+ "8:1": "8:1";
92
+ "9:16": "9:16";
93
+ "16:9": "16:9";
94
+ "9:19.5": "9:19.5";
95
+ "19.5:9": "19.5:9";
96
+ "9:20": "9:20";
97
+ "20:9": "20:9";
98
+ "9:21": "9:21";
99
+ "21:9": "21:9";
100
+ }>>;
101
+ background: import("zod").ZodOptional<import("zod").ZodEnum<{
102
+ transparent: "transparent";
103
+ auto: "auto";
104
+ opaque: "opaque";
105
+ }>>;
106
+ n: import("zod").ZodOptional<import("zod").ZodNumber>;
107
+ output_format: import("zod").ZodOptional<import("zod").ZodEnum<{
108
+ png: "png";
109
+ jpeg: "jpeg";
110
+ webp: "webp";
111
+ }>>;
112
+ output_compression: import("zod").ZodOptional<import("zod").ZodNumber>;
113
+ quality: import("zod").ZodOptional<import("zod").ZodEnum<{
114
+ auto: "auto";
115
+ high: "high";
116
+ low: "low";
117
+ medium: "medium";
118
+ }>>;
119
+ resolution: import("zod").ZodOptional<import("zod").ZodEnum<{
120
+ 512: "512";
121
+ "1K": "1K";
122
+ "2K": "2K";
123
+ "4K": "4K";
124
+ }>>;
125
+ seed: import("zod").ZodOptional<import("zod").ZodNumber>;
126
+ };
127
+ //# sourceMappingURL=schema.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../src/tools/schema.ts"],"names":[],"mappings":"AAoBA,eAAO,MAAM,kBAAkB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAW9B,CAAA;AAED,eAAO,MAAM,oBAAoB;;;;;;;;;2CAmB/B,CAAA;AAEF,eAAO,MAAM,YAAY;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAGxB,CAAA"}
@@ -0,0 +1,47 @@
1
+ import { tool } from "@opencode-ai/plugin";
2
+ import { IMAGE_ASPECT_RATIOS, IMAGE_BACKGROUNDS, IMAGE_OUTPUT_FORMATS, IMAGE_QUALITIES, IMAGE_RESOLUTIONS, } from "../config/types.js";
3
+ const prompt = tool.schema
4
+ .string()
5
+ .max(32_000)
6
+ .refine((value) => value.trim().length > 0, "Prompt must not be empty.");
7
+ const outputPath = tool.schema
8
+ .string()
9
+ .max(4_096)
10
+ .refine((value) => value.trim().length > 0, "Output path must not be empty.");
11
+ export const generationToolArgs = {
12
+ prompt,
13
+ output_path: outputPath.optional(),
14
+ aspect_ratio: tool.schema.enum(IMAGE_ASPECT_RATIOS).optional(),
15
+ background: tool.schema.enum(IMAGE_BACKGROUNDS).optional(),
16
+ n: tool.schema.number().int().min(1).max(10).optional(),
17
+ output_format: tool.schema.enum(IMAGE_OUTPUT_FORMATS).optional(),
18
+ output_compression: tool.schema.number().int().min(0).max(100).optional(),
19
+ quality: tool.schema.enum(IMAGE_QUALITIES).optional(),
20
+ resolution: tool.schema.enum(IMAGE_RESOLUTIONS).optional(),
21
+ seed: tool.schema.number().int().nonnegative().optional(),
22
+ };
23
+ export const imageReferenceSchema = tool.schema.discriminatedUnion("type", [
24
+ tool.schema
25
+ .object({
26
+ type: tool.schema.literal("message_attachment"),
27
+ index: tool.schema.number().int().min(1),
28
+ })
29
+ .strict(),
30
+ tool.schema
31
+ .object({
32
+ type: tool.schema.literal("project_file"),
33
+ path: tool.schema.string().min(1).max(4_096),
34
+ })
35
+ .strict(),
36
+ tool.schema
37
+ .object({
38
+ type: tool.schema.literal("https_url"),
39
+ url: tool.schema.string().min(1).max(8_192),
40
+ })
41
+ .strict(),
42
+ ]);
43
+ export const editToolArgs = {
44
+ ...generationToolArgs,
45
+ references: tool.schema.array(imageReferenceSchema).max(16).optional(),
46
+ };
47
+ //# sourceMappingURL=schema.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schema.js","sourceRoot":"","sources":["../../src/tools/schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM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C,oBAAoB,CAAC,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,QAAQ,EAAE;CACvE,CAAA"}
@@ -0,0 +1,18 @@
1
+ import type { PluginConfigState, ResolvedPluginOptions } from "../config/types.js";
2
+ import type { SafeLogger } from "../logging.js";
3
+ import type { ModelCapabilityService } from "../openrouter/capabilities.js";
4
+ import type { OpenRouterImageClient } from "../openrouter/client.js";
5
+ import type { OpenCodeMessageClient } from "../references/attachments.js";
6
+ export interface RuntimeServices {
7
+ options: ResolvedPluginOptions;
8
+ client: OpenRouterImageClient;
9
+ capabilities: ModelCapabilityService;
10
+ }
11
+ export interface ToolDependencies {
12
+ configState: PluginConfigState;
13
+ getRuntime(): RuntimeServices;
14
+ messageClient: OpenCodeMessageClient;
15
+ serverUrl: URL;
16
+ logger: SafeLogger;
17
+ }
18
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/tools/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAA;AAClF,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,eAAe,CAAA;AAC/C,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,+BAA+B,CAAA;AAC3E,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAA;AACpE,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,8BAA8B,CAAA;AAEzE,MAAM,WAAW,eAAe;IAC9B,OAAO,EAAE,qBAAqB,CAAA;IAC9B,MAAM,EAAE,qBAAqB,CAAA;IAC7B,YAAY,EAAE,sBAAsB,CAAA;CACrC;AAED,MAAM,WAAW,gBAAgB;IAC/B,WAAW,EAAE,iBAAiB,CAAA;IAC9B,UAAU,IAAI,eAAe,CAAA;IAC7B,aAAa,EAAE,qBAAqB,CAAA;IACpC,SAAS,EAAE,GAAG,CAAA;IACd,MAAM,EAAE,UAAU,CAAA;CACnB"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/tools/types.ts"],"names":[],"mappings":""}
@@ -0,0 +1,10 @@
1
+ import type { HttpTransport } from "./types.js";
2
+ export type FetchLike = (input: string | URL | Request, init?: RequestInit) => Promise<Response>;
3
+ /** A fetch implementation that cannot be replaced by another plugin's global wrapper. */
4
+ export declare const nativeFetch: FetchLike;
5
+ export declare class DirectTransport implements HttpTransport {
6
+ #private;
7
+ constructor(fetchImplementation?: FetchLike);
8
+ request(url: URL, init: RequestInit, signal: AbortSignal): Promise<Response>;
9
+ }
10
+ //# sourceMappingURL=direct.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"direct.d.ts","sourceRoot":"","sources":["../../src/transport/direct.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAA;AAG/C,MAAM,MAAM,SAAS,GAAG,CACtB,KAAK,EAAE,MAAM,GAAG,GAAG,GAAG,OAAO,EAC7B,IAAI,CAAC,EAAE,WAAW,KACf,OAAO,CAAC,QAAQ,CAAC,CAAA;AAEtB,yFAAyF;AACzF,eAAO,MAAM,WAAW,EAAE,SAGiB,CAAA;AAE3C,qBAAa,eAAgB,YAAW,aAAa;;gBAGvC,mBAAmB,GAAE,SAAuB;IAIxD,OAAO,CAAC,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,WAAW,EAAE,MAAM,EAAE,WAAW,GAAG,OAAO,CAAC,QAAQ,CAAC;CAG7E"}
@@ -0,0 +1,15 @@
1
+ import { fetch as undiciFetch } from "undici";
2
+ /** A fetch implementation that cannot be replaced by another plugin's global wrapper. */
3
+ export const nativeFetch = typeof Bun !== "undefined" && typeof Bun.fetch === "function"
4
+ ? Bun.fetch.bind(Bun)
5
+ : undiciFetch;
6
+ export class DirectTransport {
7
+ #fetch;
8
+ constructor(fetchImplementation = nativeFetch) {
9
+ this.#fetch = fetchImplementation;
10
+ }
11
+ request(url, init, signal) {
12
+ return this.#fetch(url, { ...init, signal });
13
+ }
14
+ }
15
+ //# sourceMappingURL=direct.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"direct.js","sourceRoot":"","sources":["../../src/transport/direct.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,IAAI,WAAW,EAAE,MAAM,QAAQ,CAAA;AAO7C,yFAAyF;AACzF,MAAM,CAAC,MAAM,WAAW,GACtB,OAAO,GAAG,KAAK,WAAW,IAAI,OAAO,GAAG,CAAC,KAAK,KAAK,UAAU;IAC3D,CAAC,CAAE,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,CAA0B;IAC/C,CAAC,CAAE,WAAoC,CAAA;AAE3C,MAAM,OAAO,eAAe;IACjB,MAAM,CAAW;IAE1B,YAAY,sBAAiC,WAAW;QACtD,IAAI,CAAC,MAAM,GAAG,mBAAmB,CAAA;IACnC,CAAC;IAED,OAAO,CAAC,GAAQ,EAAE,IAAiB,EAAE,MAAmB;QACtD,OAAO,IAAI,CAAC,MAAM,CAAC,GAAG,EAAE,EAAE,GAAG,IAAI,EAAE,MAAM,EAAE,CAAC,CAAA;IAC9C,CAAC;CACF"}
@@ -0,0 +1,4 @@
1
+ export { DirectTransport, type FetchLike } from "./direct.js";
2
+ export { KoteGatewayTransport, type KoteGatewayTransportOptions, } from "./kote-gateway.js";
3
+ export { GatewayTransportError, type GatewayErrorCode, type HttpTransport, } from "./types.js";
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/transport/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,KAAK,SAAS,EAAE,MAAM,aAAa,CAAA;AAC7D,OAAO,EACL,oBAAoB,EACpB,KAAK,2BAA2B,GACjC,MAAM,mBAAmB,CAAA;AAC1B,OAAO,EACL,qBAAqB,EACrB,KAAK,gBAAgB,EACrB,KAAK,aAAa,GACnB,MAAM,YAAY,CAAA"}
@@ -0,0 +1,4 @@
1
+ export { DirectTransport } from "./direct.js";
2
+ export { KoteGatewayTransport, } from "./kote-gateway.js";
3
+ export { GatewayTransportError, } from "./types.js";
4
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/transport/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAkB,MAAM,aAAa,CAAA;AAC7D,OAAO,EACL,oBAAoB,GAErB,MAAM,mBAAmB,CAAA;AAC1B,OAAO,EACL,qBAAqB,GAGtB,MAAM,YAAY,CAAA"}