@genspark/cli 1.15.4 → 1.15.6

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.
Files changed (47) hide show
  1. package/README.md +31 -11
  2. package/dist/acp-serve.d.ts +2 -2
  3. package/dist/acp-serve.d.ts.map +1 -1
  4. package/dist/acp-serve.js +7 -2
  5. package/dist/acp-serve.js.map +1 -1
  6. package/dist/client.d.ts +5 -0
  7. package/dist/client.d.ts.map +1 -1
  8. package/dist/client.js +23 -12
  9. package/dist/client.js.map +1 -1
  10. package/dist/commands/aidrive-contract.generated.d.ts.map +1 -1
  11. package/dist/commands/aidrive-contract.generated.js +21 -2
  12. package/dist/commands/aidrive-contract.generated.js.map +1 -1
  13. package/dist/commands/task-status-follow.d.ts +9 -0
  14. package/dist/commands/task-status-follow.d.ts.map +1 -1
  15. package/dist/commands/task-status-follow.js +24 -4
  16. package/dist/commands/task-status-follow.js.map +1 -1
  17. package/dist/confirm.d.ts.map +1 -1
  18. package/dist/confirm.js +18 -1
  19. package/dist/confirm.js.map +1 -1
  20. package/dist/humanApproval.d.ts +48 -0
  21. package/dist/humanApproval.d.ts.map +1 -0
  22. package/dist/humanApproval.js +86 -0
  23. package/dist/humanApproval.js.map +1 -0
  24. package/dist/index.js +88 -21
  25. package/dist/index.js.map +1 -1
  26. package/dist/mediaSummary.d.ts.map +1 -1
  27. package/dist/mediaSummary.js +4 -1
  28. package/dist/mediaSummary.js.map +1 -1
  29. package/dist/task-shim.d.ts +11 -2
  30. package/dist/task-shim.d.ts.map +1 -1
  31. package/dist/task-shim.js +21 -2
  32. package/dist/task-shim.js.map +1 -1
  33. package/docs/skills.md +1 -1
  34. package/gated-skills/gsk-issue/SKILL.md +7 -0
  35. package/gated-skills/gsk-m365-apps/SKILL.md +197 -0
  36. package/gated-skills/gsk-m365-apps/references/add-genspark-ai.md +399 -0
  37. package/gated-skills/gsk-m365-apps/scripts/install-genspark-connector.mjs +548 -0
  38. package/gated-skills/gsk-m365-apps/scripts/sync-microsoft-guidance.mjs +557 -0
  39. package/package.json +1 -1
  40. package/skills/gsk-aidrive/SKILL.md +14 -2
  41. package/skills/gsk-aidrive/command-reference.md +13 -3
  42. package/skills/gsk-image-generation/SKILL.md +6 -3
  43. package/skills/gsk-phone-call/SKILL.md +33 -13
  44. package/skills/gsk-second-brain/SKILL.md +2 -2
  45. package/skills/gsk-slack/SKILL.md +4 -1
  46. package/skills/gsk-team-brain/SKILL.md +89 -22
  47. package/skills/gsk-video-generation/SKILL.md +3 -3
