@nodetool-ai/transformers-js-nodes 0.7.0-rc.11

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 (93) hide show
  1. package/dist/cache-scan.d.ts +26 -0
  2. package/dist/cache-scan.d.ts.map +1 -0
  3. package/dist/cache-scan.js +112 -0
  4. package/dist/cache-scan.js.map +1 -0
  5. package/dist/index.d.ts +28 -0
  6. package/dist/index.d.ts.map +1 -0
  7. package/dist/index.js +62 -0
  8. package/dist/index.js.map +1 -0
  9. package/dist/nodes/audio-classification.d.ts +22 -0
  10. package/dist/nodes/audio-classification.d.ts.map +1 -0
  11. package/dist/nodes/audio-classification.js +102 -0
  12. package/dist/nodes/audio-classification.js.map +1 -0
  13. package/dist/nodes/automatic-speech-recognition.d.ts +22 -0
  14. package/dist/nodes/automatic-speech-recognition.d.ts.map +1 -0
  15. package/dist/nodes/automatic-speech-recognition.js +129 -0
  16. package/dist/nodes/automatic-speech-recognition.js.map +1 -0
  17. package/dist/nodes/feature-extraction.d.ts +20 -0
  18. package/dist/nodes/feature-extraction.d.ts.map +1 -0
  19. package/dist/nodes/feature-extraction.js +153 -0
  20. package/dist/nodes/feature-extraction.js.map +1 -0
  21. package/dist/nodes/fill-mask.d.ts +19 -0
  22. package/dist/nodes/fill-mask.d.ts.map +1 -0
  23. package/dist/nodes/fill-mask.js +87 -0
  24. package/dist/nodes/fill-mask.js.map +1 -0
  25. package/dist/nodes/image-classification.d.ts +21 -0
  26. package/dist/nodes/image-classification.d.ts.map +1 -0
  27. package/dist/nodes/image-classification.js +90 -0
  28. package/dist/nodes/image-classification.js.map +1 -0
  29. package/dist/nodes/image-to-text.d.ts +19 -0
  30. package/dist/nodes/image-to-text.d.ts.map +1 -0
  31. package/dist/nodes/image-to-text.js +81 -0
  32. package/dist/nodes/image-to-text.js.map +1 -0
  33. package/dist/nodes/object-detection.d.ts +20 -0
  34. package/dist/nodes/object-detection.d.ts.map +1 -0
  35. package/dist/nodes/object-detection.js +93 -0
  36. package/dist/nodes/object-detection.js.map +1 -0
  37. package/dist/nodes/question-answering.d.ts +23 -0
  38. package/dist/nodes/question-answering.d.ts.map +1 -0
  39. package/dist/nodes/question-answering.js +108 -0
  40. package/dist/nodes/question-answering.js.map +1 -0
  41. package/dist/nodes/summarization.d.ts +20 -0
  42. package/dist/nodes/summarization.d.ts.map +1 -0
  43. package/dist/nodes/summarization.js +103 -0
  44. package/dist/nodes/summarization.js.map +1 -0
  45. package/dist/nodes/text-classification.d.ts +20 -0
  46. package/dist/nodes/text-classification.d.ts.map +1 -0
  47. package/dist/nodes/text-classification.js +93 -0
  48. package/dist/nodes/text-classification.js.map +1 -0
  49. package/dist/nodes/text-generation.d.ts +23 -0
  50. package/dist/nodes/text-generation.d.ts.map +1 -0
  51. package/dist/nodes/text-generation.js +150 -0
  52. package/dist/nodes/text-generation.js.map +1 -0
  53. package/dist/nodes/text-to-speech.d.ts +20 -0
  54. package/dist/nodes/text-to-speech.d.ts.map +1 -0
  55. package/dist/nodes/text-to-speech.js +122 -0
  56. package/dist/nodes/text-to-speech.js.map +1 -0
  57. package/dist/nodes/token-classification.d.ts +18 -0
  58. package/dist/nodes/token-classification.d.ts.map +1 -0
  59. package/dist/nodes/token-classification.js +88 -0
  60. package/dist/nodes/token-classification.js.map +1 -0
  61. package/dist/nodes/translation.d.ts +20 -0
  62. package/dist/nodes/translation.d.ts.map +1 -0
  63. package/dist/nodes/translation.js +106 -0
  64. package/dist/nodes/translation.js.map +1 -0
  65. package/dist/nodes/zero-shot-classification.d.ts +23 -0
  66. package/dist/nodes/zero-shot-classification.d.ts.map +1 -0
  67. package/dist/nodes/zero-shot-classification.js +128 -0
  68. package/dist/nodes/zero-shot-classification.js.map +1 -0
  69. package/dist/nodes/zero-shot-image-classification.d.ts +21 -0
  70. package/dist/nodes/zero-shot-image-classification.d.ts.map +1 -0
  71. package/dist/nodes/zero-shot-image-classification.js +101 -0
  72. package/dist/nodes/zero-shot-image-classification.js.map +1 -0
  73. package/dist/recommended-models.d.ts +32 -0
  74. package/dist/recommended-models.d.ts.map +1 -0
  75. package/dist/recommended-models.js +140 -0
  76. package/dist/recommended-models.js.map +1 -0
  77. package/dist/tjs-downloader.d.ts +44 -0
  78. package/dist/tjs-downloader.d.ts.map +1 -0
  79. package/dist/tjs-downloader.js +84 -0
  80. package/dist/tjs-downloader.js.map +1 -0
  81. package/dist/transformers-base.d.ts +156 -0
  82. package/dist/transformers-base.d.ts.map +1 -0
  83. package/dist/transformers-base.js +435 -0
  84. package/dist/transformers-base.js.map +1 -0
  85. package/dist/tts-shared.d.ts +16 -0
  86. package/dist/tts-shared.d.ts.map +1 -0
  87. package/dist/tts-shared.js +51 -0
  88. package/dist/tts-shared.js.map +1 -0
  89. package/dist/wav.d.ts +23 -0
  90. package/dist/wav.d.ts.map +1 -0
  91. package/dist/wav.js +115 -0
  92. package/dist/wav.js.map +1 -0
  93. package/package.json +50 -0
