@dolfinhos/studio 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,301 @@
1
+ import * as react from 'react';
2
+ import { ReactNode } from 'react';
3
+
4
+ type Mode = 'auto' | 'ask' | 'deny';
5
+ type Kind = 'read' | 'create' | 'update' | 'delete' | 'action' | 'send';
6
+ type Risk = 'low' | 'medium' | 'high';
7
+ interface Actor {
8
+ type: 'user' | 'service';
9
+ id: string;
10
+ name?: string;
11
+ roles?: string[];
12
+ }
13
+ interface Rule {
14
+ id?: string;
15
+ description?: string;
16
+ match?: {
17
+ capability?: string | string[];
18
+ kind?: Kind | Kind[];
19
+ risk?: Risk | Risk[];
20
+ tag?: string | string[];
21
+ entity?: string | string[];
22
+ channel?: string | string[];
23
+ actorType?: 'user' | 'service';
24
+ role?: string | string[];
25
+ };
26
+ mode: Mode;
27
+ reason?: string;
28
+ }
29
+ interface Automation {
30
+ id: string;
31
+ event: string;
32
+ instruction: string;
33
+ enabled?: boolean;
34
+ description?: string;
35
+ }
36
+ interface Settings {
37
+ rules: Rule[];
38
+ instructions?: string;
39
+ automations?: Automation[];
40
+ budget?: {
41
+ monthly: number;
42
+ };
43
+ updatedAt?: string;
44
+ updatedBy?: string;
45
+ }
46
+ interface Capability {
47
+ name: string;
48
+ title?: string;
49
+ description: string;
50
+ kind: Kind;
51
+ risk: Risk;
52
+ tags: string[];
53
+ entity?: string;
54
+ }
55
+ interface EventInfo {
56
+ name: string;
57
+ description: string;
58
+ }
59
+ interface PendingApproval {
60
+ executionId: string;
61
+ toolName: string;
62
+ title?: string;
63
+ summary?: string;
64
+ description?: string;
65
+ args: unknown;
66
+ }
67
+ interface ApprovalItem {
68
+ sessionId: string;
69
+ pod: string;
70
+ actor: Actor | null;
71
+ channel: string | null;
72
+ meta: Record<string, unknown> | null;
73
+ pendingApproval: PendingApproval;
74
+ updatedAt: string;
75
+ }
76
+ interface AuditRecord {
77
+ id: string;
78
+ at: string;
79
+ actor: Actor | null;
80
+ channel: string | null;
81
+ sessionId: string;
82
+ capability: string;
83
+ kind: Kind;
84
+ risk: Risk;
85
+ input: unknown;
86
+ decision: 'auto' | 'approved' | 'rejected' | 'denied' | 'failed';
87
+ rule?: string;
88
+ status: 'success' | 'error' | 'rejected' | 'denied';
89
+ error?: string;
90
+ decidedBy?: Actor;
91
+ }
92
+ interface UsageTotals {
93
+ runs: number;
94
+ calls: number;
95
+ inputTokens: number;
96
+ cachedInputTokens: number;
97
+ outputTokens: number;
98
+ cost: number;
99
+ unpricedCalls: number;
100
+ }
101
+ interface UsageSummary {
102
+ total: UsageTotals;
103
+ byDay: Array<UsageTotals & {
104
+ day: string;
105
+ }>;
106
+ byModel: Array<UsageTotals & {
107
+ model: string;
108
+ }>;
109
+ byChannel: Array<UsageTotals & {
110
+ channel: string;
111
+ }>;
112
+ currency: string | null;
113
+ budget: {
114
+ monthly: number;
115
+ } | null;
116
+ }
117
+ type Audience = 'all' | 'internal';
118
+ interface KnowledgeDoc {
119
+ id: string;
120
+ title: string;
121
+ content: string;
122
+ audience: Audience;
123
+ tags: string[];
124
+ updatedAt: string;
125
+ updatedBy?: string;
126
+ }
127
+ interface KnowledgeHit {
128
+ docId: string;
129
+ title: string;
130
+ excerpt: string;
131
+ score: number;
132
+ }
133
+ interface FactSubject {
134
+ type: string;
135
+ id: string;
136
+ label?: string;
137
+ }
138
+ interface Fact {
139
+ id: string;
140
+ subject: FactSubject;
141
+ text: string;
142
+ createdAt: string;
143
+ createdBy: Actor | null;
144
+ }
145
+ declare class StudioError extends Error {
146
+ readonly status: number;
147
+ constructor(message: string, status: number);
148
+ }
149
+ interface StudioClientOptions {
150
+ /** Endereço das rotas do Dolfinhos. Padrão: `/dolfinhos`. */
151
+ endpoint?: string;
152
+ /** Cabeçalhos de cada pedido (ex.: o token de login). */
153
+ headers?: () => Record<string, string> | Promise<Record<string, string>>;
154
+ fetch?: typeof fetch;
155
+ }
156
+ /** Chamadas às rotas de administração do Dolfinhos. */
157
+ declare function createStudioClient(options?: StudioClientOptions): {
158
+ settings: () => Promise<Settings>;
159
+ saveSettings: (settings: Settings) => Promise<Settings>;
160
+ capabilities: () => Promise<Capability[]>;
161
+ events: () => Promise<EventInfo[]>;
162
+ approvals: () => Promise<ApprovalItem[]>;
163
+ decide: (item: ApprovalItem, approved: boolean, reason?: string) => Promise<{
164
+ status: string;
165
+ text: string;
166
+ }>;
167
+ audit: (params?: {
168
+ before?: string;
169
+ limit?: number;
170
+ sessionId?: string;
171
+ }) => Promise<AuditRecord[]>;
172
+ usage: (params?: {
173
+ from?: string;
174
+ to?: string;
175
+ }) => Promise<UsageSummary>;
176
+ knowledge: () => Promise<KnowledgeDoc[]>;
177
+ saveKnowledge: (doc: Partial<Pick<KnowledgeDoc, "id">> & Pick<KnowledgeDoc, "title" | "content" | "audience"> & {
178
+ tags?: string[];
179
+ }) => Promise<KnowledgeDoc>;
180
+ removeKnowledge: (id: string) => Promise<{
181
+ ok: true;
182
+ }>;
183
+ searchKnowledge: (query: string, audience: Audience) => Promise<KnowledgeHit[]>;
184
+ factSubjects: (type?: string) => Promise<(FactSubject & {
185
+ count: number;
186
+ lastAt: string;
187
+ })[]>;
188
+ facts: (subject: Pick<FactSubject, "type" | "id">) => Promise<Fact[]>;
189
+ forget: (id: string) => Promise<{
190
+ ok: true;
191
+ }>;
192
+ };
193
+ type StudioClient = ReturnType<typeof createStudioClient>;
194
+ interface StudioLabels {
195
+ /** Nome de cada canal nas telas (ex.: `{ bot: 'Bot de atendimento' }`). */
196
+ channels?: Record<string, string>;
197
+ /** Nome de cada tipo de pessoa na memória (ex.: `{ contact: 'Contato', user: 'Pessoa da equipe' }`). */
198
+ subjects?: Record<string, string>;
199
+ /** Link para abrir o que originou um pedido (ex.: a conversa do bot). */
200
+ approvalLink?: (item: ApprovalItem) => {
201
+ href: string;
202
+ label: string;
203
+ } | null;
204
+ }
205
+ interface StudioContextValue {
206
+ client: StudioClient;
207
+ labels: StudioLabels;
208
+ locale: string;
209
+ /** Navegação da aplicação (ex.: o `navigate` do roteador) para os links do Studio. */
210
+ navigate?: (href: string) => void;
211
+ }
212
+ declare const StudioContextProvider: react.Provider<StudioContextValue | null>;
213
+ declare function useStudio(): StudioContextValue;
214
+ /** Carrega um recurso e recarrega sob demanda; ignora respostas de pedidos antigos. */
215
+ declare function useResource<T>(load: () => Promise<T>, deps: unknown[]): {
216
+ reload: () => Promise<void>;
217
+ setData: (data: T) => void;
218
+ data: T | null;
219
+ error: string | null;
220
+ loading: boolean;
221
+ };
222
+
223
+ interface ApprovalsInboxProps {
224
+ /** Recarrega a cada tantos ms. Padrão: 30 s. `0` desliga. */
225
+ refreshMs?: number;
226
+ /** Depois de cada decisão (ex.: atualizar um contador no menu ou mostrar um aviso). */
227
+ onDecided?: (args: {
228
+ item: ApprovalItem;
229
+ approved: boolean;
230
+ reply: string;
231
+ }) => void;
232
+ /** Quando a lista muda (ex.: o contador do menu). */
233
+ onCount?: (count: number) => void;
234
+ }
235
+ /** O que bots e automações pediram para fazer. Nada acontece até alguém aprovar. */
236
+ declare function ApprovalsInbox({ refreshMs, onDecided, onCount }: ApprovalsInboxProps): react.JSX.Element;
237
+
238
+ /** O que o assistente fez ou tentou fazer, quem pediu, quem aprovou e qual regra decidiu. */
239
+ declare function AuditLog(): react.JSX.Element;
240
+
241
+ /**
242
+ * Automações escritas pela empresa: "quando X acontecer, faça Y". Rodam como
243
+ * o assistente, com as mesmas regras: o que pede aprovação vai para a caixa.
244
+ */
245
+ declare function AutomationsEditor(): react.JSX.Element;
246
+
247
+ /**
248
+ * O comportamento do assistente nesta empresa: o que faz sozinho, o que
249
+ * pergunta e o que nunca faz; preferências; e o limite de gasto do mês.
250
+ */
251
+ declare function BehaviorSettings({ currency }: {
252
+ currency?: string | null;
253
+ }): react.JSX.Element;
254
+
255
+ /** Documentos que o assistente e o bot consultam: perguntas frequentes, políticas, explicações. */
256
+ declare function KnowledgeBase(): react.JSX.Element;
257
+
258
+ /** O que o assistente e o bot lembram de cada pessoa, para quem administra conferir e apagar. */
259
+ declare function MemoryBrowser(): react.JSX.Element;
260
+ /** As preferências que o assistente guardou sobre quem está usando (cada pessoa vê e apaga as suas). */
261
+ declare function MyMemory({ subject }: {
262
+ subject: Pick<FactSubject, 'type' | 'id'>;
263
+ }): react.JSX.Element;
264
+
265
+ type StudioSection = 'approvals' | 'behavior' | 'automations' | 'knowledge' | 'memory' | 'usage' | 'audit';
266
+ interface DolfinhosStudioProps {
267
+ /** Quais abas mostrar, nesta ordem. Padrão: todas. */
268
+ sections?: StudioSection[];
269
+ /** Aba controlada pela aplicação (ex.: guardada na URL). */
270
+ section?: StudioSection;
271
+ defaultSection?: StudioSection;
272
+ onSectionChange?: (section: StudioSection) => void;
273
+ /** Moeda da tabela de preços, para o campo de limite de gasto. */
274
+ currency?: string | null;
275
+ /** Pedidos esperando (mostra o número na aba). */
276
+ pendingApprovals?: number;
277
+ onPendingApprovalsChange?: (count: number) => void;
278
+ }
279
+ /** Todas as telas de administração do Dolfinhos em abas. Use dentro de `<StudioProvider>`. */
280
+ declare function DolfinhosStudio({ sections, section, defaultSection, onSectionChange, currency, pendingApprovals, onPendingApprovalsChange }: DolfinhosStudioProps): react.JSX.Element;
281
+
282
+ /** Uso e custo de IA: total, limite do mês, por dia, por canal e por modelo. */
283
+ declare function UsageReport(): react.JSX.Element;
284
+
285
+ interface StudioProviderProps extends StudioClientOptions {
286
+ children: ReactNode;
287
+ labels?: StudioLabels;
288
+ /** Idioma das datas e números. Padrão: `pt-BR`. */
289
+ locale?: string;
290
+ /** Navegação da aplicação para os links do Studio (sem recarregar a página). */
291
+ navigate?: (href: string) => void;
292
+ }
293
+ /**
294
+ * Conecta as telas do Studio às rotas do Dolfinhos. Os componentes usam a
295
+ * classe `dlf`; importe `@dolfinhos/studio/styles.css` e ajuste as variáveis
296
+ * `--dlf-*` para o visual da aplicação.
297
+ */
298
+ declare function StudioProvider({ children, endpoint, headers, fetch, labels, locale, navigate }: StudioProviderProps): react.JSX.Element;
299
+
300
+ export { ApprovalsInbox, AuditLog, AutomationsEditor, BehaviorSettings, DolfinhosStudio, KnowledgeBase, MemoryBrowser, MyMemory, StudioContextProvider, StudioError, StudioProvider, UsageReport, createStudioClient, useResource, useStudio };
301
+ export type { Actor, ApprovalItem, ApprovalsInboxProps, Audience, AuditRecord, Automation, Capability, DolfinhosStudioProps, EventInfo, Fact, FactSubject, Kind, KnowledgeDoc, KnowledgeHit, Mode, PendingApproval, Risk, Rule, Settings, StudioClient, StudioClientOptions, StudioLabels, StudioProviderProps, StudioSection, UsageSummary, UsageTotals };