@@ -0,0 +1,399 @@
1
+ # Add Genspark AI to a managed app
2
+
3
+ A managed app has no backend and no secrets, so it cannot call Genspark's APIs
4
+ directly. It creates Genspark **slides and documents** through the **"Genspark"
5
+ custom connector**: an MCP
6
+ connector whose single operation (`InvokeGensparkMCP`) posts JSON-RPC to
7
+ `https://www.genspark.ai/mcp/m365`. Each app user signs in to Genspark once (an
8
+ OAuth connection Power Platform keeps for them). Usage is billed to **that user's**
9
+ Genspark credits.
10
+
11
+ Tools the connector exposes:
12
+
13
+ | Tool | Arguments | Returns (JSON text in `content[0].text`, also `structuredContent`) |
14
+ |---|---|---|
15
+ | `create_slides` | `requirements` | `{project_id, project_url, status, message}`, returns at once |
16
+ | `get_slides_status` | `project_id` | `{status, slide_count, project_url, screenshot_urls}` |
17
+ | `create_document` | `requirements` | `{project_id, project_url, status, message}`, returns at once |
18
+ | `get_document_status` | `project_id` | `{status, project_url, document_type?, content_preview?, content_truncated?}` |
19
+
20
+ `status` is `pending`, `generating`, `completed` or `failed`. One request holds
21
+ at most 10 JSON-RPC messages (the wrapper below sends one at a time).
22
+
23
+ ### `genspark_chat` (gated: `gk_m365_genspark_chat`)
24
+
25
+ | Tool | Arguments | Returns |
26
+ |---|---|---|
27
+ | `genspark_chat` | `message` (required), `system?`, `model?` (`gpt-6-luna` default, `gpt-6-sol`, `claude-sonnet-5-5`), `max_tokens?` (1–2000, default 1000) | the reply as plain text in `content[0].text` |
28
+
29
+ One LLM completion billed to the signed-in user's credits. It is listed by
30
+ `tools/list` and runs only when the user has **both** `gk_m365_managed_apps` and
31
+ `gk_m365_genspark_chat`, and only through the Genspark connector installed in
32
+ Step 1 (any other MCP client gets "genspark_chat is only available from the
33
+ Genspark Microsoft 365 connector"; general LLM use belongs on the Genspark
34
+ Developer API, `/api/v1/chat/completions`). Limits: message + system at most
35
+ 60,000 characters, at most one `genspark_chat` per request (a second one in a
36
+ batch is a JSON-RPC error), refused when the credit balance is empty. If
37
+ `tools/list` does not show it, do not build features on it.
38
+
39
+ ## Step 1: install the connector into the app's environment
40
+
41
+ Run once per Power Platform environment (re-running is safe: it updates the
42
+ connector in place). From the app folder (`ms.config.json` must exist):
43
+
44
+ ```bash
45
+ node "$SKILL_DIR/scripts/install-genspark-connector.mjs"
46
+ # options: --environment-id <id> --tenant <tenant-id|domain> --project <app dir> --dry-run
47
+ ```
48
+
49
+ What happens, so you can explain it to the user:
50
+
51
+ 1. It reads `environmentId` from `ms.config.json` and the tenant from
52
+ `ms auth status --json`.
53
+ 2. It prints a Microsoft sign-in message such as *"To sign in, use a web browser to
54
+ open https://microsoft.com/devicelogin and enter the code ABCD-EFGH"*. Relay it
55
+ verbatim and ask the user to sign in with the **same work account** as `ms`. The
56
+ sign-in uses Microsoft's own Azure CLI client (the one Microsoft's `paconn`
57
+ connector CLI uses) and asks for "Power Apps service" access. The script polls
58
+ until the user finishes (up to 15 minutes).
59
+ 3. It calls `gsk m365 connector_config` with that sign-in's ID token (on stdin,
60
+ never on the command line). Genspark checks the token is a Microsoft one for
61
+ that tenant and returns the **environment's Genspark connector client**: one
62
+ per Microsoft tenant environment, created the first time any maker installs the
63
+ connector there and shared by all of them.
64
+ 4. It creates or updates the "Genspark" custom connector in the environment with
65
+ the user's Microsoft token and prints `{"connector_id": "shared_genspark-…",
66
+ "created": true, "display_name": "Genspark", "environment_id": "…"}`. It only
67
+ updates a connector Genspark created (named "Genspark (Microsoft 365 apps)" when
68
+ the maker already has their own "Genspark"), and leaves one that holds another
69
+ sign-in client unchanged (`"skipped": "client_mismatch"`).
70
+
71
+ The client secret and the Microsoft tokens stay in the script's memory. Never echo
72
+ them, write them to a file, or paste them into chat. `--dry-run` prints the
73
+ request it would send (secret redacted) without signing in or changing anything.
74
+
75
+ Errors you may see:
76
+
77
+ | Message | Meaning / what to do |
78
+ |---|---|
79
+ | `AADSTS50199`, `AADSTS53003`, "device code flow is blocked" | The tenant's Conditional Access blocks device code sign-in. The admin must allow it for the user, or publish from Genspark's cloud editor instead. |
80
+ | `invalid_tenant_proof` | The sign-in was for another tenant or account. Sign in with the work account `ms auth status` shows. |
81
+ | `Power Apps API 403` | The user may not create custom connectors in this environment (needs Environment Maker), or a policy blocks it. |
82
+ | `not available` / unknown command `m365` | The user's Genspark account does not have Microsoft 365 apps enabled. |
83
+
84
+ ## Step 2: add the connector to the app
85
+
86
+ ```bash
87
+ ms connector list --search genspark # confirm the id printed by the installer
88
+ ms app add data-source --connector <connector_id> --as action
89
+ ```
90
+
91
+ The CLI asks which connection to use. The first time, choose **(Create a new
92
+ connection)**: a browser opens the Genspark sign-in and consent page ("Microsoft
93
+ Power Platform – Genspark connector … wants to use Genspark tools"). The user signs
94
+ in to **Genspark** and approves. That connection is the user's own; every other app
95
+ user gets the same prompt the first time they open the app.
96
+
97
+ If the shell is non-interactive and the CLI says the connection needs browser
98
+ consent, give the user the exact command to run in their own terminal from the app
99
+ folder, then continue.
100
+
101
+ This generates `generated/services/<Name>Service.ts` (normally `GensparkService`)
102
+ and `generated/models/<Name>Model.ts`. Check the generated signature; with the
103
+ current connector it is:
104
+
105
+ ```typescript
106
+ GensparkService.InvokeGensparkMCP(queryRequest: QueryRequest, Mcp_Session_Id?: string)
107
+ ```
108
+
109
+ If the names differ, adjust the two imports and the one call in the wrapper below.
110
+ If `ms.config.json` records a `sharedConnectionId` for it, declare
111
+ `"allowedActions": ["InvokeGensparkMCP"]` on that reference
112
+ (`$MS_GUIDE/shared/allowed-actions.md`, from `scripts/sync-microsoft-guidance.mjs`).
113
+
114
+ ## Step 3: the MCP session wrapper
115
+
116
+ MCP is a JSON-RPC protocol: `initialize` once, then `tools/list` / `tools/call`.
117
+ Replies may arrive as an object **or as an SSE string** (`event: message\ndata:
118
+ {...}`), and the connector may hand back a session id. Copy this file as
119
+ `src/connectors/genspark.ts`:
120
+
121
+ ```typescript
122
+ import type { IOperationResult } from '@microsoft/cmr-apps/data' // apps scaffolded before Nov 2026: '@microsoft/managed-apps/data' (match generated/)
123
+ import { GensparkService } from '../../generated/services/GensparkService'
124
+ import type { QueryRequest } from '../../generated/models/GensparkModel'
125
+
126
+ interface JsonRpcResponse {
127
+ jsonrpc?: string
128
+ id?: string | number | null
129
+ result?: Record<string, unknown>
130
+ error?: { code?: number; message?: string; data?: unknown }
131
+ }
132
+
133
+ export interface ToolResult<T = unknown> {
134
+ text: string
135
+ data: T | undefined
136
+ }
137
+
138
+ export class GensparkError extends Error {
139
+ constructor(message: string, readonly code?: number) {
140
+ super(message)
141
+ this.name = 'GensparkError'
142
+ }
143
+ }
144
+
145
+ /** One JSON-RPC message from an object, a JSON string, or an SSE body. */
146
+ export function parseRpc(raw: unknown, id?: string): JsonRpcResponse {
147
+ if (raw == null || raw === '') return {}
148
+ if (typeof raw === 'object') return raw as JsonRpcResponse
149
+ if (typeof raw !== 'string') return { result: { raw } }
150
+ const text = raw.trim()
151
+ if (text.startsWith('{') || text.startsWith('[')) {
152
+ try {
153
+ const parsed = JSON.parse(text) as JsonRpcResponse | JsonRpcResponse[]
154
+ return Array.isArray(parsed) ? (parsed.find((m) => m.id === id) ?? parsed[0] ?? {}) : parsed
155
+ } catch {
156
+ return { result: { raw } }
157
+ }
158
+ }
159
+ // SSE: events separated by blank lines; each event's data: lines join with "\n".
160
+ const messages: JsonRpcResponse[] = []
161
+ for (const event of text.split(/\r?\n\r?\n/)) {
162
+ const data = event
163
+ .split(/\r?\n/)
164
+ .filter((line) => line.startsWith('data:'))
165
+ .map((line) => line.slice(5).replace(/^ /, ''))
166
+ .join('\n')
167
+ if (!data) continue
168
+ try {
169
+ messages.push(JSON.parse(data) as JsonRpcResponse)
170
+ } catch {
171
+ // keep-alive or non-JSON event
172
+ }
173
+ }
174
+ const answers = messages.filter((m) => m.result !== undefined || m.error !== undefined)
175
+ return answers.find((m) => String(m.id) === id) ?? answers[answers.length - 1] ?? { result: { raw } }
176
+ }
177
+
178
+ function findSessionId(raw: IOperationResult<unknown>): string | undefined {
179
+ const holders = [raw as unknown, raw.data, (raw.data as { result?: unknown } | undefined)?.result]
180
+ for (const holder of holders) {
181
+ if (!holder || typeof holder !== 'object') continue
182
+ const record = holder as Record<string, unknown>
183
+ for (const key of ['Mcp-Session-Id', 'mcp-session-id', 'mcpSessionId', 'sessionId']) {
184
+ const value = record[key]
185
+ if (typeof value === 'string' && value) return value
186
+ }
187
+ }
188
+ return undefined
189
+ }
190
+
191
+ export class GensparkMcp {
192
+ private nextId = 1
193
+ private sessionId: string | undefined
194
+ private ready: Promise<void> | undefined
195
+ private tools: Array<{ name: string; description?: string }> | undefined
196
+
197
+ private async send(method: string, params?: Record<string, unknown>, retry = true): Promise<JsonRpcResponse> {
198
+ const id = String(this.nextId++)
199
+ const request = { jsonrpc: '2.0', id, method, ...(params ? { params } : {}) }
200
+ const raw = (await GensparkService.InvokeGensparkMCP(
201
+ request as unknown as QueryRequest,
202
+ this.sessionId
203
+ )) as unknown as IOperationResult<unknown>
204
+ if (!raw.success && raw.error) {
205
+ throw new GensparkError(raw.error.message || 'Genspark connector call failed')
206
+ }
207
+ this.sessionId = findSessionId(raw) ?? this.sessionId
208
+ const response = parseRpc(raw.data, id)
209
+ const message = (response.error?.message ?? '').toLowerCase()
210
+ if (retry && method !== 'initialize' && (response.error?.code === -32001 || message.includes('session not found'))) {
211
+ this.sessionId = undefined
212
+ this.ready = undefined
213
+ await this.initialize()
214
+ return this.send(method, params, false)
215
+ }
216
+ if (response.error) throw new GensparkError(response.error.message || 'Genspark error', response.error.code)
217
+ return response
218
+ }
219
+
220
+ /** Handshake once per app session; concurrent callers share it. */
221
+ initialize(): Promise<void> {
222
+ this.ready ??= this.send('initialize', {
223
+ protocolVersion: '2025-06-18',
224
+ capabilities: {},
225
+ clientInfo: { name: 'Microsoft 365 managed app', version: '1.0.0' },
226
+ })
227
+ .then(async () => {
228
+ // Notifications get no reply; a failure here is harmless.
229
+ await this.send('notifications/initialized').catch(() => undefined)
230
+ })
231
+ .catch((error: unknown) => {
232
+ this.ready = undefined
233
+ throw error
234
+ })
235
+ return this.ready
236
+ }
237
+
238
+ async listTools(): Promise<Array<{ name: string; description?: string }>> {
239
+ await this.initialize()
240
+ if (!this.tools) {
241
+ const response = await this.send('tools/list')
242
+ this.tools = (response.result?.tools as Array<{ name: string; description?: string }>) ?? []
243
+ }
244
+ return this.tools
245
+ }
246
+
247
+ async callTool<T = unknown>(name: string, args: Record<string, unknown>): Promise<ToolResult<T>> {
248
+ await this.initialize()
249
+ const response = await this.send('tools/call', { name, arguments: args })
250
+ const result = response.result ?? {}
251
+ const content = (result.content as Array<{ type?: string; text?: string }> | undefined) ?? []
252
+ const text = content
253
+ .filter((c) => c.type === 'text' && typeof c.text === 'string')
254
+ .map((c) => c.text as string)
255
+ .join('\n')
256
+ .trim()
257
+ let data = result.structuredContent as T | undefined
258
+ if (data === undefined && text.startsWith('{')) {
259
+ try {
260
+ data = JSON.parse(text) as T
261
+ } catch {
262
+ // plain text reply
263
+ }
264
+ }
265
+ if (result.isError) throw new GensparkError(text || 'Genspark tool failed')
266
+ return { text, data }
267
+ }
268
+
269
+ // ---- typed helpers -------------------------------------------------------
270
+
271
+ // Only when tools/list shows genspark_chat (gk_m365_genspark_chat).
272
+ async chat(message: string, options: { system?: string; model?: string; maxTokens?: number } = {}): Promise<string> {
273
+ const { text } = await this.callTool('genspark_chat', {
274
+ message,
275
+ ...(options.system ? { system: options.system } : {}),
276
+ ...(options.model ? { model: options.model } : {}),
277
+ ...(options.maxTokens ? { max_tokens: options.maxTokens } : {}),
278
+ })
279
+ return text
280
+ }
281
+
282
+ createSlides(requirements: string) {
283
+ return this.callTool<GensparkProject>('create_slides', { requirements })
284
+ }
285
+
286
+ getSlidesStatus(projectId: string) {
287
+ return this.callTool<GensparkProject & { slide_count?: number; screenshot_urls?: string[] }>(
288
+ 'get_slides_status',
289
+ { project_id: projectId }
290
+ )
291
+ }
292
+
293
+ createDocument(requirements: string) {
294
+ return this.callTool<GensparkProject>('create_document', { requirements })
295
+ }
296
+
297
+ getDocumentStatus(projectId: string) {
298
+ return this.callTool<GensparkProject & { content_preview?: string; content_truncated?: boolean }>(
299
+ 'get_document_status',
300
+ { project_id: projectId }
301
+ )
302
+ }
303
+
304
+ /** Poll a slides/document project until it completes or fails. */
305
+ async waitFor(
306
+ kind: 'slides' | 'document',
307
+ projectId: string,
308
+ { intervalMs = 5000, timeoutMs = 10 * 60_000 } = {}
309
+ ): Promise<GensparkProject> {
310
+ const deadline = Date.now() + timeoutMs
311
+ for (;;) {
312
+ const { data } = kind === 'slides' ? await this.getSlidesStatus(projectId) : await this.getDocumentStatus(projectId)
313
+ if (data?.status === 'completed') return data
314
+ if (data?.status === 'failed') throw new GensparkError(data.message || `${kind} generation failed`)
315
+ if (Date.now() > deadline) throw new GensparkError(`${kind} generation is still running; open ${data?.project_url}`)
316
+ await new Promise((resolve) => setTimeout(resolve, intervalMs))
317
+ }
318
+ }
319
+ }
320
+
321
+ export interface GensparkProject {
322
+ project_id?: string
323
+ project_url?: string
324
+ status?: 'pending' | 'generating' | 'completed' | 'failed' | string
325
+ message?: string
326
+ }
327
+
328
+ /** One session per app. */
329
+ export const genspark = new GensparkMcp()
330
+ ```
331
+
332
+ ## Step 4: use it from React
333
+
334
+ ```tsx
335
+ import { useState } from 'react'
336
+ import { genspark, GensparkError } from './connectors/genspark'
337
+
338
+ export function BriefingCard({ text }: { text: string }) {
339
+ const [docUrl, setDocUrl] = useState('')
340
+ const [deckUrl, setDeckUrl] = useState('')
341
+ const [busy, setBusy] = useState(false)
342
+ const [error, setError] = useState('')
343
+
344
+ async function run<T>(work: () => Promise<T>) {
345
+ setBusy(true)
346
+ setError('')
347
+ try {
348
+ return await work()
349
+ } catch (e) {
350
+ setError(e instanceof GensparkError ? e.message : 'Genspark is not reachable right now.')
351
+ } finally {
352
+ setBusy(false)
353
+ }
354
+ }
355
+
356
+ const writeReport = () =>
357
+ run(async () => {
358
+ const { data } = await genspark.createDocument(`A one-page briefing for a busy manager about:\n${text.slice(0, 8000)}`)
359
+ if (!data?.project_id) throw new GensparkError(data?.message || 'Could not start the document')
360
+ const done = await genspark.waitFor('document', data.project_id)
361
+ setDocUrl(done.project_url ?? '')
362
+ })
363
+
364
+ const makeDeck = () =>
365
+ run(async () => {
366
+ const { data } = await genspark.createSlides(`A 6-slide briefing deck about:\n${text.slice(0, 8000)}`)
367
+ if (!data?.project_id) throw new GensparkError(data?.message || 'Could not start the deck')
368
+ const done = await genspark.waitFor('slides', data.project_id)
369
+ setDeckUrl(done.project_url ?? '')
370
+ })
371
+
372
+ return (
373
+ <section>
374
+ <button disabled={busy} onClick={writeReport}>Write a briefing</button>
375
+ <button disabled={busy} onClick={makeDeck}>Make a deck</button>
376
+ {error && <p role="alert">{error}</p>}
377
+ {docUrl && (
378
+ <a href={docUrl} target="_blank" rel="noreferrer">Open the briefing in Genspark</a>
379
+ )}
380
+ {deckUrl && (
381
+ <a href={deckUrl} target="_blank" rel="noreferrer">Open the deck in Genspark</a>
382
+ )}
383
+ </section>
384
+ )
385
+ }
386
+ ```
387
+
388
+ Notes:
389
+
390
+ - Call `genspark` only from user actions; every slide deck, document or
391
+ `chat` reply spends the signed-in user's credits. Keep `maxTokens` small for UI
392
+ snippets.
393
+ - Slides and documents are created in the user's Genspark account; link to
394
+ `project_url` rather than embedding it (the app's content security policy may
395
+ block third-party frames and images).
396
+ - Send only the data the feature needs: whatever the app passes to Genspark leaves
397
+ the tenant under the user's Genspark account.
398
+ - If a call fails with an authentication error, the user's Genspark connection was
399
+ removed or expired; the App Player asks them to sign in again.