@burdenoff/microfe-botmanor 2026.1119.3 → 2026.1119.4

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,167 @@
1
+ import { useWorkspaceClient as e, useWorkspaceId as t, useWorkspaceMutation as n } from "./internal/workspaceGateway.js";
2
+ import { useCallback as r, useEffect as i, useRef as a, useState as o } from "react";
3
+ import { gql as s } from "@apollo/client";
4
+ // src/botlit/hooks/useBotCopilot.ts
5
+ var c = s`
6
+ mutation draftBotFromDescription($input: DraftBotFromDescriptionInput!) {
7
+ draftBotFromDescription(input: $input) {
8
+ draftId
9
+ scope
10
+ description
11
+ llmModelId
12
+ model
13
+ template {
14
+ id
15
+ name
16
+ kind
17
+ }
18
+ app {
19
+ name
20
+ description
21
+ type
22
+ routingStrategy
23
+ welcomeMessage
24
+ fallbackMessage
25
+ }
26
+ agents {
27
+ key
28
+ name
29
+ description
30
+ type
31
+ systemPrompt
32
+ temperature
33
+ knowledgeBaseIds
34
+ templateId
35
+ }
36
+ links {
37
+ agentKey
38
+ priority
39
+ isDefault
40
+ intentPatterns
41
+ triggerKeywords
42
+ fallbackAgentKey
43
+ }
44
+ knowledgeBases {
45
+ knowledgeBaseId
46
+ name
47
+ reason
48
+ agentKeys
49
+ }
50
+ notes
51
+ inputTokens
52
+ outputTokens
53
+ aiCredits
54
+ }
55
+ }
56
+ `, l = s`
57
+ mutation createBotFromDraft($input: CreateBotFromDraftInput!) {
58
+ createBotFromDraft(input: $input) {
59
+ app {
60
+ id
61
+ name
62
+ }
63
+ agents {
64
+ id
65
+ name
66
+ }
67
+ }
68
+ }
69
+ `, u = s`
70
+ mutation createAgentsFromDraft($input: CreateAgentsFromDraftInput!) {
71
+ createAgentsFromDraft(input: $input) {
72
+ app {
73
+ id
74
+ name
75
+ }
76
+ agents {
77
+ id
78
+ name
79
+ }
80
+ }
81
+ }
82
+ `;
83
+ function d(e, t) {
84
+ return e instanceof Error ? e : Error(t);
85
+ }
86
+ function f() {
87
+ let n = e(), s = t(), l = a(null), [u, f] = o(!1), p = r(() => {
88
+ l.current?.abort(), l.current = null, f(!1);
89
+ }, []);
90
+ return i(() => p, [p, s]), {
91
+ draft: r(async (e) => {
92
+ l.current?.abort();
93
+ let t = new AbortController();
94
+ l.current = t, f(!0);
95
+ try {
96
+ let r = await n.mutate({
97
+ mutation: c,
98
+ variables: { input: {
99
+ ...e,
100
+ workspaceId: s
101
+ } },
102
+ context: { fetchOptions: { signal: t.signal } }
103
+ });
104
+ if (t.signal.aborted) return null;
105
+ let i = r.error;
106
+ if (i != null) throw d(i, "Failed to draft the bot");
107
+ let a = r.data?.draftBotFromDescription;
108
+ if (!a) throw Error("Failed to draft the bot");
109
+ return a;
110
+ } catch (e) {
111
+ if (t.signal.aborted) return null;
112
+ throw d(e, "Failed to draft the bot");
113
+ } finally {
114
+ l.current === t && (l.current = null, f(!1));
115
+ }
116
+ }, [n, s]),
117
+ cancel: p,
118
+ loading: u,
119
+ workspaceId: s
120
+ };
121
+ }
122
+ var p = (e) => ({
123
+ key: e.key,
124
+ name: e.name.trim(),
125
+ description: e.description?.trim() || null,
126
+ type: e.type,
127
+ systemPrompt: e.systemPrompt.trim(),
128
+ temperature: e.temperature,
129
+ knowledgeBaseIds: e.knowledgeBaseIds,
130
+ templateId: e.templateId
131
+ });
132
+ function m(e) {
133
+ let r = t();
134
+ return n({
135
+ document: e === "BOT" ? l : u,
136
+ variables: ({ draft: t, app: n, agents: i, links: a }) => {
137
+ let o = {
138
+ workspaceId: r,
139
+ draftId: t.draftId,
140
+ description: t.description,
141
+ llmModelId: t.llmModelId,
142
+ templateId: t.template?.id ?? null,
143
+ agents: i.map(p)
144
+ };
145
+ return { input: e === "BOT" && n ? {
146
+ ...o,
147
+ app: {
148
+ name: n.name.trim(),
149
+ description: n.description?.trim() || null,
150
+ type: n.type,
151
+ routingStrategy: i.length > 1 ? n.routingStrategy : "SINGLE",
152
+ welcomeMessage: n.welcomeMessage?.trim() || null,
153
+ fallbackMessage: n.fallbackMessage?.trim() || null
154
+ },
155
+ links: a.filter((e) => i.some((t) => t.key === e.agentKey)).map((e) => ({
156
+ ...e,
157
+ fallbackAgentKey: e.fallbackAgentKey && i.some((t) => t.key === e.fallbackAgentKey) ? e.fallbackAgentKey : null
158
+ }))
159
+ } : o };
160
+ },
161
+ select: (t) => (e === "BOT" ? t?.createBotFromDraft : t?.createAgentsFromDraft) ?? void 0,
162
+ errorMessage: e === "BOT" ? "Failed to create the draft bot" : "Failed to create the draft agents"
163
+ });
164
+ }
165
+ export { m as useCreateFromDraft, f as useDraftBot };
166
+
167
+ //# sourceMappingURL=useBotCopilot.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useBotCopilot.js","names":["DRAFT_DOCUMENT","CREATE_BOT_DOCUMENT","CREATE_AGENTS_DOCUMENT","errorOf","value","fallback","useDraftBot","client","useWorkspaceClient","workspaceId","useWorkspaceId","controller","useRef","loading","setLoading","useState","cancel","useCallback","useEffect","current","result","request","operationError","data","error","agentInput","agent","useCreateFromDraft","useWorkspaceMutation","scope","base","draft","agents","app","links","link"],"sources":["../../../src/botlit/hooks/useBotCopilot.ts"],"sourcesContent":["/**\n * Copilot \"Describe your bot\" (BOFF-15360, BL-UC-21)\n * @module botlit/hooks\n *\n * `draftBotFromDescription` turns one sentence into a reviewable plan and\n * writes nothing; it is metered as AI credits. `createBotFromDraft` /\n * `createAgentsFromDraft` create only what the person accepted, as DRAFT\n * entities, in one transaction. Drafting is cancellable: the request is\n * aborted and its answer discarded.\n */\n\nimport { gql } from '@apollo/client';\nimport { useCallback, useEffect, useRef, useState } from 'react';\n\nimport {\n useWorkspaceClient,\n useWorkspaceId,\n useWorkspaceMutation,\n} from './internal/workspaceGateway';\n\nexport type BotDraftScope = 'BOT' | 'AGENTS';\nexport type DraftAgentType = 'ASSISTANT' | 'AUTOMATION' | 'ANALYST' | 'SPECIALIST';\nexport type DraftRoutingStrategy = 'SINGLE' | 'ROUND_ROBIN' | 'INTELLIGENT';\n\nexport interface BotDraftApp {\n name: string;\n description: string | null;\n type: DraftAgentType;\n routingStrategy: DraftRoutingStrategy;\n welcomeMessage: string | null;\n fallbackMessage: string | null;\n}\n\nexport interface BotDraftAgent {\n key: string;\n name: string;\n description: string | null;\n type: DraftAgentType;\n systemPrompt: string;\n temperature: number | null;\n knowledgeBaseIds: string[];\n templateId: string | null;\n}\n\nexport interface BotDraftLink {\n agentKey: string;\n priority: number;\n isDefault: boolean;\n intentPatterns: string[];\n triggerKeywords: string[];\n fallbackAgentKey: string | null;\n}\n\nexport interface BotDraftKnowledgeBase {\n knowledgeBaseId: string;\n name: string;\n reason: string;\n agentKeys: string[];\n}\n\nexport interface BotDraft {\n draftId: string;\n scope: BotDraftScope;\n description: string;\n llmModelId: string;\n model: string;\n template: { id: string; name: string; kind: string } | null;\n app: BotDraftApp | null;\n agents: BotDraftAgent[];\n links: BotDraftLink[];\n knowledgeBases: BotDraftKnowledgeBase[];\n notes: string | null;\n inputTokens: number;\n outputTokens: number;\n aiCredits: number | null;\n}\n\nexport interface CreatedDraft {\n app: { id: string; name: string } | null;\n agents: Array<{ id: string; name: string }>;\n}\n\nconst DRAFT_DOCUMENT = gql`\n mutation draftBotFromDescription($input: DraftBotFromDescriptionInput!) {\n draftBotFromDescription(input: $input) {\n draftId\n scope\n description\n llmModelId\n model\n template {\n id\n name\n kind\n }\n app {\n name\n description\n type\n routingStrategy\n welcomeMessage\n fallbackMessage\n }\n agents {\n key\n name\n description\n type\n systemPrompt\n temperature\n knowledgeBaseIds\n templateId\n }\n links {\n agentKey\n priority\n isDefault\n intentPatterns\n triggerKeywords\n fallbackAgentKey\n }\n knowledgeBases {\n knowledgeBaseId\n name\n reason\n agentKeys\n }\n notes\n inputTokens\n outputTokens\n aiCredits\n }\n }\n`;\n\nconst CREATE_BOT_DOCUMENT = gql`\n mutation createBotFromDraft($input: CreateBotFromDraftInput!) {\n createBotFromDraft(input: $input) {\n app {\n id\n name\n }\n agents {\n id\n name\n }\n }\n }\n`;\n\nconst CREATE_AGENTS_DOCUMENT = gql`\n mutation createAgentsFromDraft($input: CreateAgentsFromDraftInput!) {\n createAgentsFromDraft(input: $input) {\n app {\n id\n name\n }\n agents {\n id\n name\n }\n }\n }\n`;\n\nexport interface DraftRequest {\n description: string;\n llmModelId: string;\n scope: BotDraftScope;\n}\n\nfunction errorOf(value: unknown, fallback: string): Error {\n if (value instanceof Error) return value;\n return new Error(fallback);\n}\n\n/** Draft from a sentence. `cancel` aborts the request; nothing was written, so nothing is left behind. */\nexport function useDraftBot() {\n const client = useWorkspaceClient();\n const workspaceId = useWorkspaceId();\n const controller = useRef<AbortController | null>(null);\n const [loading, setLoading] = useState(false);\n\n const cancel = useCallback(() => {\n controller.current?.abort();\n controller.current = null;\n setLoading(false);\n }, []);\n\n // A draft belongs to the workspace it was asked in: switching workspace (or\n // unmounting) abandons an in-flight draft instead of letting it land later.\n useEffect(() => cancel, [cancel, workspaceId]);\n\n const draft = useCallback(\n async (request: DraftRequest): Promise<BotDraft | null> => {\n controller.current?.abort();\n const current = new AbortController();\n controller.current = current;\n setLoading(true);\n try {\n const result = await client.mutate<{ draftBotFromDescription?: BotDraft | null }>({\n mutation: DRAFT_DOCUMENT,\n variables: { input: { ...request, workspaceId } },\n context: { fetchOptions: { signal: current.signal } },\n });\n if (current.signal.aborted) return null;\n const operationError = (result as { error?: unknown }).error;\n if (operationError != null) throw errorOf(operationError, 'Failed to draft the bot');\n const data = result.data?.draftBotFromDescription;\n if (!data) throw new Error('Failed to draft the bot');\n return data;\n } catch (error: unknown) {\n if (current.signal.aborted) return null;\n throw errorOf(error, 'Failed to draft the bot');\n } finally {\n if (controller.current === current) {\n controller.current = null;\n setLoading(false);\n }\n }\n },\n [client, workspaceId]\n );\n\n return { draft, cancel, loading, workspaceId } as const;\n}\n\nexport interface CreateFromDraftInput {\n draft: BotDraft;\n app: BotDraftApp | null;\n agents: BotDraftAgent[];\n links: BotDraftLink[];\n}\n\nconst agentInput = (agent: BotDraftAgent) => ({\n key: agent.key,\n name: agent.name.trim(),\n description: agent.description?.trim() || null,\n type: agent.type,\n systemPrompt: agent.systemPrompt.trim(),\n temperature: agent.temperature,\n knowledgeBaseIds: agent.knowledgeBaseIds,\n templateId: agent.templateId,\n});\n\n/** Create the reviewed draft as DRAFT entities. */\nexport function useCreateFromDraft(scope: BotDraftScope) {\n const workspaceId = useWorkspaceId();\n return useWorkspaceMutation<\n {\n createBotFromDraft?: CreatedDraft | null;\n createAgentsFromDraft?: CreatedDraft | null;\n },\n CreateFromDraftInput,\n CreatedDraft\n >({\n document: scope === 'BOT' ? CREATE_BOT_DOCUMENT : CREATE_AGENTS_DOCUMENT,\n variables: ({ draft, app, agents, links }) => {\n const base = {\n workspaceId,\n draftId: draft.draftId,\n description: draft.description,\n llmModelId: draft.llmModelId,\n templateId: draft.template?.id ?? null,\n agents: agents.map(agentInput),\n };\n return {\n input:\n scope === 'BOT' && app\n ? {\n ...base,\n app: {\n name: app.name.trim(),\n description: app.description?.trim() || null,\n type: app.type,\n routingStrategy: agents.length > 1 ? app.routingStrategy : 'SINGLE',\n welcomeMessage: app.welcomeMessage?.trim() || null,\n fallbackMessage: app.fallbackMessage?.trim() || null,\n },\n links: links\n .filter((link) => agents.some((agent) => agent.key === link.agentKey))\n .map((link) => ({\n ...link,\n fallbackAgentKey:\n link.fallbackAgentKey &&\n agents.some((agent) => agent.key === link.fallbackAgentKey)\n ? link.fallbackAgentKey\n : null,\n })),\n }\n : base,\n };\n },\n select: (data) =>\n (scope === 'BOT' ? data?.createBotFromDraft : data?.createAgentsFromDraft) ?? undefined,\n errorMessage:\n scope === 'BOT' ? 'Failed to create the draft bot' : 'Failed to create the draft agents',\n });\n}\n"],"mappings":";;;;AAkFA,IAAMA,IAAiB,CAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqDpBC,IAAsB,CAAG;;;;;;;;;;;;;GAezBC,IAAyB,CAAG;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