@quilltap/plugin-types 1.17.3 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -0
- package/dist/{index-C2T_GwJc.d.mts → index-BXJLgAuZ.d.ts} +134 -57
- package/dist/{index-aiujxDsP.d.ts → index-DtW7izgw.d.mts} +134 -57
- package/dist/index.d.mts +102 -4
- package/dist/index.d.ts +102 -4
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +2 -2
- package/dist/index.mjs.map +1 -1
- package/dist/llm/index.d.mts +174 -151
- package/dist/llm/index.d.ts +174 -151
- package/dist/llm/index.js +1 -1
- package/dist/llm/index.js.map +1 -1
- package/dist/llm/index.mjs +1 -1
- package/dist/llm/index.mjs.map +1 -1
- package/dist/plugins/index.d.mts +2 -1
- package/dist/plugins/index.d.ts +2 -1
- package/dist/providers/index.d.mts +132 -0
- package/dist/providers/index.d.ts +132 -0
- package/dist/providers/index.js +10 -0
- package/dist/providers/index.js.map +1 -0
- package/dist/providers/index.mjs +8 -0
- package/dist/providers/index.mjs.map +1 -0
- package/package.json +6 -1
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
export { AttachmentResults, CacheUsage, EmbeddingOptions, EmbeddingProvider, EmbeddingResult, FileAttachment, GeneratedImage, ImageGenParams, ImageGenResponse, ImageGenProvider as ImageProvider, JSONSchemaDefinition, LLMMessage, LLMParams, LLMResponse, LocalEmbeddingProvider, LocalEmbeddingProviderState, ModelMetadata, ModelWarning, ModelWarningLevel, ResponseFormat, StreamChunk, LLMProvider as TextProvider, TokenUsage, isLocalEmbeddingProvider } from '../llm/index.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Scoring Provider — Shape 4: Text + Candidates -> Scores
|
|
5
|
+
*
|
|
6
|
+
* Send content (and optionally candidates or labels) to a scoring model,
|
|
7
|
+
* receive scored categories or ranked results. This generalizes content
|
|
8
|
+
* moderation, reranking, and classification into a single interface shape.
|
|
9
|
+
*
|
|
10
|
+
* ## Supported Tasks
|
|
11
|
+
*
|
|
12
|
+
* ### Moderation (implemented)
|
|
13
|
+
* Score content against safety categories. The provider returns per-category
|
|
14
|
+
* flagged/score pairs (e.g., "violence": 0.95, "hate": 0.02).
|
|
15
|
+
*
|
|
16
|
+
* ```typescript
|
|
17
|
+
* const result = await provider.score({
|
|
18
|
+
* content: 'some user message',
|
|
19
|
+
* task: 'moderation',
|
|
20
|
+
* }, apiKey);
|
|
21
|
+
* // result.flagged = true, result.categories = [{ category: 'violence', flagged: true, score: 0.95 }, ...]
|
|
22
|
+
* ```
|
|
23
|
+
*
|
|
24
|
+
* ### Reranking (future)
|
|
25
|
+
* Given a query and candidate passages, score each passage by relevance.
|
|
26
|
+
* Uses `candidates` field to pass the passages to rank.
|
|
27
|
+
*
|
|
28
|
+
* ```typescript
|
|
29
|
+
* const result = await provider.score({
|
|
30
|
+
* content: 'What is the capital of France?',
|
|
31
|
+
* task: 'reranking',
|
|
32
|
+
* candidates: ['Paris is the capital of France.', 'London is in England.', ...],
|
|
33
|
+
* }, apiKey);
|
|
34
|
+
* // result.categories = [{ category: '0', score: 0.98 }, { category: '1', score: 0.12 }, ...]
|
|
35
|
+
* ```
|
|
36
|
+
*
|
|
37
|
+
* ### Classification (future)
|
|
38
|
+
* Classify content into one or more predefined labels.
|
|
39
|
+
* Uses `labels` field to define the classification categories.
|
|
40
|
+
*
|
|
41
|
+
* ```typescript
|
|
42
|
+
* const result = await provider.score({
|
|
43
|
+
* content: 'I love this product!',
|
|
44
|
+
* task: 'classification',
|
|
45
|
+
* labels: ['positive', 'negative', 'neutral'],
|
|
46
|
+
* }, apiKey);
|
|
47
|
+
* // result.categories = [{ category: 'positive', flagged: true, score: 0.92 }, ...]
|
|
48
|
+
* ```
|
|
49
|
+
*
|
|
50
|
+
* @module @quilltap/plugin-types/providers/scoring
|
|
51
|
+
*/
|
|
52
|
+
/**
|
|
53
|
+
* The type of scoring task to perform
|
|
54
|
+
*/
|
|
55
|
+
type ScoringTask = 'moderation' | 'reranking' | 'classification';
|
|
56
|
+
/**
|
|
57
|
+
* Input for a scoring operation
|
|
58
|
+
*/
|
|
59
|
+
interface ScoringInput {
|
|
60
|
+
/** The primary text to score */
|
|
61
|
+
content: string;
|
|
62
|
+
/** The scoring task type */
|
|
63
|
+
task: ScoringTask;
|
|
64
|
+
/**
|
|
65
|
+
* Candidate passages for reranking.
|
|
66
|
+
* Each candidate is scored against the content (used as query).
|
|
67
|
+
*/
|
|
68
|
+
candidates?: string[];
|
|
69
|
+
/**
|
|
70
|
+
* Label set for classification.
|
|
71
|
+
* Content is classified into these categories.
|
|
72
|
+
*/
|
|
73
|
+
labels?: string[];
|
|
74
|
+
/** Task-specific options */
|
|
75
|
+
options?: Record<string, unknown>;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* A single category/label score
|
|
79
|
+
*/
|
|
80
|
+
interface CategoryScore {
|
|
81
|
+
/** Category or label name (e.g., 'violence', 'positive', or candidate index) */
|
|
82
|
+
category: string;
|
|
83
|
+
/** Whether this category was triggered/flagged */
|
|
84
|
+
flagged: boolean;
|
|
85
|
+
/** Confidence score (0-1) */
|
|
86
|
+
score: number;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Result from a scoring operation
|
|
90
|
+
*/
|
|
91
|
+
interface ScoringResult {
|
|
92
|
+
/** Overall flagged status (for moderation) or top match (for classification) */
|
|
93
|
+
flagged: boolean;
|
|
94
|
+
/** Per-category/label breakdown with scores */
|
|
95
|
+
categories: CategoryScore[];
|
|
96
|
+
/** Which task produced this result */
|
|
97
|
+
task: ScoringTask;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Scoring provider interface — Shape 4: Text + Candidates -> Scores
|
|
101
|
+
*
|
|
102
|
+
* Sends content to a scoring model and receives scored categories,
|
|
103
|
+
* ranked results, or classification labels. Generalizes moderation,
|
|
104
|
+
* reranking, and classification into a single provider shape.
|
|
105
|
+
*/
|
|
106
|
+
interface ScoringProvider {
|
|
107
|
+
/**
|
|
108
|
+
* Score content according to the specified task
|
|
109
|
+
*
|
|
110
|
+
* @param input The scoring input with content, task type, and optional candidates/labels
|
|
111
|
+
* @param apiKey The API key for authentication
|
|
112
|
+
* @param baseUrl Optional base URL for the scoring API
|
|
113
|
+
* @returns Scored results with per-category breakdown
|
|
114
|
+
*/
|
|
115
|
+
score(input: ScoringInput, apiKey: string, baseUrl?: string): Promise<ScoringResult>;
|
|
116
|
+
/**
|
|
117
|
+
* Get the scoring tasks this provider supports
|
|
118
|
+
*
|
|
119
|
+
* @returns Array of supported task types
|
|
120
|
+
*/
|
|
121
|
+
getSupportedTasks(): ScoringTask[];
|
|
122
|
+
/**
|
|
123
|
+
* Validate an API key for this provider (optional)
|
|
124
|
+
*
|
|
125
|
+
* @param apiKey The API key to validate
|
|
126
|
+
* @param baseUrl Optional base URL
|
|
127
|
+
* @returns True if valid
|
|
128
|
+
*/
|
|
129
|
+
validateApiKey?(apiKey: string, baseUrl?: string): Promise<boolean>;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
export type { CategoryScore, ScoringInput, ScoringProvider, ScoringResult, ScoringTask };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// src/providers/embedding.ts
|
|
4
|
+
function isLocalEmbeddingProvider(provider) {
|
|
5
|
+
return "fitCorpus" in provider && "loadState" in provider && "getState" in provider;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
exports.isLocalEmbeddingProvider = isLocalEmbeddingProvider;
|
|
9
|
+
//# sourceMappingURL=index.js.map
|
|
10
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/providers/embedding.ts"],"names":[],"mappings":";;;AAyLO,SAAS,yBACd,QAAA,EACoC;AACpC,EAAA,OAAO,WAAA,IAAe,QAAA,IAAY,WAAA,IAAe,QAAA,IAAY,UAAA,IAAc,QAAA;AAC7E","file":"index.js","sourcesContent":["/**\n * Embedding Provider — Shape 3: Text -> Vector\n *\n * Send text to an embedding model, receive a numeric vector representation.\n * Used for semantic search, RAG, and similarity matching.\n *\n * @module @quilltap/plugin-types/providers/embedding\n */\n\n/**\n * Result of an embedding operation\n */\nexport interface EmbeddingResult {\n /** The embedding vector (array of floating point numbers) */\n embedding: number[];\n /** The model used to generate the embedding */\n model: string;\n /** Number of dimensions in the embedding vector */\n dimensions: number;\n /** Token usage information (if available) */\n usage?: {\n promptTokens: number;\n totalTokens: number;\n cost?: number;\n };\n}\n\n/**\n * Options for embedding generation\n */\nexport interface EmbeddingOptions {\n /** Desired dimensions for the embedding (if model supports variable dimensions) */\n dimensions?: number;\n}\n\n/**\n * Embedding provider interface — Shape 3: Text -> Vector\n *\n * Sends text to an embedding model and receives a numeric vector\n * representation for use in semantic search, RAG, and similarity matching.\n */\nexport interface EmbeddingProvider {\n /**\n * Generate an embedding for a single text\n *\n * @param text The text to embed\n * @param model The model to use\n * @param apiKey The API key for authentication\n * @param options Optional configuration\n * @returns The embedding result\n */\n generateEmbedding(\n text: string,\n model: string,\n apiKey: string,\n options?: EmbeddingOptions\n ): Promise<EmbeddingResult>;\n\n /**\n * Generate embeddings for multiple texts in a batch\n *\n * @param texts Array of texts to embed\n * @param model The model to use\n * @param apiKey The API key for authentication\n * @param options Optional configuration\n * @returns Array of embedding results\n */\n generateBatchEmbeddings?(\n texts: string[],\n model: string,\n apiKey: string,\n options?: EmbeddingOptions\n ): Promise<EmbeddingResult[]>;\n\n /**\n * Get available embedding models\n *\n * @param apiKey The API key for authentication\n * @returns Array of model IDs\n */\n getAvailableModels?(apiKey: string): Promise<string[]>;\n\n /**\n * Check if the provider is available and properly configured\n *\n * @param apiKey Optional API key to validate\n * @returns True if the provider is ready to use\n */\n isAvailable?(apiKey?: string): Promise<boolean>;\n}\n\n/**\n * Serializable state for local embedding providers\n *\n * Used by providers like TF-IDF that maintain vocabulary state\n */\nexport interface LocalEmbeddingProviderState {\n /** The vocabulary as an array of [term, index] pairs */\n vocabulary: [string, number][];\n /** The IDF (Inverse Document Frequency) weights */\n idf: number[];\n /** Average document length across the corpus */\n avgDocLength: number;\n /** Size of the vocabulary */\n vocabularySize: number;\n /** Whether bigrams are included in the vocabulary */\n includeBigrams: boolean;\n /** Timestamp when the vocabulary was fitted */\n fittedAt: string;\n}\n\n/**\n * Local embedding provider interface\n *\n * Extended interface for local/offline embedding providers that\n * maintain vocabulary state (like TF-IDF). These providers don't\n * require API keys and can work entirely offline.\n */\nexport interface LocalEmbeddingProvider extends Omit<EmbeddingProvider, 'generateEmbedding' | 'generateBatchEmbeddings'> {\n /**\n * Generate an embedding for a single text\n * Local providers don't need apiKey parameter\n *\n * @param text The text to embed\n * @returns The embedding result\n */\n generateEmbedding(text: string): EmbeddingResult;\n\n /**\n * Generate embeddings for multiple texts in a batch\n *\n * @param texts Array of texts to embed\n * @returns Array of embedding results\n */\n generateBatchEmbeddings(texts: string[]): EmbeddingResult[];\n\n /**\n * Fit the vocabulary on a corpus of documents\n *\n * This method analyzes the corpus to build vocabulary, calculate IDF weights,\n * and other statistics needed for embedding generation.\n *\n * @param documents Array of text documents to analyze\n */\n fitCorpus(documents: string[]): void;\n\n /**\n * Check if the vocabulary has been fitted\n *\n * @returns True if fitCorpus has been called with documents\n */\n isFitted(): boolean;\n\n /**\n * Load state from a serialized representation\n *\n * @param state The serialized provider state\n */\n loadState(state: LocalEmbeddingProviderState): void;\n\n /**\n * Get the current state for serialization\n *\n * @returns The provider state, or null if not fitted\n */\n getState(): LocalEmbeddingProviderState | null;\n\n /**\n * Get the vocabulary size\n *\n * @returns Number of terms in the vocabulary\n */\n getVocabularySize(): number;\n\n /**\n * Get the embedding dimensions\n *\n * @returns Number of dimensions in generated embeddings\n */\n getDimensions(): number;\n}\n\n/**\n * Type guard to check if a provider is a local embedding provider\n */\nexport function isLocalEmbeddingProvider(\n provider: EmbeddingProvider | LocalEmbeddingProvider\n): provider is LocalEmbeddingProvider {\n return 'fitCorpus' in provider && 'loadState' in provider && 'getState' in provider;\n}\n"]}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
// src/providers/embedding.ts
|
|
2
|
+
function isLocalEmbeddingProvider(provider) {
|
|
3
|
+
return "fitCorpus" in provider && "loadState" in provider && "getState" in provider;
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
export { isLocalEmbeddingProvider };
|
|
7
|
+
//# sourceMappingURL=index.mjs.map
|
|
8
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/providers/embedding.ts"],"names":[],"mappings":";AAyLO,SAAS,yBACd,QAAA,EACoC;AACpC,EAAA,OAAO,WAAA,IAAe,QAAA,IAAY,WAAA,IAAe,QAAA,IAAY,UAAA,IAAc,QAAA;AAC7E","file":"index.mjs","sourcesContent":["/**\n * Embedding Provider — Shape 3: Text -> Vector\n *\n * Send text to an embedding model, receive a numeric vector representation.\n * Used for semantic search, RAG, and similarity matching.\n *\n * @module @quilltap/plugin-types/providers/embedding\n */\n\n/**\n * Result of an embedding operation\n */\nexport interface EmbeddingResult {\n /** The embedding vector (array of floating point numbers) */\n embedding: number[];\n /** The model used to generate the embedding */\n model: string;\n /** Number of dimensions in the embedding vector */\n dimensions: number;\n /** Token usage information (if available) */\n usage?: {\n promptTokens: number;\n totalTokens: number;\n cost?: number;\n };\n}\n\n/**\n * Options for embedding generation\n */\nexport interface EmbeddingOptions {\n /** Desired dimensions for the embedding (if model supports variable dimensions) */\n dimensions?: number;\n}\n\n/**\n * Embedding provider interface — Shape 3: Text -> Vector\n *\n * Sends text to an embedding model and receives a numeric vector\n * representation for use in semantic search, RAG, and similarity matching.\n */\nexport interface EmbeddingProvider {\n /**\n * Generate an embedding for a single text\n *\n * @param text The text to embed\n * @param model The model to use\n * @param apiKey The API key for authentication\n * @param options Optional configuration\n * @returns The embedding result\n */\n generateEmbedding(\n text: string,\n model: string,\n apiKey: string,\n options?: EmbeddingOptions\n ): Promise<EmbeddingResult>;\n\n /**\n * Generate embeddings for multiple texts in a batch\n *\n * @param texts Array of texts to embed\n * @param model The model to use\n * @param apiKey The API key for authentication\n * @param options Optional configuration\n * @returns Array of embedding results\n */\n generateBatchEmbeddings?(\n texts: string[],\n model: string,\n apiKey: string,\n options?: EmbeddingOptions\n ): Promise<EmbeddingResult[]>;\n\n /**\n * Get available embedding models\n *\n * @param apiKey The API key for authentication\n * @returns Array of model IDs\n */\n getAvailableModels?(apiKey: string): Promise<string[]>;\n\n /**\n * Check if the provider is available and properly configured\n *\n * @param apiKey Optional API key to validate\n * @returns True if the provider is ready to use\n */\n isAvailable?(apiKey?: string): Promise<boolean>;\n}\n\n/**\n * Serializable state for local embedding providers\n *\n * Used by providers like TF-IDF that maintain vocabulary state\n */\nexport interface LocalEmbeddingProviderState {\n /** The vocabulary as an array of [term, index] pairs */\n vocabulary: [string, number][];\n /** The IDF (Inverse Document Frequency) weights */\n idf: number[];\n /** Average document length across the corpus */\n avgDocLength: number;\n /** Size of the vocabulary */\n vocabularySize: number;\n /** Whether bigrams are included in the vocabulary */\n includeBigrams: boolean;\n /** Timestamp when the vocabulary was fitted */\n fittedAt: string;\n}\n\n/**\n * Local embedding provider interface\n *\n * Extended interface for local/offline embedding providers that\n * maintain vocabulary state (like TF-IDF). These providers don't\n * require API keys and can work entirely offline.\n */\nexport interface LocalEmbeddingProvider extends Omit<EmbeddingProvider, 'generateEmbedding' | 'generateBatchEmbeddings'> {\n /**\n * Generate an embedding for a single text\n * Local providers don't need apiKey parameter\n *\n * @param text The text to embed\n * @returns The embedding result\n */\n generateEmbedding(text: string): EmbeddingResult;\n\n /**\n * Generate embeddings for multiple texts in a batch\n *\n * @param texts Array of texts to embed\n * @returns Array of embedding results\n */\n generateBatchEmbeddings(texts: string[]): EmbeddingResult[];\n\n /**\n * Fit the vocabulary on a corpus of documents\n *\n * This method analyzes the corpus to build vocabulary, calculate IDF weights,\n * and other statistics needed for embedding generation.\n *\n * @param documents Array of text documents to analyze\n */\n fitCorpus(documents: string[]): void;\n\n /**\n * Check if the vocabulary has been fitted\n *\n * @returns True if fitCorpus has been called with documents\n */\n isFitted(): boolean;\n\n /**\n * Load state from a serialized representation\n *\n * @param state The serialized provider state\n */\n loadState(state: LocalEmbeddingProviderState): void;\n\n /**\n * Get the current state for serialization\n *\n * @returns The provider state, or null if not fitted\n */\n getState(): LocalEmbeddingProviderState | null;\n\n /**\n * Get the vocabulary size\n *\n * @returns Number of terms in the vocabulary\n */\n getVocabularySize(): number;\n\n /**\n * Get the embedding dimensions\n *\n * @returns Number of dimensions in generated embeddings\n */\n getDimensions(): number;\n}\n\n/**\n * Type guard to check if a provider is a local embedding provider\n */\nexport function isLocalEmbeddingProvider(\n provider: EmbeddingProvider | LocalEmbeddingProvider\n): provider is LocalEmbeddingProvider {\n return 'fitCorpus' in provider && 'loadState' in provider && 'getState' in provider;\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@quilltap/plugin-types",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"description": "Type definitions for Quilltap plugin development",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -25,6 +25,11 @@
|
|
|
25
25
|
"types": "./dist/common/index.d.ts",
|
|
26
26
|
"import": "./dist/common/index.mjs",
|
|
27
27
|
"require": "./dist/common/index.js"
|
|
28
|
+
},
|
|
29
|
+
"./providers": {
|
|
30
|
+
"types": "./dist/providers/index.d.ts",
|
|
31
|
+
"import": "./dist/providers/index.mjs",
|
|
32
|
+
"require": "./dist/providers/index.js"
|
|
28
33
|
}
|
|
29
34
|
},
|
|
30
35
|
"files": [
|