@grafana/assistant 0.1.35 → 0.1.36
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 +110 -0
- package/dist/analyticsEvents.d.ts +33 -0
- package/dist/analyticsEvents.d.ts.map +1 -0
- package/dist/components/button/OpenAssistantButton.d.ts +6 -1
- package/dist/components/button/OpenAssistantButton.d.ts.map +1 -1
- package/dist/components/grots/GrotAvatar.d.ts +31 -0
- package/dist/components/grots/GrotAvatar.d.ts.map +1 -0
- package/dist/components/grots/GrotTopicView.d.ts +19 -0
- package/dist/components/grots/GrotTopicView.d.ts.map +1 -0
- package/dist/components/grots/OpenGrotButton.d.ts +23 -0
- package/dist/components/grots/OpenGrotButton.d.ts.map +1 -0
- package/dist/components/index.d.ts +3 -0
- package/dist/components/index.d.ts.map +1 -1
- package/dist/esm/analyticsEvents.js +31 -0
- package/dist/esm/analyticsEvents.js.map +1 -0
- package/dist/esm/components/button/OpenAssistantButton.js +11 -10
- package/dist/esm/components/button/OpenAssistantButton.js.map +1 -1
- package/dist/esm/components/button/OpenAssistantSplitButton.js +2 -2
- package/dist/esm/components/button/OpenAssistantSplitButton.js.map +1 -1
- package/dist/esm/components/grots/GrotAvatar.js +37 -0
- package/dist/esm/components/grots/GrotAvatar.js.map +1 -0
- package/dist/esm/components/grots/GrotTopicView.js +25 -0
- package/dist/esm/components/grots/GrotTopicView.js.map +1 -0
- package/dist/esm/components/grots/OpenGrotButton.js +36 -0
- package/dist/esm/components/grots/OpenGrotButton.js.map +1 -0
- package/dist/esm/components/index.js +3 -0
- package/dist/esm/components/index.js.map +1 -1
- package/dist/esm/components/prompt-card/AssistantPromptCard.js +2 -2
- package/dist/esm/components/prompt-card/AssistantPromptCard.js.map +1 -1
- package/dist/esm/grots/avatar/appearance.js +303 -0
- package/dist/esm/grots/avatar/appearance.js.map +1 -0
- package/dist/esm/grots/avatar/sprite.js +481 -0
- package/dist/esm/grots/avatar/sprite.js.map +1 -0
- package/dist/esm/grots/client.js +377 -0
- package/dist/esm/grots/client.js.map +1 -0
- package/dist/esm/grots/index.js +2 -0
- package/dist/esm/grots/index.js.map +1 -0
- package/dist/esm/grots/retry.js +67 -0
- package/dist/esm/grots/retry.js.map +1 -0
- package/dist/esm/grots/types.js +2 -0
- package/dist/esm/grots/types.js.map +1 -0
- package/dist/esm/index.js +1 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/sidebar.js +4 -3
- package/dist/esm/sidebar.js.map +1 -1
- package/dist/grots/avatar/appearance.d.ts +82 -0
- package/dist/grots/avatar/appearance.d.ts.map +1 -0
- package/dist/grots/avatar/sprite.d.ts +84 -0
- package/dist/grots/avatar/sprite.d.ts.map +1 -0
- package/dist/grots/client.d.ts +130 -0
- package/dist/grots/client.d.ts.map +1 -0
- package/dist/grots/index.d.ts +3 -0
- package/dist/grots/index.d.ts.map +1 -0
- package/dist/grots/retry.d.ts +7 -0
- package/dist/grots/retry.d.ts.map +1 -0
- package/dist/grots/types.d.ts +331 -0
- package/dist/grots/types.d.ts.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/investigations/api.gen.d.ts +3 -3
- package/dist/sidebar.d.ts.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,377 @@
|
|
|
1
|
+
import { getBackendSrv } from '@grafana/runtime';
|
|
2
|
+
import { firstValueFrom, fromEvent, merge, mergeMap, throwError } from 'rxjs';
|
|
3
|
+
import { z } from 'zod';
|
|
4
|
+
import { ASSISTANT_PLUGIN_ID } from '../plugin';
|
|
5
|
+
import { withRetry } from './retry';
|
|
6
|
+
const baseUrl = `api/plugins/${ASSISTANT_PLUGIN_ID}/resources/api/v1/durable-agents`;
|
|
7
|
+
const grotSchema = z.object({
|
|
8
|
+
id: z.string().min(1),
|
|
9
|
+
name: z.string(),
|
|
10
|
+
purpose: z.string().optional(),
|
|
11
|
+
role: z.string().optional(),
|
|
12
|
+
scope: z.string().optional(),
|
|
13
|
+
teamId: z.string().optional(),
|
|
14
|
+
status: z.string().optional(),
|
|
15
|
+
avatar: z.string().optional(),
|
|
16
|
+
revision: z.number(),
|
|
17
|
+
labels: z.record(z.string(), z.string()).optional(),
|
|
18
|
+
});
|
|
19
|
+
const grotListSchema = z.object({ agents: z.array(grotSchema) });
|
|
20
|
+
const workSchema = z.object({ id: z.string().min(1), state: z.string() });
|
|
21
|
+
const laneClosedSchema = z.object({
|
|
22
|
+
laneKey: z.string(),
|
|
23
|
+
closed: z.boolean(),
|
|
24
|
+
cancelledFollowUps: z.number(),
|
|
25
|
+
});
|
|
26
|
+
const messagesFields = {
|
|
27
|
+
messages: z.array(z.record(z.string(), z.unknown())),
|
|
28
|
+
total: z.number().optional(),
|
|
29
|
+
from: z.number().optional(),
|
|
30
|
+
reset: z.boolean().optional(),
|
|
31
|
+
};
|
|
32
|
+
const messagesPageSchema = z.object(messagesFields);
|
|
33
|
+
const laneSchema = z.object({
|
|
34
|
+
...messagesFields,
|
|
35
|
+
laneKey: z.string(),
|
|
36
|
+
topicId: z.string(),
|
|
37
|
+
chatId: z.string(),
|
|
38
|
+
title: z.string(),
|
|
39
|
+
settled: z.boolean(),
|
|
40
|
+
runningWorkId: z.string().optional(),
|
|
41
|
+
pendingWork: z.number(),
|
|
42
|
+
busy: z.boolean(),
|
|
43
|
+
});
|
|
44
|
+
const topicSchema = z.object({
|
|
45
|
+
id: z.string().min(1),
|
|
46
|
+
agentId: z.string(),
|
|
47
|
+
threadId: z.string(),
|
|
48
|
+
number: z.number(),
|
|
49
|
+
title: z.string(),
|
|
50
|
+
chatId: z.string(),
|
|
51
|
+
revision: z.number(),
|
|
52
|
+
createdBy: z.string(),
|
|
53
|
+
archivedAt: z.string().optional(),
|
|
54
|
+
pinnedAt: z.string().optional(),
|
|
55
|
+
});
|
|
56
|
+
const topicAcceptedSchema = z.object({
|
|
57
|
+
topic: topicSchema,
|
|
58
|
+
work: workSchema,
|
|
59
|
+
});
|
|
60
|
+
const directTopicSchema = topicSchema.extend({
|
|
61
|
+
runningWorkId: z.string().optional(),
|
|
62
|
+
helpersWorking: z.boolean().optional(),
|
|
63
|
+
});
|
|
64
|
+
const topicListSchema = z.object({
|
|
65
|
+
thread: z.object({ id: z.string(), agentId: z.string(), title: z.string() }).optional(),
|
|
66
|
+
topics: z.array(directTopicSchema),
|
|
67
|
+
settledCount: z.number().optional(),
|
|
68
|
+
});
|
|
69
|
+
async function request(method, path, schema, options, data, query, retryable = false) {
|
|
70
|
+
return withRetry(() => requestOnce(method, path, schema, options, data, query), retryable ? options.retry : undefined, options.signal);
|
|
71
|
+
}
|
|
72
|
+
async function requestOnce(method, path, schema, options, data, query) {
|
|
73
|
+
const signal = options.signal;
|
|
74
|
+
signal === null || signal === void 0 ? void 0 : signal.throwIfAborted();
|
|
75
|
+
const search = query && Object.keys(query).length > 0 ? `?${new URLSearchParams(query).toString()}` : '';
|
|
76
|
+
const response$ = getBackendSrv().fetch({
|
|
77
|
+
url: `${baseUrl}${path}${search}`,
|
|
78
|
+
method,
|
|
79
|
+
data,
|
|
80
|
+
abortSignal: signal,
|
|
81
|
+
retry: 0,
|
|
82
|
+
showErrorAlert: false,
|
|
83
|
+
showSuccessAlert: false,
|
|
84
|
+
});
|
|
85
|
+
// Unsubscribe on cancellation even on Grafana versions that ignore abortSignal.
|
|
86
|
+
const response = await firstValueFrom(signal
|
|
87
|
+
? merge(response$, fromEvent(signal, 'abort').pipe(mergeMap(() => throwError(() => signal.reason))))
|
|
88
|
+
: response$);
|
|
89
|
+
return z.object({ data: schema }).parse(response.data).data;
|
|
90
|
+
}
|
|
91
|
+
/** Copy the named fields that are set, so extra properties a caller passes never reach the backend. */
|
|
92
|
+
function pick(source, keys) {
|
|
93
|
+
const out = {};
|
|
94
|
+
for (const key of keys) {
|
|
95
|
+
if (source[key] !== undefined) {
|
|
96
|
+
out[key] = source[key];
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
return out;
|
|
100
|
+
}
|
|
101
|
+
function requireValue(value, name) {
|
|
102
|
+
if (value.trim() === '') {
|
|
103
|
+
throw new Error(`${name} is required.`);
|
|
104
|
+
}
|
|
105
|
+
return encodeURIComponent(value);
|
|
106
|
+
}
|
|
107
|
+
function grotPath(grotId, suffix = '') {
|
|
108
|
+
return `/${requireValue(grotId, 'A Grot ID')}${suffix}`;
|
|
109
|
+
}
|
|
110
|
+
function requireMessage(input) {
|
|
111
|
+
if (input.content.trim() === '') {
|
|
112
|
+
throw new Error('content must contain non-whitespace text.');
|
|
113
|
+
}
|
|
114
|
+
if (input.dedupeKey === '') {
|
|
115
|
+
throw new Error('dedupeKey is required.');
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* List the Grots the signed-in user may use (newest 100, newest first).
|
|
120
|
+
* Needs `durable-agents.<scope>:read` for each scope listed.
|
|
121
|
+
* @experimental This API is under active development and may change in future releases.
|
|
122
|
+
*/
|
|
123
|
+
export async function listGrots(options = {}) {
|
|
124
|
+
const query = options.labelSelector ? { labelSelector: options.labelSelector } : undefined;
|
|
125
|
+
const list = await request('GET', '', grotListSchema, options, undefined, query, true);
|
|
126
|
+
return list.agents;
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Read one Grot. Another user's private Grot returns 404.
|
|
130
|
+
*
|
|
131
|
+
* @experimental This API is under active development and may change in future releases.
|
|
132
|
+
*/
|
|
133
|
+
export async function getGrot(grotId, options = {}) {
|
|
134
|
+
return request('GET', grotPath(grotId), grotSchema, options, undefined, undefined, true);
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Create a Grot. Needs `durable-agents.<scope>:create` for the new Grot's scope. Never retried, even with
|
|
138
|
+
* `retry` set: retrying creation can create duplicates.
|
|
139
|
+
*
|
|
140
|
+
* The call sends exactly the fields of {@link CreateGrotInput} and nothing else. A private Grot (the default scope)
|
|
141
|
+
* needs `ownerDelegation: true`, the creator's explicit consent for background work with their own Grafana
|
|
142
|
+
* permissions. On a `team` Grot the backend refuses it, so it is dropped from the request.
|
|
143
|
+
*
|
|
144
|
+
* Without `executionBinding` and `grant` the Grot is created as a `draft` and cannot run: a run, such as
|
|
145
|
+
* `createGrotTopic`, fails with 400 until you call {@link bindGrot}. Pass both to create a Grot that can run at
|
|
146
|
+
* once. That turns on its background work and gives it tool access, so it also needs `durable-agents:configure`
|
|
147
|
+
* and `durable-agents.<scope>:execute`. `grant: { allowAllTools: true }` lets the Grot call every tool. Set these
|
|
148
|
+
* only when the person using your code has explicitly agreed; they are never defaulted.
|
|
149
|
+
* @experimental This API is under active development and may change in future releases.
|
|
150
|
+
*/
|
|
151
|
+
export async function createGrot(input, options = {}) {
|
|
152
|
+
if (input.name.trim() === '') {
|
|
153
|
+
throw new Error('A Grot name is required.');
|
|
154
|
+
}
|
|
155
|
+
const body = pick(input, [
|
|
156
|
+
'name',
|
|
157
|
+
'purpose',
|
|
158
|
+
'role',
|
|
159
|
+
'scope',
|
|
160
|
+
'teamId',
|
|
161
|
+
'ownerDelegation',
|
|
162
|
+
'executionBinding',
|
|
163
|
+
'grant',
|
|
164
|
+
'labels',
|
|
165
|
+
]);
|
|
166
|
+
if (body.scope === 'team') {
|
|
167
|
+
// The backend refuses ownerDelegation on a team Grot with a 400, so never send it.
|
|
168
|
+
delete body.ownerDelegation;
|
|
169
|
+
}
|
|
170
|
+
return request('POST', '', grotSchema, options, body);
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* Give an existing Grot access so it can run (`PUT /durable-agents/{id}/binding`; the Go SDK has no such call). On
|
|
174
|
+
* a `draft` Grot this also activates it and turns on its background work; on an active one it replaces the tool
|
|
175
|
+
* grant. Needs `durable-agents:configure` and `durable-agents.<scope>:write`, plus `:execute` for a draft. A stale
|
|
176
|
+
* `expectedRevision` returns 409, as does a Grot with a run in progress; wait for it to finish, re-read the Grot
|
|
177
|
+
* and call again. Never retried, even with `retry` set. Returns the updated Grot.
|
|
178
|
+
*
|
|
179
|
+
* `grant: { allowAllTools: true }` lets the Grot call every tool. Only call this when the person using your code
|
|
180
|
+
* has explicitly agreed to give the Grot that access.
|
|
181
|
+
* @experimental This API is under active development and may change in future releases.
|
|
182
|
+
*/
|
|
183
|
+
export async function bindGrot(grotId, input, options = {}) {
|
|
184
|
+
const path = grotPath(grotId, '/binding');
|
|
185
|
+
requireRevision(input.expectedRevision);
|
|
186
|
+
return request('PUT', path, grotSchema, options, pick(input, ['expectedRevision', 'executionBinding', 'grant']));
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* Wake a Grot with a workflow event in its own conversation. Needs `durable-agents.<scope>:execute`.
|
|
190
|
+
* Retry only with the same workflow, laneKey, dedupeKey and body. The API limits `workflow` to 253 characters,
|
|
191
|
+
* `title`, `dedupeKey`, `runId` and `stepId` to 256, and `content` to 16000. Unlike direct-topic keys, a workflow
|
|
192
|
+
* `dedupeKey` may contain ":".
|
|
193
|
+
* @experimental This API is under active development and may change in future releases.
|
|
194
|
+
*/
|
|
195
|
+
export async function wakeGrot(grotId, event, options = {}) {
|
|
196
|
+
if (event.workflow.trim() === '' || event.content.trim() === '') {
|
|
197
|
+
throw new Error('workflow and content must contain non-whitespace text.');
|
|
198
|
+
}
|
|
199
|
+
if (event.dedupeKey === '') {
|
|
200
|
+
throw new Error('dedupeKey is required.');
|
|
201
|
+
}
|
|
202
|
+
return request('POST', grotPath(grotId, '/workflow-events'), workSchema, options, pick(event, ['workflow', 'title', 'dedupeKey', 'content', 'runId', 'stepId', 'laneKey']), undefined, true);
|
|
203
|
+
}
|
|
204
|
+
/** Close a lane to free one of the Grot's 50 open lanes. An unknown lane returns `closed: false`. Never retried, even
|
|
205
|
+
* with `retry`: a repeat after a lost response would report `closed: false` for a lane the first call closed.
|
|
206
|
+
*
|
|
207
|
+
* @experimental This API is under active development and may change in future releases.
|
|
208
|
+
*/
|
|
209
|
+
export async function closeGrotLane(grotId, laneKey, options = {}) {
|
|
210
|
+
requireValue(laneKey, 'laneKey'); // Validation only: the key goes in the JSON body as is.
|
|
211
|
+
return request('POST', grotPath(grotId, '/workflow-events/lanes/close'), laneClosedSchema, options, { laneKey });
|
|
212
|
+
}
|
|
213
|
+
/**
|
|
214
|
+
* Read a lane you opened with `wakeGrot`. Needs `durable-agents.<scope>:execute` and `:read`, plus
|
|
215
|
+
* `conversations.tenant:read`. A key you never sent returns 404.
|
|
216
|
+
* @experimental This API is under active development and may change in future releases.
|
|
217
|
+
*/
|
|
218
|
+
export async function readGrotLane(grotId, laneKey, options = {}) {
|
|
219
|
+
requireValue(laneKey, 'laneKey'); // Validation only: the key goes in the query string, percent-encoded.
|
|
220
|
+
const query = { laneKey };
|
|
221
|
+
if (options.after) {
|
|
222
|
+
query.after = options.after;
|
|
223
|
+
}
|
|
224
|
+
return request('GET', grotPath(grotId, '/workflow-events/lanes'), laneSchema, options, undefined, query, true);
|
|
225
|
+
}
|
|
226
|
+
/**
|
|
227
|
+
* Open a topic in the signed-in user's direct conversation with a Grot and send its first message.
|
|
228
|
+
* Needs `durable-agents.<scope>:execute`, plus `conversations.user:create` for the first topic and
|
|
229
|
+
* `conversations.user:write` for later topics and for retries. Retries only with `retry`
|
|
230
|
+
* (the `dedupeKey` makes that safe); otherwise retry by hand with the same `dedupeKey`.
|
|
231
|
+
* @experimental This API is under active development and may change in future releases.
|
|
232
|
+
*/
|
|
233
|
+
export async function createGrotTopic(grotId, input, options = {}) {
|
|
234
|
+
requireMessage(input);
|
|
235
|
+
return request('POST', grotPath(grotId, '/direct/topics'), topicAcceptedSchema, options, pick(input, ['title', 'content', 'dedupeKey']), undefined, true);
|
|
236
|
+
}
|
|
237
|
+
/**
|
|
238
|
+
* Send a follow-up message in an existing topic. Posting to an archived topic restores it.
|
|
239
|
+
* Needs `durable-agents.<scope>:execute` and `conversations.user:write`.
|
|
240
|
+
* @experimental This API is under active development and may change in future releases.
|
|
241
|
+
*/
|
|
242
|
+
export async function postGrotTopicMessage(grotId, topicId, message, options = {}) {
|
|
243
|
+
const topic = requireValue(topicId, 'A topic ID');
|
|
244
|
+
requireMessage(message);
|
|
245
|
+
return request('POST', grotPath(grotId, `/direct/topics/${topic}/messages`), topicAcceptedSchema, options, pick(message, ['content', 'dedupeKey']), undefined, true);
|
|
246
|
+
}
|
|
247
|
+
/**
|
|
248
|
+
* List the topics in the signed-in user's direct conversation with a Grot. 404 before the first topic.
|
|
249
|
+
* Needs `durable-agents.<scope>:read` and `conversations.user:read`.
|
|
250
|
+
* @experimental This API is under active development and may change in future releases.
|
|
251
|
+
*/
|
|
252
|
+
export async function listGrotTopics(grotId, options = {}) {
|
|
253
|
+
const query = options.excludeSettled ? { settled: 'false' } : undefined;
|
|
254
|
+
return request('GET', grotPath(grotId, '/direct'), topicListSchema, options, undefined, query, true);
|
|
255
|
+
}
|
|
256
|
+
/**
|
|
257
|
+
* Read a topic's messages, oldest first. Pass the topic's `chatId`, not its `id`.
|
|
258
|
+
* Needs `durable-agents.<scope>:read` and read access on that chat (`conversations.user:read` for your direct
|
|
259
|
+
* topics).
|
|
260
|
+
* @experimental This API is under active development and may change in future releases.
|
|
261
|
+
*/
|
|
262
|
+
export async function listGrotTopicMessages(grotId, chatId, options = {}) {
|
|
263
|
+
const chat = requireValue(chatId, 'A chat ID');
|
|
264
|
+
const query = options.after ? { after: options.after } : undefined;
|
|
265
|
+
return request('GET', grotPath(grotId, `/conversations/${chat}/messages`), messagesPageSchema, options, undefined, query, true);
|
|
266
|
+
}
|
|
267
|
+
/**
|
|
268
|
+
* Thrown by `updateGrot` when you sent `labels` and the response has no `labels` key: a backend that predates
|
|
269
|
+
* labels (grafana-assistant-app #17893) applied the other fields and ignored the labels, so even `{}` did not clear
|
|
270
|
+
* them. Mirrors the Go SDK's `ErrLabelsNotSupported`. `grot` is the updated Grot.
|
|
271
|
+
* @experimental This API is under active development and may change in future releases.
|
|
272
|
+
*/
|
|
273
|
+
export class GrotLabelsNotSupportedError extends Error {
|
|
274
|
+
constructor(grot) {
|
|
275
|
+
super(`Grot ${grot.id}: labels were not updated because the backend does not support labels.`);
|
|
276
|
+
this.grot = grot;
|
|
277
|
+
this.name = 'GrotLabelsNotSupportedError';
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
/**
|
|
281
|
+
* Change a Grot's name, purpose, role or labels (Go: `UpdateGrot`, `PUT /durable-agents/{id}`). A stale
|
|
282
|
+
* `expectedRevision` returns 409. Needs `durable-agents.<scope>:write`. Never retried. Throws {@link GrotLabelsNotSupportedError} (carrying the updated Grot)
|
|
283
|
+
* when `labels` was sent and the backend did not return labels.
|
|
284
|
+
*
|
|
285
|
+
* The body is built from `expectedRevision`, `name`, `purpose`, `role` and `labels` only. The backend's update body
|
|
286
|
+
* also accepts avatar, budget, parallel runs and memory mode, which the Go SDK leaves out and so does this client;
|
|
287
|
+
* the tool grant and execution binding have their own route, {@link bindGrot}, and cannot be sent from here.
|
|
288
|
+
* @experimental This API is under active development and may change in future releases.
|
|
289
|
+
*/
|
|
290
|
+
export async function updateGrot(grotId, input, options = {}) {
|
|
291
|
+
const id = grotPath(grotId);
|
|
292
|
+
requireRevision(input.expectedRevision);
|
|
293
|
+
const updated = await request('PUT', id, grotSchema, options, pick(input, ['expectedRevision', 'name', 'purpose', 'role', 'labels']));
|
|
294
|
+
if (input.labels !== undefined && updated.labels === undefined) {
|
|
295
|
+
throw new GrotLabelsNotSupportedError(updated);
|
|
296
|
+
}
|
|
297
|
+
return updated;
|
|
298
|
+
}
|
|
299
|
+
/**
|
|
300
|
+
* Rename, archive, restore, pin or unpin a topic (Go: `UpdateTopic`,
|
|
301
|
+
* `PUT /durable-agents/{id}/direct/topics/{topicId}`). A stale `expectedRevision` returns 409. Needs
|
|
302
|
+
* `durable-agents.<scope>:execute` and `conversations.user:write`. Never retried.
|
|
303
|
+
* @experimental This API is under active development and may change in future releases.
|
|
304
|
+
*/
|
|
305
|
+
export async function updateGrotTopic(grotId, topicId, input, options = {}) {
|
|
306
|
+
const path = grotPath(grotId, `/direct/topics/${requireValue(topicId, 'A topic ID')}`);
|
|
307
|
+
requireRevision(input.expectedRevision);
|
|
308
|
+
return request('PUT', path, topicSchema, options, pick(input, ['expectedRevision', 'title', 'archived', 'pinned']));
|
|
309
|
+
}
|
|
310
|
+
/**
|
|
311
|
+
* Archive a topic (Go: `ArchiveTopic`). Same route and RBAC as {@link updateGrotTopic}; post a message to restore it.
|
|
312
|
+
*
|
|
313
|
+
* @experimental This API is under active development and may change in future releases.
|
|
314
|
+
*/
|
|
315
|
+
export async function archiveGrotTopic(grotId, topicId, expectedRevision, options = {}) {
|
|
316
|
+
return updateGrotTopic(grotId, topicId, { expectedRevision, archived: true }, options);
|
|
317
|
+
}
|
|
318
|
+
function requireRevision(revision) {
|
|
319
|
+
if (!Number.isInteger(revision) || revision < 1) {
|
|
320
|
+
throw new Error('expectedRevision must be a whole number of at least 1.');
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
function asRecord(value) {
|
|
324
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value)
|
|
325
|
+
? value
|
|
326
|
+
: undefined;
|
|
327
|
+
}
|
|
328
|
+
function parsePart(value) {
|
|
329
|
+
const part = asRecord(value);
|
|
330
|
+
const type = typeof (part === null || part === void 0 ? void 0 : part.type) === 'string' ? part.type : '';
|
|
331
|
+
const text = typeof (part === null || part === void 0 ? void 0 : part.text) === 'string' ? part.text : '';
|
|
332
|
+
if (!part) {
|
|
333
|
+
return { kind: 'unknown', type, raw: {} };
|
|
334
|
+
}
|
|
335
|
+
if (type === 'text' || type === 'reasoning') {
|
|
336
|
+
return { kind: type, text };
|
|
337
|
+
}
|
|
338
|
+
if (type.startsWith('tool-') || type === 'dynamic-tool') {
|
|
339
|
+
return {
|
|
340
|
+
kind: 'tool',
|
|
341
|
+
type,
|
|
342
|
+
...(typeof part.toolName === 'string' ? { toolName: part.toolName } : {}),
|
|
343
|
+
...(typeof part.state === 'string' ? { state: part.state } : {}),
|
|
344
|
+
};
|
|
345
|
+
}
|
|
346
|
+
return { kind: 'unknown', type, raw: part };
|
|
347
|
+
}
|
|
348
|
+
/**
|
|
349
|
+
* Decode a raw message from `listGrotTopicMessages` or `readGrotLane` (Go: `ParseTopicMessage`). Like Go it throws
|
|
350
|
+
* when the value is not an object or `id` / `role` is not a string. Unlike Go it keeps unknown roles and part types
|
|
351
|
+
* readable (`kind: 'unknown'`) instead of failing. `GrotMessage` itself is unchanged.
|
|
352
|
+
* @experimental This API is under active development and may change in future releases.
|
|
353
|
+
*/
|
|
354
|
+
export function parseGrotTopicMessage(raw) {
|
|
355
|
+
const msg = asRecord(raw);
|
|
356
|
+
if (!msg) {
|
|
357
|
+
throw new Error('A topic message must be an object.');
|
|
358
|
+
}
|
|
359
|
+
const { id, role, created, parts, metadata } = msg;
|
|
360
|
+
if (typeof id !== 'string' || (role !== undefined && typeof role !== 'string')) {
|
|
361
|
+
throw new Error('A topic message needs a string id and role.');
|
|
362
|
+
}
|
|
363
|
+
const parsed = Array.isArray(parts) ? parts.map(parsePart) : [];
|
|
364
|
+
const base = {
|
|
365
|
+
id,
|
|
366
|
+
parts: parsed,
|
|
367
|
+
raw: msg,
|
|
368
|
+
text: parsed.flatMap((p) => (p.kind === 'text' && p.text !== '' ? [p.text] : [])).join('\n'),
|
|
369
|
+
...(typeof created === 'string' ? { created } : {}),
|
|
370
|
+
...(metadata !== undefined ? { metadata } : {}),
|
|
371
|
+
};
|
|
372
|
+
if (role === 'user' || role === 'assistant' || role === 'system') {
|
|
373
|
+
return { ...base, kind: role };
|
|
374
|
+
}
|
|
375
|
+
return { ...base, kind: 'unknown', role: role !== null && role !== void 0 ? role : '' };
|
|
376
|
+
}
|
|
377
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../../../src/grots/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACjD,OAAO,EAAE,cAAc,E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O,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,IAAI,KAAK,MAAM,IAAI,CAAC,CAAC,IAAI,KAAK,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC;QAC5F,GAAG,CAAC,OAAO,OAAO,KAAK,QAAQ,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QACnD,GAAG,CAAC,QAAQ,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;KAChD,CAAC;IACF,IAAI,IAAI,KAAK,MAAM,IAAI,IAAI,KAAK,WAAW,IAAI,IAAI,KAAK,QAAQ,EAAE,CAAC;QACjE,OAAO,EAAE,GAAG,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC;IACjC,CAAC;IACD,OAAO,EAAE,GAAG,IAAI,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,IAAI,aAAJ,IAAI,cAAJ,IAAI,GAAI,EAAE,EAAE,CAAC;AACxD,CAAC"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
export { archiveGrotTopic, bindGrot, closeGrotLane, createGrot, createGrotTopic, getGrot, GrotLabelsNotSupportedError, listGrotTopicMessages, listGrotTopics, listGrots, parseGrotTopicMessage, postGrotTopicMessage, readGrotLane, updateGrot, updateGrotTopic, wakeGrot, } from './client';
|
|
2
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/grots/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,gBAAgB,EAChB,QAAQ,EACR,aAAa,EACb,UAAU,EACV,eAAe,EACf,OAAO,EACP,2BAA2B,EAC3B,qBAAqB,EACrB,cAAc,EACd,SAAS,EACT,qBAAqB,EACrB,oBAAoB,EACpB,YAAY,EACZ,UAAU,EACV,eAAe,EACf,QAAQ,GACT,MAAM,UAAU,CAAC"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Retry policy copied from the Go SDK's `defaultRetryPolicy` (packages/assistant-go/retry.go): 3 attempts,
|
|
3
|
+
* 500 ms initial backoff, factor 2, 10 s cap, 10% jitter. The statuses are those of `IsRetryable` (errors.go):
|
|
4
|
+
* 429, 502, 503 and 504. Go also retries timeouts; a browser fetch error has no stable timeout marker, so those
|
|
5
|
+
* are not retried here.
|
|
6
|
+
*/
|
|
7
|
+
const defaults = { maxAttempts: 3, initialBackoffMs: 500, maxBackoffMs: 10000, factor: 2, jitter: 0.1 };
|
|
8
|
+
const maxTimeoutMs = 2147483647;
|
|
9
|
+
const retryableStatuses = new Set([429, 502, 503, 504]);
|
|
10
|
+
/** `value` when it is a whole number of at least 1, else `fallback`. Guards NaN, Infinity and fractions. */
|
|
11
|
+
function positiveInteger(value, fallback) {
|
|
12
|
+
return typeof value === 'number' && Number.isSafeInteger(value) && value >= 1 ? value : fallback;
|
|
13
|
+
}
|
|
14
|
+
/** `value` when it is a finite number of at least 0, else `fallback`. Guards NaN and Infinity. */
|
|
15
|
+
function finiteNonNegative(value, fallback) {
|
|
16
|
+
return typeof value === 'number' && Number.isFinite(value) && value >= 0 ? value : fallback;
|
|
17
|
+
}
|
|
18
|
+
export function isRetryableStatus(error) {
|
|
19
|
+
const status = typeof error === 'object' && error !== null ? error.status : undefined;
|
|
20
|
+
return typeof status === 'number' && retryableStatuses.has(status);
|
|
21
|
+
}
|
|
22
|
+
/** Wait before retry number `attempt` (1 is the wait after the first failure). `random` is injectable for tests. */
|
|
23
|
+
export function backoffMs(attempt, options = {}, random = Math.random) {
|
|
24
|
+
const initial = finiteNonNegative(options.initialBackoffMs, defaults.initialBackoffMs);
|
|
25
|
+
const max = finiteNonNegative(options.maxBackoffMs, defaults.maxBackoffMs);
|
|
26
|
+
// 0 * 2 ** 1024 is NaN, and setTimeout fires at once past 2^31 - 1 ms, so clamp both (after jitter too).
|
|
27
|
+
const grown = initial * defaults.factor ** (attempt - 1);
|
|
28
|
+
const base = Math.min(Number.isNaN(grown) ? 0 : grown, max, maxTimeoutMs);
|
|
29
|
+
return Math.min(base * (1 + (random() * 2 - 1) * defaults.jitter), maxTimeoutMs);
|
|
30
|
+
}
|
|
31
|
+
function sleep(ms, signal) {
|
|
32
|
+
return new Promise((resolve, reject) => {
|
|
33
|
+
if (signal === null || signal === void 0 ? void 0 : signal.aborted) {
|
|
34
|
+
reject(signal.reason);
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
const onAbort = () => {
|
|
38
|
+
clearTimeout(timer);
|
|
39
|
+
reject(signal === null || signal === void 0 ? void 0 : signal.reason);
|
|
40
|
+
};
|
|
41
|
+
const timer = setTimeout(() => {
|
|
42
|
+
signal === null || signal === void 0 ? void 0 : signal.removeEventListener('abort', onAbort);
|
|
43
|
+
resolve();
|
|
44
|
+
}, ms);
|
|
45
|
+
signal === null || signal === void 0 ? void 0 : signal.addEventListener('abort', onAbort, { once: true });
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
/** Run `attempt`, repeating it on a retryable status when `retry` is enabled. Aborting stops the wait. */
|
|
49
|
+
export async function withRetry(attempt, retry, signal) {
|
|
50
|
+
if (!retry) {
|
|
51
|
+
return attempt();
|
|
52
|
+
}
|
|
53
|
+
const options = retry === true ? {} : retry;
|
|
54
|
+
const maxAttempts = positiveInteger(options.maxAttempts, defaults.maxAttempts);
|
|
55
|
+
for (let n = 1;; n++) {
|
|
56
|
+
try {
|
|
57
|
+
return await attempt();
|
|
58
|
+
}
|
|
59
|
+
catch (error) {
|
|
60
|
+
if (n >= maxAttempts || (signal === null || signal === void 0 ? void 0 : signal.aborted) || !isRetryableStatus(error)) {
|
|
61
|
+
throw error;
|
|
62
|
+
}
|
|
63
|
+
await sleep(backoffMs(n, options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}
|
package/dist/esm/index.js
CHANGED
package/dist/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,0BAA0B,EAC1B,kBAAkB,EAElB,gBAAgB,EAEhB,iBAAiB,EACjB,iBAAiB,EACjB,kBAAkB,EAClB,cAAc,EACd,cAAc,EAEd,iBAAiB,EACjB,kBAAkB,EAClB,aAAa,EACb,kBAAkB,EAElB,kBAAkB,EAClB,qBAAqB,EAErB,cAAc,EACd,gBAAgB,EAChB,mBAAmB,EACnB,YAAY;AAGZ,sBAAsB;AACtB,iBAAiB,EACjB,iBAAiB,GAGlB,MAAM,iBAAiB,CAAC;AACzB,cAAc,aAAa,CAAC;AAC5B,cAAc,QAAQ,CAAC;AACvB,cAAc,UAAU,CAAC;AACzB,cAAc,WAAW,CAAC;AAC1B,cAAc,cAAc,CAAC;AAC7B,cAAc,UAAU,CAAC;AACzB,cAAc,QAAQ,CAAC;AACvB,cAAc,kBAAkB,CAAC;AACjC,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC;AACxB,cAAc,UAAU,CAAC;AACzB,cAAc,MAAM,CAAC;AACrB,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,0BAA0B,EAC1B,kBAAkB,EAElB,gBAAgB,EAEhB,iBAAiB,EACjB,iBAAiB,EACjB,kBAAkB,EAClB,cAAc,EACd,cAAc,EAEd,iBAAiB,EACjB,kBAAkB,EAClB,aAAa,EACb,kBAAkB,EAElB,kBAAkB,EAClB,qBAAqB,EAErB,cAAc,EACd,gBAAgB,EAChB,mBAAmB,EACnB,YAAY;AAGZ,sBAAsB;AACtB,iBAAiB,EACjB,iBAAiB,GAGlB,MAAM,iBAAiB,CAAC;AACzB,cAAc,aAAa,CAAC;AAC5B,cAAc,QAAQ,CAAC;AACvB,cAAc,UAAU,CAAC;AACzB,cAAc,WAAW,CAAC;AAC1B,cAAc,cAAc,CAAC;AAC7B,cAAc,UAAU,CAAC;AACzB,cAAc,QAAQ,CAAC;AACvB,cAAc,kBAAkB,CAAC;AACjC,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC;AACxB,cAAc,UAAU,CAAC;AACzB,cAAc,MAAM,CAAC;AACrB,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC"}
|
package/dist/esm/sidebar.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { BusEventBase, BusEventWithPayload } from '@grafana/data';
|
|
2
|
-
import { getAppEvents
|
|
2
|
+
import { getAppEvents } from '@grafana/runtime';
|
|
3
|
+
import { trackSidebarOpened, trackSidebarToggled } from './analyticsEvents';
|
|
3
4
|
import { ASSISTANT_PLUGIN_ID, ASSISTANT_PLUGIN_TITLE } from './plugin';
|
|
4
5
|
class OpenExtensionSidebarEvent extends BusEventWithPayload {
|
|
5
6
|
}
|
|
@@ -79,7 +80,7 @@ function toSidebarProps(props) {
|
|
|
79
80
|
* @param props.agentSkillInvocationName - One Agent Skill to attach to the new conversation, by the token a user types after `/`. Naming one never auto-sends, and pins Assistant mode when no mode and no chatId are given. Attaches nothing with `chatId`, which still does not send.
|
|
80
81
|
*/
|
|
81
82
|
export function openAssistant(props) {
|
|
82
|
-
|
|
83
|
+
trackSidebarOpened({
|
|
83
84
|
from: props.origin,
|
|
84
85
|
});
|
|
85
86
|
openExtensionSidebar(ASSISTANT_PLUGIN_ID, ASSISTANT_PLUGIN_TITLE, toSidebarProps(props));
|
|
@@ -92,7 +93,7 @@ export function closeAssistant() {
|
|
|
92
93
|
}
|
|
93
94
|
export function toggleAssistant(props) {
|
|
94
95
|
var _a;
|
|
95
|
-
|
|
96
|
+
trackSidebarToggled({
|
|
96
97
|
from: props.origin,
|
|
97
98
|
prompt: (_a = props.prompt) !== null && _a !== void 0 ? _a : '',
|
|
98
99
|
});
|
package/dist/esm/sidebar.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sidebar.js","sourceRoot":"","sources":["../../src/sidebar.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC;AAClE,OAAO,EAAE,YAAY,EAAE,
|
|
1
|
+
{"version":3,"file":"sidebar.js","sourceRoot":"","sources":["../../src/sidebar.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC;AAClE,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAChD,OAAO,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AAE5E,OAAO,EAAE,mBAAmB,EAAE,sBAAsB,EAAE,MAAM,UAAU,CAAC;AAQvE,MAAM,yBAA0B,SAAQ,mBAAgD;CAEvF;AADQ,8BAAI,GAAG,wBAAwB,CAAC;AAGzC,MAAM,0BAA2B,SAAQ,YAAY;CAEpD;AADQ,+BAAI,GAAG,yBAAyB,CAAC;AAG1C,MAAM,2BAA4B,SAAQ,mBAAgD;CAEzF;AADQ,gCAAI,GAAG,0BAA0B,CAAC;AAG3C,SAAS,oBAAoB,CAAC,QAAgB,EAAE,cAAsB,EAAE,KAA+B;IACrG,MAAM,KAAK,GAAG,IAAI,yBAAyB,CAAC;QAC1C,QAAQ;QACR,cAAc;QACd,KAAK;KACN,CAAC,CAAC;IACH,YAAY,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;AAChC,CAAC;AAED,SAAS,qBAAqB;IAC5B,MAAM,KAAK,GAAG,IAAI,0BAA0B,EAAE,CAAC;IAC/C,YAAY,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;AAChC,CAAC;AAED,SAAS,sBAAsB,CAAC,QAAgB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;AAED;;GAEG;AACH,MAAM,UAAU,cAAc;IAC5B,qBAAqB,EAAE,CAAC;AAC1B,CAAC;AAED,MAAM,UAAU,eAAe,CAAC,KAAyB;;IACvD,mBAAmB,CAAC;QAClB,IAAI,EAAE,KAAK,CAAC,MAAM;QAClB,MAAM,QAAE,KAAK,CAAC,MAAM,mCAAI,EAAE;KAC3B,CAAC,CAAC;IAEH,sBAAsB,CAAC,mBAAmB,EAAE,sBAAsB,EAAE,cAAc,CAAC,KAAK,CAAC,CAAC,CAAC;AAC7F,CAAC"}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/** Local-day drink gestures; independent of the saved appearance. */
|
|
2
|
+
export type GrotDaypart = 'morning' | 'evening';
|
|
3
|
+
/**
|
|
4
|
+
* The parts a Grot's pixel sprite is put together from, with their options in
|
|
5
|
+
* the order its look editor shows them. Each part's first option is the
|
|
6
|
+
* classic Grot.
|
|
7
|
+
*/
|
|
8
|
+
declare const options: {
|
|
9
|
+
readonly palette: readonly ['classic', 'mint', 'berry', 'glacier', 'night', 'moss', 'handheld', 'sunset', 'cotton', 'grape', 'ember', 'slate'];
|
|
10
|
+
readonly crest: readonly ['spikes', 'fin', 'mohawk', 'antenna', 'flame', 'sprout', 'horns', 'bald'];
|
|
11
|
+
readonly visor: readonly ['band', 'goggles', 'slim', 'shades'];
|
|
12
|
+
readonly screen: readonly ['bars', 'dots', 'tall', 'big', 'love', 'plus', 'dizzy', 'wink'];
|
|
13
|
+
readonly mouth: readonly ['smile', 'grin', 'flat', 'fang', 'stache', 'wavy'];
|
|
14
|
+
readonly hat: readonly ['nohat', 'beanie', 'cap', 'crown', 'party', 'headset', 'wizard', 'cowboy', 'chef', 'viking', 'tophat', 'halo', 'flower', 'copter', 'hardhat'];
|
|
15
|
+
readonly held: readonly ['empty', 'coffee', 'wrench', 'magnifier', 'chart', 'duck', 'pager', 'laptop', 'balloon', 'pizza', 'flag', 'donut', 'clip', 'bell', 'shield', 'bug', 'key'];
|
|
16
|
+
readonly tail: readonly ['curl', 'spike', 'bolt', 'heart', 'fluff', 'notail'];
|
|
17
|
+
};
|
|
18
|
+
export type GrotPart = keyof typeof options;
|
|
19
|
+
export type Appearance = {
|
|
20
|
+
[P in GrotPart]: (typeof options)[P][number];
|
|
21
|
+
};
|
|
22
|
+
export type GrotOption = Appearance[GrotPart];
|
|
23
|
+
/** Typed per part, so a part's options are its own option type. */
|
|
24
|
+
export declare const grotOptions: {
|
|
25
|
+
[P in GrotPart]: readonly Appearance[P][];
|
|
26
|
+
};
|
|
27
|
+
export declare const partLabels: {
|
|
28
|
+
palette: string;
|
|
29
|
+
crest: string;
|
|
30
|
+
visor: string;
|
|
31
|
+
screen: string;
|
|
32
|
+
mouth: string;
|
|
33
|
+
hat: string;
|
|
34
|
+
held: string;
|
|
35
|
+
tail: string;
|
|
36
|
+
};
|
|
37
|
+
/** The parts in editor order, which is also the order an avatar string stores them in. */
|
|
38
|
+
export declare const partOrder: GrotPart[];
|
|
39
|
+
export type GrotPalette = Appearance['palette'];
|
|
40
|
+
/**
|
|
41
|
+
* Grot's own illustration palettes. These are mascot colours, not UI colours:
|
|
42
|
+
* they stay the same in light and dark themes, like the mascot artwork does.
|
|
43
|
+
* `accent` is the UI token that stands in for the Grot on its surfaces.
|
|
44
|
+
*/
|
|
45
|
+
export declare const grotPalette: Record<GrotPalette, {
|
|
46
|
+
outline: string;
|
|
47
|
+
body: string;
|
|
48
|
+
light: string;
|
|
49
|
+
shade: string;
|
|
50
|
+
crest: string;
|
|
51
|
+
crestShade: string;
|
|
52
|
+
visor: string;
|
|
53
|
+
visorLight: string;
|
|
54
|
+
screen: string;
|
|
55
|
+
glyph: string;
|
|
56
|
+
accent: string;
|
|
57
|
+
}>;
|
|
58
|
+
/** The classic Grot: every part's first option. */
|
|
59
|
+
export declare const classicLook: Appearance;
|
|
60
|
+
/** Options that were removed, by part: the id a saved look may still name, and the option that replaces it. */
|
|
61
|
+
export declare const renamedOptions: {
|
|
62
|
+
[P in GrotPart]?: Record<string, Appearance[P]>;
|
|
63
|
+
};
|
|
64
|
+
type Renamed = {
|
|
65
|
+
[Q in GrotPart]?: Record<string, Appearance[Q]>;
|
|
66
|
+
};
|
|
67
|
+
/**
|
|
68
|
+
* The stored look, part by part. A part it does not name, such as one added
|
|
69
|
+
* since it was saved, gets a stable option derived from the id. A removed option
|
|
70
|
+
* maps to its replacement in renamedOptions first.
|
|
71
|
+
*/
|
|
72
|
+
export declare function appearanceWith(agent: {
|
|
73
|
+
id: string;
|
|
74
|
+
avatar?: string;
|
|
75
|
+
}, renamed: Renamed): Appearance;
|
|
76
|
+
/** The stored look of an agent. Takes one argument, so it is safe to pass to `.map`. */
|
|
77
|
+
export declare const appearanceOf: (agent: {
|
|
78
|
+
id: string;
|
|
79
|
+
avatar?: string;
|
|
80
|
+
}) => Appearance;
|
|
81
|
+
export {};
|
|
82
|
+
//# sourceMappingURL=appearance.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"appearance.d.ts","sourceRoot":"","sources":["../../../src/grots/avatar/appearance.ts"],"names":[],"mappings":"AACA,qEAAqE;AACrE,MAAM,MAAM,WAAW,GAAG,SAAS,GAAG,SAAS,CAAC;AAEhD;;;;GAIG;AACH,QAAA,MAAM,OAAO;aACX,OAAO,YACL,SAAS,EACT,MAAM,EACN,OAAO,EACP,SAAS,EACT,OAAO,EACP,MAAM,EACN,UAAU,EACV,QAAQ,EACR,QAAQ,EACR,OAAO,EACP,OAAO,EACP,OAAO;aAET,KAAK,YAAG,QAAQ,EAAE,KAAK,EAAE,QAAQ,EAAE,SAAS,EAAE,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM;aAChF,KAAK,YAAG,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ;aAC3C,MAAM,YAAG,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM;aACvE,KAAK,YAAG,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