@@ -0,0 +1,153 @@
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ import { BaseNode, prop } from "@nodetool-ai/node-sdk";
8
+ import { DEVICE_VALUES, DTYPE_VALUES, asString, extractRepoId, getPipeline, tjsModelDefault, normalizeOption } from "../transformers-base.js";
9
+ import { defaultRepoFor } from "../recommended-models.js";
10
+ const TJS_TYPE = "tjs.feature_extraction";
11
+ function meanPool(matrix) {
12
+ if (matrix.length === 0)
13
+ return [];
14
+ const dim = matrix[0]?.length ?? 0;
15
+ const out = new Array(dim).fill(0);
16
+ for (const row of matrix) {
17
+ for (let i = 0; i < dim; i++) {
18
+ out[i] += Number(row[i] ?? 0);
19
+ }
20
+ }
21
+ for (let i = 0; i < dim; i++) {
22
+ out[i] /= matrix.length;
23
+ }
24
+ return out;
25
+ }
26
+ /**
27
+ * Reduce a feature-extraction tensor to a single 1-D embedding vector.
28
+ *
29
+ * Transformers.js returns differently-shaped tensors depending on whether
30
+ * the caller asked for pooling:
31
+ * - pooled (mean / cls): shape `[batch, dim]` → take batch[0]
32
+ * - no pooling: shape `[batch, seq, dim]` → mean-pool seq
33
+ * - already 1-D: shape `[dim]` → pass through
34
+ *
35
+ * Falling back to the flat `.data` buffer drops shape information and is
36
+ * only safe when the tensor is already known to be 1-D.
37
+ */
38
+ function tensorToVector(tensor) {
39
+ if (!tensor || typeof tensor !== "object")
40
+ return [];
41
+ const t = tensor;
42
+ if (typeof t.tolist === "function") {
43
+ const nested = t.tolist();
44
+ if (Array.isArray(nested)) {
45
+ const first = nested[0];
46
+ if (Array.isArray(first) && Array.isArray(first[0])) {
47
+ // [batch][seq][dim] — pool sequence axis to a single vector.
48
+ return meanPool(first.map((row) => row));
49
+ }
50
+ if (Array.isArray(first)) {
51
+ // [batch][dim] — already pooled by the pipeline.
52
+ return first.map(Number);
53
+ }
54
+ return nested.map(Number);
55
+ }
56
+ }
57
+ if (t.data && t.dims && t.dims.length === 1) {
58
+ return Array.from(t.data, Number);
59
+ }
60
+ if (t.data && (!t.dims || t.dims.length === 0)) {
61
+ return Array.from(t.data, Number);
62
+ }
63
+ return [];
64
+ }
65
+ export class FeatureExtractionNode extends BaseNode {
66
+ static nodeType = "transformers.FeatureExtraction";
67
+ static title = "Feature Extraction (Embeddings)";
68
+ static description = "Compute text embeddings using a Transformers.js feature-extraction pipeline.\n" +
69
+ "nlp, embeddings, vectors, transformers, huggingface, semantic-search\n\n" +
70
+ "Use cases:\n" +
71
+ "- Build semantic search or RAG pipelines\n" +
72
+ "- Cluster or deduplicate documents\n" +
73
+ "- Compute sentence similarity";
74
+ static metadataOutputTypes = {
75
+ embedding: "list",
76
+ dim: "int"
77
+ };
78
+ async process() {
79
+ const text = asString(this.text);
80
+ if (!text)
81
+ throw new Error("Text is required");
82
+ const pipeline = (await getPipeline({
83
+ task: "feature-extraction",
84
+ model: extractRepoId(this.model) || undefined,
85
+ dtype: normalizeOption(this.dtype),
86
+ device: normalizeOption(this.device)
87
+ }));
88
+ const opts = {
89
+ normalize: Boolean(this.normalize)
90
+ };
91
+ const pooling = asString(this.pooling, "mean");
92
+ if (pooling && pooling !== "none")
93
+ opts.pooling = pooling;
94
+ const tensor = await pipeline(text, opts);
95
+ const embedding = tensorToVector(tensor);
96
+ return { embedding, dim: embedding.length };
97
+ }
98
+ }
99
+ __decorate([
100
+ prop({
101
+ type: "str",
102
+ default: "Hello world",
103
+ title: "Text",
104
+ description: "Text to embed."
105
+ })
106
+ ], FeatureExtractionNode.prototype, "text", void 0);
107
+ __decorate([
108
+ prop({
109
+ type: TJS_TYPE,
110
+ default: tjsModelDefault(TJS_TYPE, defaultRepoFor(TJS_TYPE)),
111
+ title: "Model",
112
+ description: "Transformers.js model (ONNX-compatible)."
113
+ })
114
+ ], FeatureExtractionNode.prototype, "model", void 0);
115
+ __decorate([
116
+ prop({
117
+ type: "enum",
118
+ default: "mean",
119
+ title: "Pooling",
120
+ description: "Pooling strategy applied to the token embeddings.",
121
+ values: ["none", "mean", "cls"]
122
+ })
123
+ ], FeatureExtractionNode.prototype, "pooling", void 0);
124
+ __decorate([
125
+ prop({
126
+ type: "bool",
127
+ default: true,
128
+ title: "Normalize",
129
+ description: "L2-normalize the resulting embedding."
130
+ })
131
+ ], FeatureExtractionNode.prototype, "normalize", void 0);
132
+ __decorate([
133
+ prop({
134
+ type: "enum",
135
+ default: "auto",
136
+ title: "Quantization",
137
+ description: "Model dtype / quantization level.",
138
+ values: DTYPE_VALUES
139
+ })
140
+ ], FeatureExtractionNode.prototype, "dtype", void 0);
141
+ __decorate([
142
+ prop({
143
+ type: "enum",
144
+ default: "auto",
145
+ title: "Device",
146
+ description: "Inference device.",
147
+ values: DEVICE_VALUES
148
+ })
149
+ ], FeatureExtractionNode.prototype, "device", void 0);
150
+ export const FEATURE_EXTRACTION_NODES = [
151
+ FeatureExtractionNode
152
+ ];
153
+ //# sourceMappingURL=feature-extraction.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"feature-extraction.js","sourceRoot":"","sources":["../../src/nodes/feature-extraction.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,uBAAuB,CAAC;AAEvD,OAAO,EACL,aAAa,EACb,YAAY,EACZ,QAAQ,EACR,aAAa,EACb,WAAW,EACX,eAAe,EACf,eAAe,EAChB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAE1D,MAAM,QAAQ,GAAG,wBAAwB,CAAC;AAS1C,SAAS,QAAQ,CAAC,MAAkB;IAClC,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,EAAE,CAAC;IACnC,MAAM,GAAG,GAAG,MAAM,CAAC,CAAC,CAAC,EAAE,MAAM,IAAI,CAAC,CAAC;IACnC,MAAM,GAAG,GAAG,IAAI,KAAK,CAAS,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAC3C,KAAK,MAAM,GAAG,IAAI,MAAM,EAAE,CAAC;QACzB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,GAAG,EAAE,CAAC,EAAE,EAAE,CAAC;YAC7B,GAAG,CAAC,CAAC,CAAC,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC;QAChC,CAAC;IACH,CAAC;IACD,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,GAAG,EAAE,CAAC,EAAE,EAAE,CAAC;QAC7B,GAAG,CAAC,CAAC,CAAC,IAAI,MAAM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,GAAyB;IAC5D,qBAAqB;CACtB,CAAC"}
@@ -0,0 +1,19 @@
1
+ import { BaseNode } from "@nodetool-ai/node-sdk";
2
+ import type { NodeClass } from "@nodetool-ai/node-sdk";
3
+ export declare class FillMaskNode extends BaseNode {
4
+ static readonly nodeType = "transformers.FillMask";
5
+ static readonly title = "Fill Mask";
6
+ static readonly description: string;
7
+ static readonly metadataOutputTypes: {
8
+ top: string;
9
+ results: string;
10
+ };
11
+ text: any;
12
+ model: any;
13
+ top_k: any;
14
+ dtype: any;
15
+ device: any;
16
+ process(): Promise<Record<string, unknown>>;
17
+ }
18
+ export declare const FILL_MASK_NODES: readonly NodeClass[];
19
+ //# sourceMappingURL=fill-mask.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fill-mask.d.ts","sourceRoot":"","sources":["../../src/nodes/fill-mask.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAQ,MAAM,uBAAuB,CAAC;AACvD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAuBvD,qBAAa,YAAa,SAAQ,QAAQ;IACxC,MAAM,CAAC,QAAQ,CAAC,QAAQ,2BAA2B;IACnD,MAAM,CAAC,QAAQ,CAAC,KAAK,eAAe;IACpC,MAAM,CAAC,QAAQ,CAAC,WAAW,SAMQ;IACnC,MAAM,CAAC,QAAQ,CAAC,mBAAmB;;;MAGjC;IAQM,IAAI,EAAE,GAAG,CAAC;IAQV,KAAK,EAAE,GAAG,CAAC;IAUX,KAAK,EAAE,GAAG,CAAC;IASX,KAAK,EAAE,GAAG,CAAC;IASX,MAAM,EAAE,GAAG,CAAC;IAEd,OAAO,IAAI,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAqBlD;AAED,eAAO,MAAM,eAAe,EAAE,SAAS,SAAS,EAAmB,CAAC"}
@@ -0,0 +1,87 @@
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ import { BaseNode, prop } from "@nodetool-ai/node-sdk";
8
+ import { DEVICE_VALUES, DTYPE_VALUES, asNumber, asString, ensureArray, extractRepoId, getPipeline, tjsModelDefault, normalizeOption } from "../transformers-base.js";
9
+ import { defaultRepoFor } from "../recommended-models.js";
10
+ const TJS_TYPE = "tjs.fill_mask";
11
+ export class FillMaskNode extends BaseNode {
12
+ static nodeType = "transformers.FillMask";
13
+ static title = "Fill Mask";
14
+ static description = "Predict masked tokens in a sentence using a Transformers.js fill-mask pipeline.\n" +
15
+ "nlp, mask, transformers, huggingface\n\n" +
16
+ "Use cases:\n" +
17
+ "- Auto-complete missing words\n" +
18
+ "- Probe a model's lexical knowledge\n" +
19
+ "- Build cloze-style test items";
20
+ static metadataOutputTypes = {
21
+ top: "str",
22
+ results: "list"
23
+ };
24
+ async process() {
25
+ const text = asString(this.text);
26
+ if (!text)
27
+ throw new Error("Text is required");
28
+ const pipeline = (await getPipeline({
29
+ task: "fill-mask",
30
+ model: extractRepoId(this.model) || undefined,
31
+ dtype: normalizeOption(this.dtype),
32
+ device: normalizeOption(this.device)
33
+ }));
34
+ const raw = await pipeline(text, { top_k: asNumber(this.top_k, 5) });
35
+ const results = ensureArray(raw);
36
+ return {
37
+ top: results[0]?.token_str ?? "",
38
+ results
39
+ };
40
+ }
41
+ }
42
+ __decorate([
43
+ prop({
44
+ type: "str",
45
+ default: "The quick brown [MASK] jumps over the lazy dog.",
46
+ title: "Text",
47
+ description: "Text containing a single mask token (e.g. [MASK] or <mask>)."
48
+ })
49
+ ], FillMaskNode.prototype, "text", void 0);
50
+ __decorate([
51
+ prop({
52
+ type: TJS_TYPE,
53
+ default: tjsModelDefault(TJS_TYPE, defaultRepoFor(TJS_TYPE)),
54
+ title: "Model",
55
+ description: "Transformers.js model (ONNX-compatible)."
56
+ })
57
+ ], FillMaskNode.prototype, "model", void 0);
58
+ __decorate([
59
+ prop({
60
+ type: "int",
61
+ default: 5,
62
+ title: "Top K",
63
+ description: "Number of candidate fill-ins to return.",
64
+ min: 1,
65
+ max: 50
66
+ })
67
+ ], FillMaskNode.prototype, "top_k", void 0);
68
+ __decorate([
69
+ prop({
70
+ type: "enum",
71
+ default: "auto",
72
+ title: "Quantization",
73
+ description: "Model dtype / quantization level.",
74
+ values: DTYPE_VALUES
75
+ })
76
+ ], FillMaskNode.prototype, "dtype", void 0);
77
+ __decorate([
78
+ prop({
79
+ type: "enum",
80
+ default: "auto",
81
+ title: "Device",
82
+ description: "Inference device.",
83
+ values: DEVICE_VALUES
84
+ })
85
+ ], FillMaskNode.prototype, "device", void 0);
86
+ export const FILL_MASK_NODES = [FillMaskNode];
87
+ //# sourceMappingURL=fill-mask.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fill-mask.js","sourceRoot":"","sources":["../../src/nodes/fill-mask.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,uBAAuB,CAAC;AAEvD,OAAO,EACL,aAAa,EACb,YAAY,EACZ,QAAQ,EACR,QAAQ,EACR,WAAW,EACX,aAAa,EACb,WAAW,EACX,eAAe,EACf,eAAe,EAChB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAE1D,MAAM,QAAQ,GAAG,eAAe,CAAC;AASjC,MAAM,OAAO,YAAa,SAAQ,QAAQ;IACxC,MAAM,CAAU,QAAQ,GAAG,uBAAuB,CAAC;IACnD,MAAM,CAAU,KAAK,GAAG,WAAW,CAAC;IACpC,MAAM,CAAU,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ACd,WAAW,EAAE,0CAA0C;KACxD,CAAC;2CACiB;AAUX;IARP,IAAI,CAAC;QACJ,IAAI,EAAE,KAAK;QACX,OAAO,EAAE,CAAC;QACV,KAAK,EAAE,OAAO;QACd,WAAW,EAAE,yCAAyC;QACtD,GAAG,EAAE,CAAC;QACN,GAAG,EAAE,EAAE;KACR,CAAC;2CACiB;AASX;IAPP,IAAI,CAAC;QACJ,IAAI,EAAE,MAAM;QACZ,OAAO,EAAE,MAAM;QACf,KAAK,EAAE,cAAc;QACrB,WAAW,EAAE,mCAAmC;QAChD,MAAM,EAAE,YAAY;KACrB,CAAC;2CACiB;AASX;IAPP,IAAI,CAAC;QACJ,IAAI,EAAE,MAAM;QACZ,OAAO,EAAE,MAAM;QACf,KAAK,EAAE,QAAQ;QACf,WAAW,EAAE,mBAAmB;QAChC,MAAM,EAAE,aAAa;KACtB,CAAC;4CACkB;AAyBtB,MAAM,CAAC,MAAM,eAAe,GAAyB,CAAC,YAAY,CAAC,CAAC"}
@@ -0,0 +1,21 @@
1
+ import { BaseNode } from "@nodetool-ai/node-sdk";
2
+ import type { NodeClass } from "@nodetool-ai/node-sdk";
3
+ import type { ProcessingContext } from "@nodetool-ai/runtime";
4
+ export declare class ImageClassificationNode extends BaseNode {
5
+ static readonly nodeType = "transformers.ImageClassification";
6
+ static readonly title = "Image Classification";
7
+ static readonly description: string;
8
+ static readonly metadataOutputTypes: {
9
+ label: string;
10
+ score: string;
11
+ results: string;
12
+ };
13
+ image: any;
14
+ model: any;
15
+ top_k: any;
16
+ dtype: any;
17
+ device: any;
18
+ process(context?: ProcessingContext): Promise<Record<string, unknown>>;
19
+ }
20
+ export declare const IMAGE_CLASSIFICATION_NODES: readonly NodeClass[];
21
+ //# sourceMappingURL=image-classification.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"image-classification.d.ts","sourceRoot":"","sources":["../../src/nodes/image-classification.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAQ,MAAM,uBAAuB,CAAC;AACvD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAmB9D,qBAAa,uBAAwB,SAAQ,QAAQ;IACnD,MAAM,CAAC,QAAQ,CAAC,QAAQ,sCAAsC;IAC9D,MAAM,CAAC,QAAQ,CAAC,KAAK,0BAA0B;IAC/C,MAAM,CAAC,QAAQ,CAAC,WAAW,SAMM;IACjC,MAAM,CAAC,QAAQ,CAAC,mBAAmB;;;;MAIjC;IAQM,KAAK,EAAE,GAAG,CAAC;IAQX,KAAK,EAAE,GAAG,CAAC;IAUX,KAAK,EAAE,GAAG,CAAC;IASX,KAAK,EAAE,GAAG,CAAC;IASX,MAAM,EAAE,GAAG,CAAC;IAEd,OAAO,CACX,OAAO,CAAC,EAAE,iBAAiB,GAC1B,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAuBpC;AAED,eAAO,MAAM,0BAA0B,EAAE,SAAS,SAAS,EAE1D,CAAC"}
@@ -0,0 +1,90 @@
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ import { BaseNode, prop } from "@nodetool-ai/node-sdk";
8
+ import { DEVICE_VALUES, DTYPE_VALUES, asNumber, ensureArray, extractRepoId, getPipeline, tjsModelDefault, loadRawImage, normalizeOption } from "../transformers-base.js";
9
+ import { defaultRepoFor } from "../recommended-models.js";
10
+ const TJS_TYPE = "tjs.image_classification";
11
+ export class ImageClassificationNode extends BaseNode {
12
+ static nodeType = "transformers.ImageClassification";
13
+ static title = "Image Classification";
14
+ static description = "Classify an image using a Transformers.js image-classification pipeline.\n" +
15
+ "vision, classification, image, transformers, huggingface\n\n" +
16
+ "Use cases:\n" +
17
+ "- Tag photos with high-level categories\n" +
18
+ "- Filter content by class\n" +
19
+ "- Build moderation pipelines";
20
+ static metadataOutputTypes = {
21
+ label: "str",
22
+ score: "float",
23
+ results: "list"
24
+ };
25
+ async process(context) {
26
+ const rawImage = await loadRawImage(this.image, context);
27
+ const pipeline = (await getPipeline({
28
+ task: "image-classification",
29
+ model: extractRepoId(this.model) || undefined,
30
+ dtype: normalizeOption(this.dtype),
31
+ device: normalizeOption(this.device)
32
+ }));
33
+ const raw = await pipeline(rawImage, { top_k: asNumber(this.top_k, 5) });
34
+ const results = ensureArray(raw);
35
+ const top = results[0] ?? { label: "", score: 0 };
36
+ return {
37
+ label: top.label,
38
+ score: top.score,
39
+ results
40
+ };
41
+ }
42
+ }
43
+ __decorate([
44
+ prop({
45
+ type: "image",
46
+ default: { type: "image" },
47
+ title: "Image",
48
+ description: "Image to classify."
49
+ })
50
+ ], ImageClassificationNode.prototype, "image", void 0);
51
+ __decorate([
52
+ prop({
53
+ type: TJS_TYPE,
54
+ default: tjsModelDefault(TJS_TYPE, defaultRepoFor(TJS_TYPE)),
55
+ title: "Model",
56
+ description: "Transformers.js model (ONNX-compatible)."
57
+ })
58
+ ], ImageClassificationNode.prototype, "model", void 0);
59
+ __decorate([
60
+ prop({
61
+ type: "int",
62
+ default: 5,
63
+ title: "Top K",
64
+ description: "Number of top labels to return.",
65
+ min: 1,
66
+ max: 100
67
+ })
68
+ ], ImageClassificationNode.prototype, "top_k", void 0);
69
+ __decorate([
70
+ prop({
71
+ type: "enum",
72
+ default: "auto",
73
+ title: "Quantization",
74
+ description: "Model dtype / quantization level.",
75
+ values: DTYPE_VALUES
76
+ })
77
+ ], ImageClassificationNode.prototype, "dtype", void 0);
78
+ __decorate([
79
+ prop({
80
+ type: "enum",
81
+ default: "auto",
82
+ title: "Device",
83
+ description: "Inference device.",
84
+ values: DEVICE_VALUES
85
+ })
86
+ ], ImageClassificationNode.prototype, "device", void 0);
87
+ export const IMAGE_CLASSIFICATION_NODES = [
88
+ ImageClassificationNode
89
+ ];
90
+ //# sourceMappingURL=image-classification.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"image-classification.js","sourceRoot":"","sources":["../../src/nodes/image-classification.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,uBAAuB,CAAC;AAGvD,OAAO,EACL,aAAa,EACb,YAAY,EACZ,QAAQ,EAER,WAAW,EACX,aAAa,EACb,WAAW,EACX,eAAe,EACf,YAAY,EACZ,eAAe,EAChB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAE1D,MAAM,QAAQ,GAAG,0BAA0B,CAAC;AAI5C,MAAM,OAAO,uBAAwB,SAAQ,QAAQ;IACnD,MAAM,CAAU,QAAQ,GAAG,kCAAkC,CAAC;IAC9D,MAAM,CAAU,KAAK,GAAG,sBAAsB,CAAC;IAC/C,MAAM,CAAU,WAAW,GACzB,4EAA4E;QAC5E,8DAA8D;QAC9D,cAAc;QACd,2CAA2C;QAC3C,6BAA6B;QAC7B,8BAA8B,CAAC;IACjC,MAAM,CAAU,mBAAmB,GAAG;QACpC,KAAK,EAAE,KAAK;QACZ,KAAK,EAAE,OAAO;QACd,OAAO,EAAE,MAAM;KAChB,CAAC;IA8CF,KAAK,CAAC,OAAO,CACX,OAA2B;QAE3B,MAAM,QAAQ,GAAG,MAAM,YAAY,CAAC,IAAI,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;QAEzD,MAAM,QAAQ,GAAG,CAAC,MAAM,WAAW,CAAC;YAClC,IAAI,EAAE,sBAAsB;YAC5B,KAAK,EAAE,aAAa,CAAC,IAAI,CAAC,KAA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W,EAAE,mCAAmC;QAChD,MAAM,EAAE,YAAY;KACrB,CAAC;sDACiB;AASX;IAPP,IAAI,CAAC;QACJ,IAAI,EAAE,MAAM;QACZ,OAAO,EAAE,MAAM;QACf,KAAK,EAAE,QAAQ;QACf,WAAW,EAAE,mBAAmB;QAChC,MAAM,EAAE,aAAa;KACtB,CAAC;uDACkB;AA6BtB,MAAM,CAAC,MAAM,0BAA0B,GAAyB;IAC9D,uBAAuB;CACxB,CAAC"}
@@ -0,0 +1,19 @@
1
+ import { BaseNode } from "@nodetool-ai/node-sdk";
2
+ import type { NodeClass } from "@nodetool-ai/node-sdk";
3
+ import type { ProcessingContext } from "@nodetool-ai/runtime";
4
+ export declare class ImageToTextNode extends BaseNode {
5
+ static readonly nodeType = "transformers.ImageToText";
6
+ static readonly title = "Image to Text (Captioning)";
7
+ static readonly description: string;
8
+ static readonly metadataOutputTypes: {
9
+ text: string;
10
+ };
11
+ image: any;
12
+ model: any;
13
+ max_new_tokens: any;
14
+ dtype: any;
15
+ device: any;
16
+ process(context?: ProcessingContext): Promise<Record<string, unknown>>;
17
+ }
18
+ export declare const IMAGE_TO_TEXT_NODES: readonly NodeClass[];
19
+ //# sourceMappingURL=image-to-text.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"image-to-text.d.ts","sourceRoot":"","sources":["../../src/nodes/image-to-text.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAQ,MAAM,uBAAuB,CAAC;AACvD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAmB9D,qBAAa,eAAgB,SAAQ,QAAQ;IAC3C,MAAM,CAAC,QAAQ,CAAC,QAAQ,8BAA8B;IACtD,MAAM,CAAC,QAAQ,CAAC,KAAK,gCAAgC;IACrD,MAAM,CAAC,QAAQ,CAAC,WAAW,SAMuB;IAClD,MAAM,CAAC,QAAQ,CAAC,mBAAmB;;MAAmB;IAQ9C,KAAK,EAAE,GAAG,CAAC;IAQX,KAAK,EAAE,GAAG,CAAC;IAUX,cAAc,EAAE,GAAG,CAAC;IASpB,KAAK,EAAE,GAAG,CAAC;IASX,MAAM,EAAE,GAAG,CAAC;IAEd,OAAO,CACX,OAAO,CAAC,EAAE,iBAAiB,GAC1B,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAmBpC;AAED,eAAO,MAAM,mBAAmB,EAAE,SAAS,SAAS,EAAsB,CAAC"}
@@ -0,0 +1,81 @@
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ import { BaseNode, prop } from "@nodetool-ai/node-sdk";
8
+ import { DEVICE_VALUES, DTYPE_VALUES, asNumber, ensureArray, extractRepoId, getPipeline, tjsModelDefault, loadRawImage, normalizeOption } from "../transformers-base.js";
9
+ import { defaultRepoFor } from "../recommended-models.js";
10
+ const TJS_TYPE = "tjs.image_to_text";
11
+ export class ImageToTextNode extends BaseNode {
12
+ static nodeType = "transformers.ImageToText";
13
+ static title = "Image to Text (Captioning)";
14
+ static description = "Generate a textual description for an image using a Transformers.js image-to-text pipeline.\n" +
15
+ "vision, captioning, image-to-text, transformers, huggingface\n\n" +
16
+ "Use cases:\n" +
17
+ "- Auto-caption photos for accessibility\n" +
18
+ "- Index images by their content\n" +
19
+ "- Feed captions into downstream LLM workflows";
20
+ static metadataOutputTypes = { text: "str" };
21
+ async process(context) {
22
+ const rawImage = await loadRawImage(this.image, context);
23
+ const pipeline = (await getPipeline({
24
+ task: "image-to-text",
25
+ model: extractRepoId(this.model) || undefined,
26
+ dtype: normalizeOption(this.dtype),
27
+ device: normalizeOption(this.device)
28
+ }));
29
+ const raw = await pipeline(rawImage, {
30
+ max_new_tokens: asNumber(this.max_new_tokens, 50)
31
+ });
32
+ const first = ensureArray(raw)[0];
33
+ return { text: first?.generated_text ?? "" };
34
+ }
35
+ }
36
+ __decorate([
37
+ prop({
38
+ type: "image",
39
+ default: { type: "image" },
40
+ title: "Image",
41
+ description: "Image to caption."
42
+ })
43
+ ], ImageToTextNode.prototype, "image", void 0);
44
+ __decorate([
45
+ prop({
46
+ type: TJS_TYPE,
47
+ default: tjsModelDefault(TJS_TYPE, defaultRepoFor(TJS_TYPE)),
48
+ title: "Model",
49
+ description: "Transformers.js model (ONNX-compatible)."
50
+ })
51
+ ], ImageToTextNode.prototype, "model", void 0);
52
+ __decorate([
53
+ prop({
54
+ type: "int",
55
+ default: 50,
56
+ title: "Max New Tokens",
57
+ description: "Maximum number of tokens in the caption.",
58
+ min: 1,
59
+ max: 1024
60
+ })
61
+ ], ImageToTextNode.prototype, "max_new_tokens", void 0);
62
+ __decorate([
63
+ prop({
64
+ type: "enum",
65
+ default: "auto",
66
+ title: "Quantization",
67
+ description: "Model dtype / quantization level.",
68
+ values: DTYPE_VALUES
69
+ })
70
+ ], ImageToTextNode.prototype, "dtype", void 0);
71
+ __decorate([
72
+ prop({
73
+ type: "enum",
74
+ default: "auto",
75
+ title: "Device",
76
+ description: "Inference device.",
77
+ values: DEVICE_VALUES
78
+ })
79
+ ], ImageToTextNode.prototype, "device", void 0);
80
+ export const IMAGE_TO_TEXT_NODES = [ImageToTextNode];
81
+ //# sourceMappingURL=image-to-text.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"image-to-text.js","sourceRoot":"","sources":["../../src/nodes/image-to-text.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,uB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AAE,EAAE,CAAC;IAC/C,CAAC;;AA1DO;IANP,IAAI,CAAC;QACJ,IAAI,EAAE,OAAO;QACb,OAAO,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE;QAC1B,KAAK,EAAE,OAAO;QACd,WAAW,EAAE,mBAAmB;KACjC,CAAC;8CACiB;AAQX;IANP,IAAI,CAAC;QACJ,IAAI,EAAE,QAAQ;QACd,OAAO,EAAE,eAAe,CAAC,QAAQ,EAAE,cAAc,CAAC,QAAQ,CAAC,CAAC;QAC5D,KAAK,EAAE,OAAO;QACd,WAAW,EAAE,0CAA0C;KACxD,CAAC;8CACiB;AAUX;IARP,IAAI,CAAC;QACJ,IAAI,EAAE,KAAK;QACX,OAAO,EAAE,EAAE;QACX,KAAK,EAAE,gBAAgB;QACvB,WAAW,EAAE,0CAA0C;QACvD,GAAG,EAAE,CAAC;QACN,GAAG,EAAE,IAAI;KACV,CAAC;uDAC0B;AASpB;IAPP,IAAI,CAAC;QACJ,IAAI,EAAE,MAAM;QACZ,OAAO,EAAE,MAAM;QACf,KAAK,EAAE,cAAc;QACrB,WAAW,EAAE,mCAAmC;QAChD,MAAM,EAAE,YAAY;KACrB,CAAC;8CACiB;AASX;IAPP,IAAI,CAAC;QACJ,IAAI,EAAE,MAAM;QACZ,OAAO,EAAE,MAAM;QACf,KAAK,EAAE,QAAQ;QACf,WAAW,EAAE,mBAAmB;QAChC,MAAM,EAAE,aAAa;KACtB,CAAC;+CACkB;AAyBtB,MAAM,CAAC,MAAM,mBAAmB,GAAyB,CAAC,eAAe,CAAC,CAAC"}
@@ -0,0 +1,20 @@
1
+ import { BaseNode } from "@nodetool-ai/node-sdk";
2
+ import type { NodeClass } from "@nodetool-ai/node-sdk";
3
+ import type { ProcessingContext } from "@nodetool-ai/runtime";
4
+ export declare class ObjectDetectionNode extends BaseNode {
5
+ static readonly nodeType = "transformers.ObjectDetection";
6
+ static readonly title = "Object Detection";
7
+ static readonly description: string;
8
+ static readonly metadataOutputTypes: {
9
+ detections: string;
10
+ };
11
+ image: any;
12
+ model: any;
13
+ threshold: any;
14
+ percentage: any;
15
+ dtype: any;
16
+ device: any;
17
+ process(context?: ProcessingContext): Promise<Record<string, unknown>>;
18
+ }
19
+ export declare const OBJECT_DETECTION_NODES: readonly NodeClass[];
20
+ //# sourceMappingURL=object-detection.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"object-detection.d.ts","sourceRoot":"","sources":["../../src/nodes/object-detection.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAQ,MAAM,uBAAuB,CAAC;AACvD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AA4B9D,qBAAa,mBAAoB,SAAQ,QAAQ;IAC/C,MAAM,CAAC,QAAQ,CAAC,QAAQ,kCAAkC;IAC1D,MAAM,CAAC,QAAQ,CAAC,KAAK,sBAAsB;IAC3C,MAAM,CAAC,QAAQ,CAAC,WAAW,SAMkB;IAC7C,MAAM,CAAC,QAAQ,CAAC,mBAAmB;;MAEjC;IAQM,KAAK,EAAE,GAAG,CAAC;IAQX,KAAK,EAAE,GAAG,CAAC;IAUX,SAAS,EAAE,GAAG,CAAC;IAQf,UAAU,EAAE,GAAG,CAAC;IAShB,KAAK,EAAE,GAAG,CAAC;IASX,MAAM,EAAE,GAAG,CAAC;IAEd,OAAO,CACX,OAAO,CAAC,EAAE,iBAAiB,GAC1B,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAmBpC;AAED,eAAO,MAAM,sBAAsB,EAAE,SAAS,SAAS,EAEtD,CAAC"}
@@ -0,0 +1,93 @@
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ import { BaseNode, prop } from "@nodetool-ai/node-sdk";
8
+ import { DEVICE_VALUES, DTYPE_VALUES, asNumber, ensureArray, extractRepoId, getPipeline, tjsModelDefault, loadRawImage, normalizeOption } from "../transformers-base.js";
9
+ import { defaultRepoFor } from "../recommended-models.js";
10
+ const TJS_TYPE = "tjs.object_detection";
11
+ export class ObjectDetectionNode extends BaseNode {
12
+ static nodeType = "transformers.ObjectDetection";
13
+ static title = "Object Detection";
14
+ static description = "Detect objects and their bounding boxes in an image using a Transformers.js object-detection pipeline.\n" +
15
+ "vision, detection, bounding-box, transformers, huggingface\n\n" +
16
+ "Use cases:\n" +
17
+ "- Localize objects for cropping or tracking\n" +
18
+ "- Count items in retail photos\n" +
19
+ "- Pre-label data for downstream training";
20
+ static metadataOutputTypes = {
21
+ detections: "list"
22
+ };
23
+ async process(context) {
24
+ const rawImage = await loadRawImage(this.image, context);
25
+ const pipeline = (await getPipeline({
26
+ task: "object-detection",
27
+ model: extractRepoId(this.model) || undefined,
28
+ dtype: normalizeOption(this.dtype),
29
+ device: normalizeOption(this.device)
30
+ }));
31
+ const raw = await pipeline(rawImage, {
32
+ threshold: asNumber(this.threshold, 0.9),
33
+ percentage: Boolean(this.percentage)
34
+ });
35
+ return { detections: ensureArray(raw) };
36
+ }
37
+ }
38
+ __decorate([
39
+ prop({
40
+ type: "image",
41
+ default: { type: "image" },
42
+ title: "Image",
43
+ description: "Image to run detection on."
44
+ })
45
+ ], ObjectDetectionNode.prototype, "image", void 0);
46
+ __decorate([
47
+ prop({
48
+ type: TJS_TYPE,
49
+ default: tjsModelDefault(TJS_TYPE, defaultRepoFor(TJS_TYPE)),
50
+ title: "Model",
51
+ description: "Transformers.js model (ONNX-compatible)."
52
+ })
53
+ ], ObjectDetectionNode.prototype, "model", void 0);
54
+ __decorate([
55
+ prop({
56
+ type: "float",
57
+ default: 0.9,
58
+ title: "Score Threshold",
59
+ description: "Minimum confidence score required to keep a detection.",
60
+ min: 0.0,
61
+ max: 1.0
62
+ })
63
+ ], ObjectDetectionNode.prototype, "threshold", void 0);
64
+ __decorate([
65
+ prop({
66
+ type: "bool",
67
+ default: true,
68
+ title: "Percentage Coordinates",
69
+ description: "Return bounding boxes as fractions of image size."
70
+ })
71
+ ], ObjectDetectionNode.prototype, "percentage", void 0);
72
+ __decorate([
73
+ prop({
74
+ type: "enum",
75
+ default: "auto",
76
+ title: "Quantization",
77
+ description: "Model dtype / quantization level.",
78
+ values: DTYPE_VALUES
79
+ })
80
+ ], ObjectDetectionNode.prototype, "dtype", void 0);
81
+ __decorate([
82
+ prop({
83
+ type: "enum",
84
+ default: "auto",
85
+ title: "Device",
86
+ description: "Inference device.",
87
+ values: DEVICE_VALUES
88
+ })
89
+ ], ObjectDetectionNode.prototype, "device", void 0);
90
+ export const OBJECT_DETECTION_NODES = [
91
+ ObjectDetectionNode
92
+ ];
93
+ //# sourceMappingURL=object-detection.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"object-detection.js","sourceRoot":"","sources":["../../src/nodes/object-detection.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,uBAAuB,CAAC;AAGvD,OAAO,EACL,aAAa,EACb,YAAY,EACZ,QAAQ,EAER,WAAW,EACX,aAAa,EACb,WAAW,EACX,eAAe,EACf,YAAY,EACZ,eAAe,EAChB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAE1D,MAAM,QAAQ,GAAG,sBAAsB,CAAC;AAaxC,MAAM,OAAO,mBAAoB,SAAQ,QAAQ;IAC/C,MAAM,CAAU,QAAQ,GAAG,8BAA8B,CAAC;IAC1D,MAAM,CAAU,K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