@grafana/assistant 0.1.4 → 0.1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,174 @@
1
+ /**
2
+ * JSON object type - simple key-value structure
3
+ */
4
+ export interface JsonObject {
5
+ [key: string]: any;
6
+ }
7
+ /**
8
+ * Represents a datasource configuration
9
+ */
10
+ export interface ToolDatasourceInfo {
11
+ uid: string;
12
+ name: string;
13
+ type: string;
14
+ }
15
+ /**
16
+ * Function to determine if a tool should be registered based on available datasources
17
+ */
18
+ export type ShouldRegisterFunction = (datasources: ToolDatasourceInfo[]) => boolean;
19
+ /**
20
+ * Minimal options for a single request.
21
+ * Tools only need these basic options. This is a standalone type to avoid
22
+ * dependency on ConversationManager types from the main app.
23
+ */
24
+ export interface SingleRequestOptions {
25
+ weak?: boolean;
26
+ signal?: AbortSignal;
27
+ showThinking?: boolean;
28
+ reasoningLevel?: string;
29
+ }
30
+ /**
31
+ * Minimal tool use content structure.
32
+ * Represents the minimal interface needed by tools without depending on main app types.
33
+ * Matches the structure from the chat API schema (ToolUseContent).
34
+ */
35
+ export interface MinimalToolUseContent {
36
+ toolId: string;
37
+ toolName: string;
38
+ toolInput?: Record<string, unknown>;
39
+ type?: 'tool_use';
40
+ }
41
+ /**
42
+ * Minimal response from a single request.
43
+ * Tools primarily need the text and toolUse fields. The output field is available
44
+ * but typed as unknown to avoid dependency on ChatPromptOutput from the main app.
45
+ */
46
+ export interface SingleRequestResponse {
47
+ text: string;
48
+ toolUse: MinimalToolUseContent[];
49
+ output?: unknown;
50
+ }
51
+ /**
52
+ * Interface for a Conversation Manager that can execute tools.
53
+ * This represents the capability to make single requests to the LLM with tool execution support.
54
+ */
55
+ export interface ToolExecutingManager {
56
+ /**
57
+ * Make a single request to the model with centralized error handling
58
+ * @param systemPrompt System prompt message
59
+ * @param userMessage User message
60
+ * @param options Options for the single request (weak, signal, showThinking)
61
+ * @returns The model's response text
62
+ */
63
+ singleRequest(systemPrompt: string, userMessage: string, options?: SingleRequestOptions): Promise<SingleRequestResponse>;
64
+ }
65
+ /**
66
+ * Type for tool invocation options.
67
+ * The manager is typed as `ToolExecutingManager` to avoid dependency on ConversationManager from the main app.
68
+ * Consumers should cast it to the appropriate type when needed.
69
+ */
70
+ export type ToolInvokeOptions = {
71
+ manager: ToolExecutingManager;
72
+ signal?: AbortSignal;
73
+ timeout?: number;
74
+ };
75
+ /**
76
+ * Tool output can be:
77
+ * - A simple string
78
+ * - A tuple of [string, artifact] where artifact can be any type (string, boolean, number, object, array, etc.)
79
+ * Examples include PanelJSON, but the artifact can be any structured data type
80
+ */
81
+ export type ToolOutput = string | [string, any | null] | [string, any[]] | [string, Record<string, any>];
82
+ /**
83
+ * Minimal Tool interface - matches the structure needed without extending external Tool type
84
+ */
85
+ export interface Tool {
86
+ name: string;
87
+ description: string;
88
+ inputSchema: JSONSchema;
89
+ }
90
+ /**
91
+ * Basic tool interface for inline tools that don't need to support conditional registration
92
+ * with the "Assistant" (aka frontend agent or chat).
93
+ *
94
+ * These tools are typically used for simple, one-off tasks like generating content or executing commands.
95
+ */
96
+ export interface InlineToolRunnable extends Tool {
97
+ invoke: (input: JsonObject, options: ToolInvokeOptions) => Promise<ToolOutput>;
98
+ metadata?: JsonObject & {
99
+ explainer?: (input?: JsonObject) => string;
100
+ };
101
+ verboseParsingErrors?: boolean;
102
+ responseFormat?: 'content_and_artifact' | string;
103
+ }
104
+ /**
105
+ * JSON Schema type definition from @types/json-schema
106
+ * Using JSONSchema7 (Draft 7) which is compatible with zod's toJSONSchema output
107
+ * and other JSON Schema converters (yup, joi-to-json, etc.)
108
+ */
109
+ export type _JSONSchema = boolean | JSONSchema;
110
+ export type JSONSchema = {
111
+ [k: string]: unknown;
112
+ $schema?: 'https://json-schema.org/draft/2020-12/schema' | 'http://json-schema.org/draft-07/schema#' | 'http://json-schema.org/draft-04/schema#';
113
+ $id?: string;
114
+ $anchor?: string;
115
+ $ref?: string;
116
+ $dynamicRef?: string;
117
+ $dynamicAnchor?: string;
118
+ $vocabulary?: Record<string, boolean>;
119
+ $comment?: string;
120
+ $defs?: Record<string, JSONSchema>;
121
+ type?: 'object' | 'array' | 'string' | 'number' | 'boolean' | 'null' | 'integer';
122
+ additionalItems?: _JSONSchema;
123
+ unevaluatedItems?: _JSONSchema;
124
+ prefixItems?: _JSONSchema[];
125
+ items?: _JSONSchema | _JSONSchema[];
126
+ contains?: _JSONSchema;
127
+ additionalProperties?: _JSONSchema;
128
+ unevaluatedProperties?: _JSONSchema;
129
+ properties?: Record<string, _JSONSchema>;
130
+ patternProperties?: Record<string, _JSONSchema>;
131
+ dependentSchemas?: Record<string, _JSONSchema>;
132
+ propertyNames?: _JSONSchema;
133
+ if?: _JSONSchema;
134
+ then?: _JSONSchema;
135
+ else?: _JSONSchema;
136
+ allOf?: JSONSchema[];
137
+ anyOf?: JSONSchema[];
138
+ oneOf?: JSONSchema[];
139
+ not?: _JSONSchema;
140
+ multipleOf?: number;
141
+ maximum?: number;
142
+ exclusiveMaximum?: number | boolean;
143
+ minimum?: number;
144
+ exclusiveMinimum?: number | boolean;
145
+ maxLength?: number;
146
+ minLength?: number;
147
+ pattern?: string;
148
+ maxItems?: number;
149
+ minItems?: number;
150
+ uniqueItems?: boolean;
151
+ maxContains?: number;
152
+ minContains?: number;
153
+ maxProperties?: number;
154
+ minProperties?: number;
155
+ required?: string[];
156
+ dependentRequired?: Record<string, string[]>;
157
+ enum?: Array<string | number | boolean | null>;
158
+ const?: string | number | boolean | null;
159
+ id?: string;
160
+ title?: string;
161
+ description?: string;
162
+ default?: unknown;
163
+ deprecated?: boolean;
164
+ readOnly?: boolean;
165
+ writeOnly?: boolean;
166
+ nullable?: boolean;
167
+ examples?: unknown[];
168
+ format?: string;
169
+ contentMediaType?: string;
170
+ contentEncoding?: string;
171
+ contentSchema?: JSONSchema;
172
+ _prefault?: unknown;
173
+ };
174
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1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"@grafana/assistant",
3
- "version": "0.1.4",
3
+ "version": "0.1.5",
4
4
  "description": "Type definitions and helper functions for Grafana Assistant",
5
5
  "repository": {
6
6
  "type": "git",
@@ -41,7 +41,7 @@
41
41
  "jest-environment-jsdom": "^29.5.0",
42
42
  "react": "18.3.1",
43
43
  "rxjs": "7.8.2",
44
- "ts-loader": "^9.0.0",
44
+ "ts-loader": "^9.5.2",
45
45
  "typescript": "^5.0.0",
46
46
  "webpack": "^5.0.0",
47
47
  "webpack-cli": "^5.0.0"