mirror of
https://github.com/simstudioai/sim.git
synced 2026-01-20 04:17:57 -05:00
Compare commits
36 Commits
fix/start-
...
feat/super
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
526b7a64f6 | ||
|
|
9da689bc8e | ||
|
|
e1bea05de0 | ||
|
|
5f45db4343 | ||
|
|
81cbfe7af4 | ||
|
|
739341b08e | ||
|
|
3c43779ba3 | ||
|
|
1861f77283 | ||
|
|
72c2ba7443 | ||
|
|
037dad6975 | ||
|
|
408597e12b | ||
|
|
932f8fd654 | ||
|
|
b4c2294e67 | ||
|
|
1dbf92db3f | ||
|
|
3a923648cb | ||
|
|
5e2468cfd3 | ||
|
|
7c0f43305b | ||
|
|
ee7572185a | ||
|
|
19a8daedf7 | ||
|
|
0fcd52683a | ||
|
|
b8b20576d3 | ||
|
|
4b8534ebd0 | ||
|
|
f6960a4bd4 | ||
|
|
8740566f6a | ||
|
|
5de7228dd9 | ||
|
|
75898c69ed | ||
|
|
b14672887b | ||
|
|
d024c1e489 | ||
|
|
d75ea37b3c | ||
|
|
fd23220cc3 | ||
|
|
a8d81097fc | ||
|
|
3768c6379c | ||
|
|
aa80116b99 | ||
|
|
78e4ca9d45 | ||
|
|
ce3ddb6ba0 | ||
|
|
8361931cdf |
@@ -9,12 +9,12 @@
|
|||||||
<p align="center">
|
<p align="center">
|
||||||
<a href="https://sim.ai" target="_blank" rel="noopener noreferrer"><img src="https://img.shields.io/badge/sim.ai-6F3DFA" alt="Sim.ai"></a>
|
<a href="https://sim.ai" target="_blank" rel="noopener noreferrer"><img src="https://img.shields.io/badge/sim.ai-6F3DFA" alt="Sim.ai"></a>
|
||||||
<a href="https://discord.gg/Hr4UWYEcTT" target="_blank" rel="noopener noreferrer"><img src="https://img.shields.io/badge/Discord-Join%20Server-5865F2?logo=discord&logoColor=white" alt="Discord"></a>
|
<a href="https://discord.gg/Hr4UWYEcTT" target="_blank" rel="noopener noreferrer"><img src="https://img.shields.io/badge/Discord-Join%20Server-5865F2?logo=discord&logoColor=white" alt="Discord"></a>
|
||||||
<a href="https://x.com/simdotai" target="_blank" rel="noopener noreferrer"><img src="https://img.shields.io/twitter/follow/simstudioai?style=social" alt="Twitter"></a>
|
<a href="https://x.com/simdotai" target="_blank" rel="noopener noreferrer"><img src="https://img.shields.io/twitter/follow/simdotai?style=social" alt="Twitter"></a>
|
||||||
<a href="https://docs.sim.ai" target="_blank" rel="noopener noreferrer"><img src="https://img.shields.io/badge/Docs-6F3DFA.svg" alt="Documentation"></a>
|
<a href="https://docs.sim.ai" target="_blank" rel="noopener noreferrer"><img src="https://img.shields.io/badge/Docs-6F3DFA.svg" alt="Documentation"></a>
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<p align="center">
|
<p align="center">
|
||||||
<a href="https://cursor.com/link/prompt?text=Help%20me%20set%20up%20Sim%20Studio%20locally.%20Follow%20these%20steps%3A%0A%0A1.%20First%2C%20verify%20Docker%20is%20installed%20and%20running%3A%0A%20%20%20docker%20--version%0A%20%20%20docker%20info%0A%0A2.%20Clone%20the%20repository%3A%0A%20%20%20git%20clone%20https%3A%2F%2Fgithub.com%2Fsimstudioai%2Fsim.git%0A%20%20%20cd%20sim%0A%0A3.%20Start%20the%20services%20with%20Docker%20Compose%3A%0A%20%20%20docker%20compose%20-f%20docker-compose.prod.yml%20up%20-d%0A%0A4.%20Wait%20for%20all%20containers%20to%20be%20healthy%20(this%20may%20take%201-2%20minutes)%3A%0A%20%20%20docker%20compose%20-f%20docker-compose.prod.yml%20ps%0A%0A5.%20Verify%20the%20app%20is%20accessible%20at%20http%3A%2F%2Flocalhost%3A3000%0A%0AIf%20there%20are%20any%20errors%2C%20help%20me%20troubleshoot%20them.%20Common%20issues%3A%0A-%20Port%203000%2C%203002%2C%20or%205432%20already%20in%20use%0A-%20Docker%20not%20running%0A-%20Insufficient%20memory%20(needs%2012GB%2B%20RAM)%0A%0AFor%20local%20AI%20models%20with%20Ollama%2C%20use%20this%20instead%20of%20step%203%3A%0A%20%20%20docker%20compose%20-f%20docker-compose.ollama.yml%20--profile%20setup%20up%20-d"><img src="https://img.shields.io/badge/Set%20Up%20with-Cursor-000000?logo=cursor&logoColor=white" alt="Set Up with Cursor"></a>
|
<a href="https://deepwiki.com/simstudioai/sim" target="_blank" rel="noopener noreferrer"><img src="https://deepwiki.com/badge.svg" alt="Ask DeepWiki"></a> <a href="https://cursor.com/link/prompt?text=Help%20me%20set%20up%20Sim%20Studio%20locally.%20Follow%20these%20steps%3A%0A%0A1.%20First%2C%20verify%20Docker%20is%20installed%20and%20running%3A%0A%20%20%20docker%20--version%0A%20%20%20docker%20info%0A%0A2.%20Clone%20the%20repository%3A%0A%20%20%20git%20clone%20https%3A%2F%2Fgithub.com%2Fsimstudioai%2Fsim.git%0A%20%20%20cd%20sim%0A%0A3.%20Start%20the%20services%20with%20Docker%20Compose%3A%0A%20%20%20docker%20compose%20-f%20docker-compose.prod.yml%20up%20-d%0A%0A4.%20Wait%20for%20all%20containers%20to%20be%20healthy%20(this%20may%20take%201-2%20minutes)%3A%0A%20%20%20docker%20compose%20-f%20docker-compose.prod.yml%20ps%0A%0A5.%20Verify%20the%20app%20is%20accessible%20at%20http%3A%2F%2Flocalhost%3A3000%0A%0AIf%20there%20are%20any%20errors%2C%20help%20me%20troubleshoot%20them.%20Common%20issues%3A%0A-%20Port%203000%2C%203002%2C%20or%205432%20already%20in%20use%0A-%20Docker%20not%20running%0A-%20Insufficient%20memory%20(needs%2012GB%2B%20RAM)%0A%0AFor%20local%20AI%20models%20with%20Ollama%2C%20use%20this%20instead%20of%20step%203%3A%0A%20%20%20docker%20compose%20-f%20docker-compose.ollama.yml%20--profile%20setup%20up%20-d"><img src="https://img.shields.io/badge/Set%20Up%20with-Cursor-000000?logo=cursor&logoColor=white" alt="Set Up with Cursor"></a>
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
### Build Workflows with Ease
|
### Build Workflows with Ease
|
||||||
|
|||||||
@@ -86,27 +86,112 @@ export async function GET(request: NextRequest) {
|
|||||||
)
|
)
|
||||||
.limit(candidateLimit)
|
.limit(candidateLimit)
|
||||||
|
|
||||||
const seenIds = new Set<string>()
|
const knownLocales = ['en', 'es', 'fr', 'de', 'ja', 'zh']
|
||||||
const mergedResults = []
|
|
||||||
|
|
||||||
for (let i = 0; i < Math.max(vectorResults.length, keywordResults.length); i++) {
|
const vectorRankMap = new Map<string, number>()
|
||||||
if (i < vectorResults.length && !seenIds.has(vectorResults[i].chunkId)) {
|
vectorResults.forEach((r, idx) => vectorRankMap.set(r.chunkId, idx + 1))
|
||||||
mergedResults.push(vectorResults[i])
|
|
||||||
seenIds.add(vectorResults[i].chunkId)
|
const keywordRankMap = new Map<string, number>()
|
||||||
}
|
keywordResults.forEach((r, idx) => keywordRankMap.set(r.chunkId, idx + 1))
|
||||||
if (i < keywordResults.length && !seenIds.has(keywordResults[i].chunkId)) {
|
|
||||||
mergedResults.push(keywordResults[i])
|
const allChunkIds = new Set([
|
||||||
seenIds.add(keywordResults[i].chunkId)
|
...vectorResults.map((r) => r.chunkId),
|
||||||
|
...keywordResults.map((r) => r.chunkId),
|
||||||
|
])
|
||||||
|
|
||||||
|
const k = 60
|
||||||
|
type ResultWithRRF = (typeof vectorResults)[0] & { rrfScore: number }
|
||||||
|
const scoredResults: ResultWithRRF[] = []
|
||||||
|
|
||||||
|
for (const chunkId of allChunkIds) {
|
||||||
|
const vectorRank = vectorRankMap.get(chunkId) ?? Number.POSITIVE_INFINITY
|
||||||
|
const keywordRank = keywordRankMap.get(chunkId) ?? Number.POSITIVE_INFINITY
|
||||||
|
|
||||||
|
const rrfScore = 1 / (k + vectorRank) + 1 / (k + keywordRank)
|
||||||
|
|
||||||
|
const result =
|
||||||
|
vectorResults.find((r) => r.chunkId === chunkId) ||
|
||||||
|
keywordResults.find((r) => r.chunkId === chunkId)
|
||||||
|
|
||||||
|
if (result) {
|
||||||
|
scoredResults.push({ ...result, rrfScore })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const filteredResults = mergedResults.slice(0, limit)
|
scoredResults.sort((a, b) => b.rrfScore - a.rrfScore)
|
||||||
const searchResults = filteredResults.map((result) => {
|
|
||||||
|
const localeFilteredResults = scoredResults.filter((result) => {
|
||||||
|
const firstPart = result.sourceDocument.split('/')[0]
|
||||||
|
if (knownLocales.includes(firstPart)) {
|
||||||
|
return firstPart === locale
|
||||||
|
}
|
||||||
|
return locale === 'en'
|
||||||
|
})
|
||||||
|
|
||||||
|
const queryLower = query.toLowerCase()
|
||||||
|
const getTitleBoost = (result: ResultWithRRF): number => {
|
||||||
|
const fileName = result.sourceDocument
|
||||||
|
.replace('.mdx', '')
|
||||||
|
.split('/')
|
||||||
|
.pop()
|
||||||
|
?.toLowerCase()
|
||||||
|
?.replace(/_/g, ' ')
|
||||||
|
|
||||||
|
if (fileName === queryLower) return 0.01
|
||||||
|
if (fileName?.includes(queryLower)) return 0.005
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
localeFilteredResults.sort((a, b) => {
|
||||||
|
return b.rrfScore + getTitleBoost(b) - (a.rrfScore + getTitleBoost(a))
|
||||||
|
})
|
||||||
|
|
||||||
|
const pageMap = new Map<string, ResultWithRRF>()
|
||||||
|
|
||||||
|
for (const result of localeFilteredResults) {
|
||||||
|
const pageKey = result.sourceDocument
|
||||||
|
const existing = pageMap.get(pageKey)
|
||||||
|
|
||||||
|
if (!existing || result.rrfScore > existing.rrfScore) {
|
||||||
|
pageMap.set(pageKey, result)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const deduplicatedResults = Array.from(pageMap.values())
|
||||||
|
.sort((a, b) => b.rrfScore + getTitleBoost(b) - (a.rrfScore + getTitleBoost(a)))
|
||||||
|
.slice(0, limit)
|
||||||
|
|
||||||
|
const searchResults = deduplicatedResults.map((result) => {
|
||||||
const title = result.headerText || result.sourceDocument.replace('.mdx', '')
|
const title = result.headerText || result.sourceDocument.replace('.mdx', '')
|
||||||
|
|
||||||
const pathParts = result.sourceDocument
|
const pathParts = result.sourceDocument
|
||||||
.replace('.mdx', '')
|
.replace('.mdx', '')
|
||||||
.split('/')
|
.split('/')
|
||||||
.map((part) => part.charAt(0).toUpperCase() + part.slice(1))
|
.filter((part) => part !== 'index' && !knownLocales.includes(part))
|
||||||
|
.map((part) => {
|
||||||
|
return part
|
||||||
|
.replace(/_/g, ' ')
|
||||||
|
.split(' ')
|
||||||
|
.map((word) => {
|
||||||
|
const acronyms = [
|
||||||
|
'api',
|
||||||
|
'mcp',
|
||||||
|
'sdk',
|
||||||
|
'url',
|
||||||
|
'http',
|
||||||
|
'json',
|
||||||
|
'xml',
|
||||||
|
'html',
|
||||||
|
'css',
|
||||||
|
'ai',
|
||||||
|
]
|
||||||
|
if (acronyms.includes(word.toLowerCase())) {
|
||||||
|
return word.toUpperCase()
|
||||||
|
}
|
||||||
|
return word.charAt(0).toUpperCase() + word.slice(1)
|
||||||
|
})
|
||||||
|
.join(' ')
|
||||||
|
})
|
||||||
|
|
||||||
return {
|
return {
|
||||||
id: result.chunkId,
|
id: result.chunkId,
|
||||||
|
|||||||
@@ -1739,12 +1739,12 @@ export function BrowserUseIcon(props: SVGProps<SVGSVGElement>) {
|
|||||||
{...props}
|
{...props}
|
||||||
version='1.0'
|
version='1.0'
|
||||||
xmlns='http://www.w3.org/2000/svg'
|
xmlns='http://www.w3.org/2000/svg'
|
||||||
width='150pt'
|
width='28'
|
||||||
height='150pt'
|
height='28'
|
||||||
viewBox='0 0 150 150'
|
viewBox='0 0 150 150'
|
||||||
preserveAspectRatio='xMidYMid meet'
|
preserveAspectRatio='xMidYMid meet'
|
||||||
>
|
>
|
||||||
<g transform='translate(0,150) scale(0.05,-0.05)' fill='#000000' stroke='none'>
|
<g transform='translate(0,150) scale(0.05,-0.05)' fill='currentColor' stroke='none'>
|
||||||
<path
|
<path
|
||||||
d='M786 2713 c-184 -61 -353 -217 -439 -405 -76 -165 -65 -539 19 -666
|
d='M786 2713 c-184 -61 -353 -217 -439 -405 -76 -165 -65 -539 19 -666
|
||||||
l57 -85 -48 -124 c-203 -517 -79 -930 346 -1155 159 -85 441 -71 585 28 l111
|
l57 -85 -48 -124 c-203 -517 -79 -930 346 -1155 159 -85 441 -71 585 28 l111
|
||||||
|
|||||||
@@ -1,3 +1,3 @@
|
|||||||
{
|
{
|
||||||
"pages": ["index", "basics", "api", "form", "logging", "costs"]
|
"pages": ["index", "basics", "api", "logging", "costs"]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import { BlockInfoCard } from "@/components/ui/block-info-card"
|
|||||||
|
|
||||||
<BlockInfoCard
|
<BlockInfoCard
|
||||||
type="browser_use"
|
type="browser_use"
|
||||||
color="#E0E0E0"
|
color="#181C1E"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
{/* MANUAL-CONTENT-START:intro */}
|
{/* MANUAL-CONTENT-START:intro */}
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -119,6 +119,145 @@ Get a specific event from Google Calendar. Returns API-aligned fields only.
|
|||||||
| `creator` | json | Event creator |
|
| `creator` | json | Event creator |
|
||||||
| `organizer` | json | Event organizer |
|
| `organizer` | json | Event organizer |
|
||||||
|
|
||||||
|
### `google_calendar_update`
|
||||||
|
|
||||||
|
Update an existing event in Google Calendar. Returns API-aligned fields only.
|
||||||
|
|
||||||
|
#### Input
|
||||||
|
|
||||||
|
| Parameter | Type | Required | Description |
|
||||||
|
| --------- | ---- | -------- | ----------- |
|
||||||
|
| `calendarId` | string | No | Calendar ID \(defaults to primary\) |
|
||||||
|
| `eventId` | string | Yes | Event ID to update |
|
||||||
|
| `summary` | string | No | New event title/summary |
|
||||||
|
| `description` | string | No | New event description |
|
||||||
|
| `location` | string | No | New event location |
|
||||||
|
| `startDateTime` | string | No | New start date and time. MUST include timezone offset \(e.g., 2025-06-03T10:00:00-08:00\) OR provide timeZone parameter |
|
||||||
|
| `endDateTime` | string | No | New end date and time. MUST include timezone offset \(e.g., 2025-06-03T11:00:00-08:00\) OR provide timeZone parameter |
|
||||||
|
| `timeZone` | string | No | Time zone \(e.g., America/Los_Angeles\). Required if datetime does not include offset. |
|
||||||
|
| `attendees` | array | No | Array of attendee email addresses \(replaces existing attendees\) |
|
||||||
|
| `sendUpdates` | string | No | How to send updates to attendees: all, externalOnly, or none |
|
||||||
|
|
||||||
|
#### Output
|
||||||
|
|
||||||
|
| Parameter | Type | Description |
|
||||||
|
| --------- | ---- | ----------- |
|
||||||
|
| `id` | string | Event ID |
|
||||||
|
| `htmlLink` | string | Event link |
|
||||||
|
| `status` | string | Event status |
|
||||||
|
| `summary` | string | Event title |
|
||||||
|
| `description` | string | Event description |
|
||||||
|
| `location` | string | Event location |
|
||||||
|
| `start` | json | Event start |
|
||||||
|
| `end` | json | Event end |
|
||||||
|
| `attendees` | json | Event attendees |
|
||||||
|
| `creator` | json | Event creator |
|
||||||
|
| `organizer` | json | Event organizer |
|
||||||
|
|
||||||
|
### `google_calendar_delete`
|
||||||
|
|
||||||
|
Delete an event from Google Calendar. Returns API-aligned fields only.
|
||||||
|
|
||||||
|
#### Input
|
||||||
|
|
||||||
|
| Parameter | Type | Required | Description |
|
||||||
|
| --------- | ---- | -------- | ----------- |
|
||||||
|
| `calendarId` | string | No | Calendar ID \(defaults to primary\) |
|
||||||
|
| `eventId` | string | Yes | Event ID to delete |
|
||||||
|
| `sendUpdates` | string | No | How to send updates to attendees: all, externalOnly, or none |
|
||||||
|
|
||||||
|
#### Output
|
||||||
|
|
||||||
|
| Parameter | Type | Description |
|
||||||
|
| --------- | ---- | ----------- |
|
||||||
|
| `eventId` | string | Deleted event ID |
|
||||||
|
| `deleted` | boolean | Whether deletion was successful |
|
||||||
|
|
||||||
|
### `google_calendar_move`
|
||||||
|
|
||||||
|
Move an event to a different calendar. Returns API-aligned fields only.
|
||||||
|
|
||||||
|
#### Input
|
||||||
|
|
||||||
|
| Parameter | Type | Required | Description |
|
||||||
|
| --------- | ---- | -------- | ----------- |
|
||||||
|
| `calendarId` | string | No | Source calendar ID \(defaults to primary\) |
|
||||||
|
| `eventId` | string | Yes | Event ID to move |
|
||||||
|
| `destinationCalendarId` | string | Yes | Destination calendar ID |
|
||||||
|
| `sendUpdates` | string | No | How to send updates to attendees: all, externalOnly, or none |
|
||||||
|
|
||||||
|
#### Output
|
||||||
|
|
||||||
|
| Parameter | Type | Description |
|
||||||
|
| --------- | ---- | ----------- |
|
||||||
|
| `id` | string | Event ID |
|
||||||
|
| `htmlLink` | string | Event link |
|
||||||
|
| `status` | string | Event status |
|
||||||
|
| `summary` | string | Event title |
|
||||||
|
| `description` | string | Event description |
|
||||||
|
| `location` | string | Event location |
|
||||||
|
| `start` | json | Event start |
|
||||||
|
| `end` | json | Event end |
|
||||||
|
| `attendees` | json | Event attendees |
|
||||||
|
| `creator` | json | Event creator |
|
||||||
|
| `organizer` | json | Event organizer |
|
||||||
|
|
||||||
|
### `google_calendar_instances`
|
||||||
|
|
||||||
|
Get instances of a recurring event from Google Calendar. Returns API-aligned fields only.
|
||||||
|
|
||||||
|
#### Input
|
||||||
|
|
||||||
|
| Parameter | Type | Required | Description |
|
||||||
|
| --------- | ---- | -------- | ----------- |
|
||||||
|
| `calendarId` | string | No | Calendar ID \(defaults to primary\) |
|
||||||
|
| `eventId` | string | Yes | Recurring event ID to get instances of |
|
||||||
|
| `timeMin` | string | No | Lower bound for instances \(RFC3339 timestamp, e.g., 2025-06-03T00:00:00Z\) |
|
||||||
|
| `timeMax` | string | No | Upper bound for instances \(RFC3339 timestamp, e.g., 2025-06-04T00:00:00Z\) |
|
||||||
|
| `maxResults` | number | No | Maximum number of instances to return \(default 250, max 2500\) |
|
||||||
|
| `pageToken` | string | No | Token for retrieving subsequent pages of results |
|
||||||
|
| `showDeleted` | boolean | No | Include deleted instances |
|
||||||
|
|
||||||
|
#### Output
|
||||||
|
|
||||||
|
| Parameter | Type | Description |
|
||||||
|
| --------- | ---- | ----------- |
|
||||||
|
| `nextPageToken` | string | Next page token |
|
||||||
|
| `timeZone` | string | Calendar time zone |
|
||||||
|
| `instances` | json | List of recurring event instances |
|
||||||
|
|
||||||
|
### `google_calendar_list_calendars`
|
||||||
|
|
||||||
|
List all calendars in the user
|
||||||
|
|
||||||
|
#### Input
|
||||||
|
|
||||||
|
| Parameter | Type | Required | Description |
|
||||||
|
| --------- | ---- | -------- | ----------- |
|
||||||
|
| `minAccessRole` | string | No | Minimum access role for returned calendars: freeBusyReader, reader, writer, or owner |
|
||||||
|
| `maxResults` | number | No | Maximum number of calendars to return \(default 100, max 250\) |
|
||||||
|
| `pageToken` | string | No | Token for retrieving subsequent pages of results |
|
||||||
|
| `showDeleted` | boolean | No | Include deleted calendars |
|
||||||
|
| `showHidden` | boolean | No | Include hidden calendars |
|
||||||
|
|
||||||
|
#### Output
|
||||||
|
|
||||||
|
| Parameter | Type | Description |
|
||||||
|
| --------- | ---- | ----------- |
|
||||||
|
| `nextPageToken` | string | Next page token |
|
||||||
|
| `calendars` | array | List of calendars |
|
||||||
|
| ↳ `id` | string | Calendar ID |
|
||||||
|
| ↳ `summary` | string | Calendar title |
|
||||||
|
| ↳ `description` | string | Calendar description |
|
||||||
|
| ↳ `location` | string | Calendar location |
|
||||||
|
| ↳ `timeZone` | string | Calendar time zone |
|
||||||
|
| ↳ `accessRole` | string | Access role for the calendar |
|
||||||
|
| ↳ `backgroundColor` | string | Calendar background color |
|
||||||
|
| ↳ `foregroundColor` | string | Calendar foreground color |
|
||||||
|
| ↳ `primary` | boolean | Whether this is the primary calendar |
|
||||||
|
| ↳ `hidden` | boolean | Whether the calendar is hidden |
|
||||||
|
| ↳ `selected` | boolean | Whether the calendar is selected |
|
||||||
|
|
||||||
### `google_calendar_quick_add`
|
### `google_calendar_quick_add`
|
||||||
|
|
||||||
Create events from natural language text. Returns API-aligned fields only.
|
Create events from natural language text. Returns API-aligned fields only.
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
---
|
---
|
||||||
title: Google Drive
|
title: Google Drive
|
||||||
description: Create, upload, and list files
|
description: Manage files, folders, and permissions
|
||||||
---
|
---
|
||||||
|
|
||||||
import { BlockInfoCard } from "@/components/ui/block-info-card"
|
import { BlockInfoCard } from "@/components/ui/block-info-card"
|
||||||
@@ -40,217 +40,12 @@ In Sim, the Google Drive integration enables your agents to interact directly wi
|
|||||||
|
|
||||||
## Usage Instructions
|
## Usage Instructions
|
||||||
|
|
||||||
Integrate Google Drive into the workflow. Can create, upload, and list files.
|
Integrate Google Drive into the workflow. Can create, upload, download, copy, move, delete, share files and manage permissions.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
## Tools
|
## Tools
|
||||||
|
|
||||||
### `google_drive_upload`
|
|
||||||
|
|
||||||
Upload a file to Google Drive with complete metadata returned
|
|
||||||
|
|
||||||
#### Input
|
|
||||||
|
|
||||||
| Parameter | Type | Required | Description |
|
|
||||||
| --------- | ---- | -------- | ----------- |
|
|
||||||
| `fileName` | string | Yes | The name of the file to upload |
|
|
||||||
| `file` | file | No | Binary file to upload \(UserFile object\) |
|
|
||||||
| `content` | string | No | Text content to upload \(use this OR file, not both\) |
|
|
||||||
| `mimeType` | string | No | The MIME type of the file to upload \(auto-detected from file if not provided\) |
|
|
||||||
| `folderSelector` | string | No | Select the folder to upload the file to |
|
|
||||||
| `folderId` | string | No | The ID of the folder to upload the file to \(internal use\) |
|
|
||||||
|
|
||||||
#### Output
|
|
||||||
|
|
||||||
| Parameter | Type | Description |
|
|
||||||
| --------- | ---- | ----------- |
|
|
||||||
| `file` | object | Complete uploaded file metadata from Google Drive |
|
|
||||||
| ↳ `id` | string | Google Drive file ID |
|
|
||||||
| ↳ `name` | string | File name |
|
|
||||||
| ↳ `mimeType` | string | MIME type |
|
|
||||||
| ↳ `kind` | string | Resource type identifier |
|
|
||||||
| ↳ `description` | string | File description |
|
|
||||||
| ↳ `originalFilename` | string | Original uploaded filename |
|
|
||||||
| ↳ `fullFileExtension` | string | Full file extension |
|
|
||||||
| ↳ `fileExtension` | string | File extension |
|
|
||||||
| ↳ `owners` | json | List of file owners |
|
|
||||||
| ↳ `permissions` | json | File permissions |
|
|
||||||
| ↳ `permissionIds` | json | Permission IDs |
|
|
||||||
| ↳ `shared` | boolean | Whether file is shared |
|
|
||||||
| ↳ `ownedByMe` | boolean | Whether owned by current user |
|
|
||||||
| ↳ `writersCanShare` | boolean | Whether writers can share |
|
|
||||||
| ↳ `viewersCanCopyContent` | boolean | Whether viewers can copy |
|
|
||||||
| ↳ `copyRequiresWriterPermission` | boolean | Whether copy requires writer permission |
|
|
||||||
| ↳ `sharingUser` | json | User who shared the file |
|
|
||||||
| ↳ `starred` | boolean | Whether file is starred |
|
|
||||||
| ↳ `trashed` | boolean | Whether file is in trash |
|
|
||||||
| ↳ `explicitlyTrashed` | boolean | Whether explicitly trashed |
|
|
||||||
| ↳ `appProperties` | json | App-specific properties |
|
|
||||||
| ↳ `createdTime` | string | File creation time |
|
|
||||||
| ↳ `modifiedTime` | string | Last modification time |
|
|
||||||
| ↳ `modifiedByMeTime` | string | When modified by current user |
|
|
||||||
| ↳ `viewedByMeTime` | string | When last viewed by current user |
|
|
||||||
| ↳ `sharedWithMeTime` | string | When shared with current user |
|
|
||||||
| ↳ `lastModifyingUser` | json | User who last modified the file |
|
|
||||||
| ↳ `viewedByMe` | boolean | Whether viewed by current user |
|
|
||||||
| ↳ `modifiedByMe` | boolean | Whether modified by current user |
|
|
||||||
| ↳ `webViewLink` | string | URL to view in browser |
|
|
||||||
| ↳ `webContentLink` | string | Direct download URL |
|
|
||||||
| ↳ `iconLink` | string | URL to file icon |
|
|
||||||
| ↳ `thumbnailLink` | string | URL to thumbnail |
|
|
||||||
| ↳ `exportLinks` | json | Export format links |
|
|
||||||
| ↳ `size` | string | File size in bytes |
|
|
||||||
| ↳ `quotaBytesUsed` | string | Storage quota used |
|
|
||||||
| ↳ `md5Checksum` | string | MD5 hash |
|
|
||||||
| ↳ `sha1Checksum` | string | SHA-1 hash |
|
|
||||||
| ↳ `sha256Checksum` | string | SHA-256 hash |
|
|
||||||
| ↳ `parents` | json | Parent folder IDs |
|
|
||||||
| ↳ `spaces` | json | Spaces containing file |
|
|
||||||
| ↳ `driveId` | string | Shared drive ID |
|
|
||||||
| ↳ `capabilities` | json | User capabilities on file |
|
|
||||||
| ↳ `version` | string | Version number |
|
|
||||||
| ↳ `headRevisionId` | string | Head revision ID |
|
|
||||||
| ↳ `hasThumbnail` | boolean | Whether has thumbnail |
|
|
||||||
| ↳ `thumbnailVersion` | string | Thumbnail version |
|
|
||||||
| ↳ `imageMediaMetadata` | json | Image-specific metadata |
|
|
||||||
| ↳ `videoMediaMetadata` | json | Video-specific metadata |
|
|
||||||
| ↳ `isAppAuthorized` | boolean | Whether created by requesting app |
|
|
||||||
| ↳ `contentRestrictions` | json | Content restrictions |
|
|
||||||
| ↳ `linkShareMetadata` | json | Link share metadata |
|
|
||||||
|
|
||||||
### `google_drive_create_folder`
|
|
||||||
|
|
||||||
Create a new folder in Google Drive with complete metadata returned
|
|
||||||
|
|
||||||
#### Input
|
|
||||||
|
|
||||||
| Parameter | Type | Required | Description |
|
|
||||||
| --------- | ---- | -------- | ----------- |
|
|
||||||
| `fileName` | string | Yes | Name of the folder to create |
|
|
||||||
| `folderSelector` | string | No | Select the parent folder to create the folder in |
|
|
||||||
| `folderId` | string | No | ID of the parent folder \(internal use\) |
|
|
||||||
|
|
||||||
#### Output
|
|
||||||
|
|
||||||
| Parameter | Type | Description |
|
|
||||||
| --------- | ---- | ----------- |
|
|
||||||
| `file` | object | Complete created folder metadata from Google Drive |
|
|
||||||
| ↳ `id` | string | Google Drive folder ID |
|
|
||||||
| ↳ `name` | string | Folder name |
|
|
||||||
| ↳ `mimeType` | string | MIME type \(application/vnd.google-apps.folder\) |
|
|
||||||
| ↳ `kind` | string | Resource type identifier |
|
|
||||||
| ↳ `description` | string | Folder description |
|
|
||||||
| ↳ `owners` | json | List of folder owners |
|
|
||||||
| ↳ `permissions` | json | Folder permissions |
|
|
||||||
| ↳ `permissionIds` | json | Permission IDs |
|
|
||||||
| ↳ `shared` | boolean | Whether folder is shared |
|
|
||||||
| ↳ `ownedByMe` | boolean | Whether owned by current user |
|
|
||||||
| ↳ `writersCanShare` | boolean | Whether writers can share |
|
|
||||||
| ↳ `viewersCanCopyContent` | boolean | Whether viewers can copy |
|
|
||||||
| ↳ `copyRequiresWriterPermission` | boolean | Whether copy requires writer permission |
|
|
||||||
| ↳ `sharingUser` | json | User who shared the folder |
|
|
||||||
| ↳ `starred` | boolean | Whether folder is starred |
|
|
||||||
| ↳ `trashed` | boolean | Whether folder is in trash |
|
|
||||||
| ↳ `explicitlyTrashed` | boolean | Whether explicitly trashed |
|
|
||||||
| ↳ `appProperties` | json | App-specific properties |
|
|
||||||
| ↳ `folderColorRgb` | string | Folder color |
|
|
||||||
| ↳ `createdTime` | string | Folder creation time |
|
|
||||||
| ↳ `modifiedTime` | string | Last modification time |
|
|
||||||
| ↳ `modifiedByMeTime` | string | When modified by current user |
|
|
||||||
| ↳ `viewedByMeTime` | string | When last viewed by current user |
|
|
||||||
| ↳ `sharedWithMeTime` | string | When shared with current user |
|
|
||||||
| ↳ `lastModifyingUser` | json | User who last modified the folder |
|
|
||||||
| ↳ `viewedByMe` | boolean | Whether viewed by current user |
|
|
||||||
| ↳ `modifiedByMe` | boolean | Whether modified by current user |
|
|
||||||
| ↳ `webViewLink` | string | URL to view in browser |
|
|
||||||
| ↳ `iconLink` | string | URL to folder icon |
|
|
||||||
| ↳ `parents` | json | Parent folder IDs |
|
|
||||||
| ↳ `spaces` | json | Spaces containing folder |
|
|
||||||
| ↳ `driveId` | string | Shared drive ID |
|
|
||||||
| ↳ `capabilities` | json | User capabilities on folder |
|
|
||||||
| ↳ `version` | string | Version number |
|
|
||||||
| ↳ `isAppAuthorized` | boolean | Whether created by requesting app |
|
|
||||||
| ↳ `contentRestrictions` | json | Content restrictions |
|
|
||||||
| ↳ `linkShareMetadata` | json | Link share metadata |
|
|
||||||
|
|
||||||
### `google_drive_download`
|
|
||||||
|
|
||||||
Download a file from Google Drive with complete metadata (exports Google Workspace files automatically)
|
|
||||||
|
|
||||||
#### Input
|
|
||||||
|
|
||||||
| Parameter | Type | Required | Description |
|
|
||||||
| --------- | ---- | -------- | ----------- |
|
|
||||||
| `fileId` | string | Yes | The ID of the file to download |
|
|
||||||
| `mimeType` | string | No | The MIME type to export Google Workspace files to \(optional\) |
|
|
||||||
| `fileName` | string | No | Optional filename override |
|
|
||||||
| `includeRevisions` | boolean | No | Whether to include revision history in the metadata \(default: true, returns first 100 revisions\) |
|
|
||||||
|
|
||||||
#### Output
|
|
||||||
|
|
||||||
| Parameter | Type | Description |
|
|
||||||
| --------- | ---- | ----------- |
|
|
||||||
| `file` | object | Downloaded file data |
|
|
||||||
| ↳ `name` | string | File name |
|
|
||||||
| ↳ `mimeType` | string | MIME type of the file |
|
|
||||||
| ↳ `data` | string | File content as base64-encoded string |
|
|
||||||
| ↳ `size` | number | File size in bytes |
|
|
||||||
| `metadata` | object | Complete file metadata from Google Drive |
|
|
||||||
| ↳ `id` | string | Google Drive file ID |
|
|
||||||
| ↳ `name` | string | File name |
|
|
||||||
| ↳ `mimeType` | string | MIME type |
|
|
||||||
| ↳ `kind` | string | Resource type identifier |
|
|
||||||
| ↳ `description` | string | File description |
|
|
||||||
| ↳ `originalFilename` | string | Original uploaded filename |
|
|
||||||
| ↳ `fullFileExtension` | string | Full file extension |
|
|
||||||
| ↳ `fileExtension` | string | File extension |
|
|
||||||
| ↳ `owners` | json | List of file owners |
|
|
||||||
| ↳ `permissions` | json | File permissions |
|
|
||||||
| ↳ `permissionIds` | json | Permission IDs |
|
|
||||||
| ↳ `shared` | boolean | Whether file is shared |
|
|
||||||
| ↳ `ownedByMe` | boolean | Whether owned by current user |
|
|
||||||
| ↳ `writersCanShare` | boolean | Whether writers can share |
|
|
||||||
| ↳ `viewersCanCopyContent` | boolean | Whether viewers can copy |
|
|
||||||
| ↳ `copyRequiresWriterPermission` | boolean | Whether copy requires writer permission |
|
|
||||||
| ↳ `sharingUser` | json | User who shared the file |
|
|
||||||
| ↳ `starred` | boolean | Whether file is starred |
|
|
||||||
| ↳ `trashed` | boolean | Whether file is in trash |
|
|
||||||
| ↳ `explicitlyTrashed` | boolean | Whether explicitly trashed |
|
|
||||||
| ↳ `appProperties` | json | App-specific properties |
|
|
||||||
| ↳ `createdTime` | string | File creation time |
|
|
||||||
| ↳ `modifiedTime` | string | Last modification time |
|
|
||||||
| ↳ `modifiedByMeTime` | string | When modified by current user |
|
|
||||||
| ↳ `viewedByMeTime` | string | When last viewed by current user |
|
|
||||||
| ↳ `sharedWithMeTime` | string | When shared with current user |
|
|
||||||
| ↳ `lastModifyingUser` | json | User who last modified the file |
|
|
||||||
| ↳ `viewedByMe` | boolean | Whether viewed by current user |
|
|
||||||
| ↳ `modifiedByMe` | boolean | Whether modified by current user |
|
|
||||||
| ↳ `webViewLink` | string | URL to view in browser |
|
|
||||||
| ↳ `webContentLink` | string | Direct download URL |
|
|
||||||
| ↳ `iconLink` | string | URL to file icon |
|
|
||||||
| ↳ `thumbnailLink` | string | URL to thumbnail |
|
|
||||||
| ↳ `exportLinks` | json | Export format links |
|
|
||||||
| ↳ `size` | string | File size in bytes |
|
|
||||||
| ↳ `quotaBytesUsed` | string | Storage quota used |
|
|
||||||
| ↳ `md5Checksum` | string | MD5 hash |
|
|
||||||
| ↳ `sha1Checksum` | string | SHA-1 hash |
|
|
||||||
| ↳ `sha256Checksum` | string | SHA-256 hash |
|
|
||||||
| ↳ `parents` | json | Parent folder IDs |
|
|
||||||
| ↳ `spaces` | json | Spaces containing file |
|
|
||||||
| ↳ `driveId` | string | Shared drive ID |
|
|
||||||
| ↳ `capabilities` | json | User capabilities on file |
|
|
||||||
| ↳ `version` | string | Version number |
|
|
||||||
| ↳ `headRevisionId` | string | Head revision ID |
|
|
||||||
| ↳ `hasThumbnail` | boolean | Whether has thumbnail |
|
|
||||||
| ↳ `thumbnailVersion` | string | Thumbnail version |
|
|
||||||
| ↳ `imageMediaMetadata` | json | Image-specific metadata |
|
|
||||||
| ↳ `videoMediaMetadata` | json | Video-specific metadata |
|
|
||||||
| ↳ `isAppAuthorized` | boolean | Whether created by requesting app |
|
|
||||||
| ↳ `contentRestrictions` | json | Content restrictions |
|
|
||||||
| ↳ `linkShareMetadata` | json | Link share metadata |
|
|
||||||
| ↳ `revisions` | json | File revision history \(first 100 revisions only\) |
|
|
||||||
|
|
||||||
### `google_drive_list`
|
### `google_drive_list`
|
||||||
|
|
||||||
List files and folders in Google Drive with complete metadata
|
List files and folders in Google Drive with complete metadata
|
||||||
@@ -271,9 +66,9 @@ List files and folders in Google Drive with complete metadata
|
|||||||
| --------- | ---- | ----------- |
|
| --------- | ---- | ----------- |
|
||||||
| `files` | array | Array of file metadata objects from Google Drive |
|
| `files` | array | Array of file metadata objects from Google Drive |
|
||||||
| ↳ `id` | string | Google Drive file ID |
|
| ↳ `id` | string | Google Drive file ID |
|
||||||
|
| ↳ `kind` | string | Resource type identifier |
|
||||||
| ↳ `name` | string | File name |
|
| ↳ `name` | string | File name |
|
||||||
| ↳ `mimeType` | string | MIME type |
|
| ↳ `mimeType` | string | MIME type |
|
||||||
| ↳ `kind` | string | Resource type identifier |
|
|
||||||
| ↳ `description` | string | File description |
|
| ↳ `description` | string | File description |
|
||||||
| ↳ `originalFilename` | string | Original uploaded filename |
|
| ↳ `originalFilename` | string | Original uploaded filename |
|
||||||
| ↳ `fullFileExtension` | string | Full file extension |
|
| ↳ `fullFileExtension` | string | Full file extension |
|
||||||
@@ -324,4 +119,455 @@ List files and folders in Google Drive with complete metadata
|
|||||||
| ↳ `linkShareMetadata` | json | Link share metadata |
|
| ↳ `linkShareMetadata` | json | Link share metadata |
|
||||||
| `nextPageToken` | string | Token for fetching the next page of results |
|
| `nextPageToken` | string | Token for fetching the next page of results |
|
||||||
|
|
||||||
|
### `google_drive_get_file`
|
||||||
|
|
||||||
|
Get metadata for a specific file in Google Drive by its ID
|
||||||
|
|
||||||
|
#### Input
|
||||||
|
|
||||||
|
| Parameter | Type | Required | Description |
|
||||||
|
| --------- | ---- | -------- | ----------- |
|
||||||
|
| `fileId` | string | Yes | The ID of the file to retrieve |
|
||||||
|
|
||||||
|
#### Output
|
||||||
|
|
||||||
|
| Parameter | Type | Description |
|
||||||
|
| --------- | ---- | ----------- |
|
||||||
|
| `file` | json | The file metadata |
|
||||||
|
| ↳ `id` | string | Google Drive file ID |
|
||||||
|
| ↳ `kind` | string | Resource type identifier |
|
||||||
|
| ↳ `name` | string | File name |
|
||||||
|
| ↳ `mimeType` | string | MIME type |
|
||||||
|
| ↳ `description` | string | File description |
|
||||||
|
| ↳ `size` | string | File size in bytes |
|
||||||
|
| ↳ `starred` | boolean | Whether file is starred |
|
||||||
|
| ↳ `trashed` | boolean | Whether file is in trash |
|
||||||
|
| ↳ `webViewLink` | string | URL to view in browser |
|
||||||
|
| ↳ `webContentLink` | string | Direct download URL |
|
||||||
|
| ↳ `iconLink` | string | URL to file icon |
|
||||||
|
| ↳ `thumbnailLink` | string | URL to thumbnail |
|
||||||
|
| ↳ `parents` | json | Parent folder IDs |
|
||||||
|
| ↳ `owners` | json | List of file owners |
|
||||||
|
| ↳ `permissions` | json | File permissions |
|
||||||
|
| ↳ `createdTime` | string | File creation time |
|
||||||
|
| ↳ `modifiedTime` | string | Last modification time |
|
||||||
|
| ↳ `lastModifyingUser` | json | User who last modified the file |
|
||||||
|
| ↳ `shared` | boolean | Whether file is shared |
|
||||||
|
| ↳ `ownedByMe` | boolean | Whether owned by current user |
|
||||||
|
| ↳ `capabilities` | json | User capabilities on file |
|
||||||
|
| ↳ `md5Checksum` | string | MD5 hash |
|
||||||
|
| ↳ `version` | string | Version number |
|
||||||
|
|
||||||
|
### `google_drive_create_folder`
|
||||||
|
|
||||||
|
Create a new folder in Google Drive with complete metadata returned
|
||||||
|
|
||||||
|
#### Input
|
||||||
|
|
||||||
|
| Parameter | Type | Required | Description |
|
||||||
|
| --------- | ---- | -------- | ----------- |
|
||||||
|
| `fileName` | string | Yes | Name of the folder to create |
|
||||||
|
| `folderSelector` | string | No | Select the parent folder to create the folder in |
|
||||||
|
| `folderId` | string | No | ID of the parent folder \(internal use\) |
|
||||||
|
|
||||||
|
#### Output
|
||||||
|
|
||||||
|
| Parameter | Type | Description |
|
||||||
|
| --------- | ---- | ----------- |
|
||||||
|
| `file` | object | Complete created folder metadata from Google Drive |
|
||||||
|
| ↳ `id` | string | Google Drive folder ID |
|
||||||
|
| ↳ `kind` | string | Resource type identifier |
|
||||||
|
| ↳ `name` | string | Folder name |
|
||||||
|
| ↳ `mimeType` | string | MIME type \(application/vnd.google-apps.folder\) |
|
||||||
|
| ↳ `description` | string | Folder description |
|
||||||
|
| ↳ `owners` | json | List of folder owners |
|
||||||
|
| ↳ `permissions` | json | Folder permissions |
|
||||||
|
| ↳ `permissionIds` | json | Permission IDs |
|
||||||
|
| ↳ `shared` | boolean | Whether folder is shared |
|
||||||
|
| ↳ `ownedByMe` | boolean | Whether owned by current user |
|
||||||
|
| ↳ `writersCanShare` | boolean | Whether writers can share |
|
||||||
|
| ↳ `viewersCanCopyContent` | boolean | Whether viewers can copy |
|
||||||
|
| ↳ `copyRequiresWriterPermission` | boolean | Whether copy requires writer permission |
|
||||||
|
| ↳ `sharingUser` | json | User who shared the folder |
|
||||||
|
| ↳ `starred` | boolean | Whether folder is starred |
|
||||||
|
| ↳ `trashed` | boolean | Whether folder is in trash |
|
||||||
|
| ↳ `explicitlyTrashed` | boolean | Whether explicitly trashed |
|
||||||
|
| ↳ `appProperties` | json | App-specific properties |
|
||||||
|
| ↳ `folderColorRgb` | string | Folder color |
|
||||||
|
| ↳ `createdTime` | string | Folder creation time |
|
||||||
|
| ↳ `modifiedTime` | string | Last modification time |
|
||||||
|
| ↳ `modifiedByMeTime` | string | When modified by current user |
|
||||||
|
| ↳ `viewedByMeTime` | string | When last viewed by current user |
|
||||||
|
| ↳ `sharedWithMeTime` | string | When shared with current user |
|
||||||
|
| ↳ `lastModifyingUser` | json | User who last modified the folder |
|
||||||
|
| ↳ `viewedByMe` | boolean | Whether viewed by current user |
|
||||||
|
| ↳ `modifiedByMe` | boolean | Whether modified by current user |
|
||||||
|
| ↳ `webViewLink` | string | URL to view in browser |
|
||||||
|
| ↳ `iconLink` | string | URL to folder icon |
|
||||||
|
| ↳ `parents` | json | Parent folder IDs |
|
||||||
|
| ↳ `spaces` | json | Spaces containing folder |
|
||||||
|
| ↳ `driveId` | string | Shared drive ID |
|
||||||
|
| ↳ `capabilities` | json | User capabilities on folder |
|
||||||
|
| ↳ `version` | string | Version number |
|
||||||
|
| ↳ `isAppAuthorized` | boolean | Whether created by requesting app |
|
||||||
|
| ↳ `contentRestrictions` | json | Content restrictions |
|
||||||
|
| ↳ `linkShareMetadata` | json | Link share metadata |
|
||||||
|
|
||||||
|
### `google_drive_upload`
|
||||||
|
|
||||||
|
Upload a file to Google Drive with complete metadata returned
|
||||||
|
|
||||||
|
#### Input
|
||||||
|
|
||||||
|
| Parameter | Type | Required | Description |
|
||||||
|
| --------- | ---- | -------- | ----------- |
|
||||||
|
| `fileName` | string | Yes | The name of the file to upload |
|
||||||
|
| `file` | file | No | Binary file to upload \(UserFile object\) |
|
||||||
|
| `content` | string | No | Text content to upload \(use this OR file, not both\) |
|
||||||
|
| `mimeType` | string | No | The MIME type of the file to upload \(auto-detected from file if not provided\) |
|
||||||
|
| `folderSelector` | string | No | Select the folder to upload the file to |
|
||||||
|
| `folderId` | string | No | The ID of the folder to upload the file to \(internal use\) |
|
||||||
|
|
||||||
|
#### Output
|
||||||
|
|
||||||
|
| Parameter | Type | Description |
|
||||||
|
| --------- | ---- | ----------- |
|
||||||
|
| `file` | object | Complete uploaded file metadata from Google Drive |
|
||||||
|
| ↳ `id` | string | Google Drive file ID |
|
||||||
|
| ↳ `kind` | string | Resource type identifier |
|
||||||
|
| ↳ `name` | string | File name |
|
||||||
|
| ↳ `mimeType` | string | MIME type |
|
||||||
|
| ↳ `description` | string | File description |
|
||||||
|
| ↳ `originalFilename` | string | Original uploaded filename |
|
||||||
|
| ↳ `fullFileExtension` | string | Full file extension |
|
||||||
|
| ↳ `fileExtension` | string | File extension |
|
||||||
|
| ↳ `owners` | json | List of file owners |
|
||||||
|
| ↳ `permissions` | json | File permissions |
|
||||||
|
| ↳ `permissionIds` | json | Permission IDs |
|
||||||
|
| ↳ `shared` | boolean | Whether file is shared |
|
||||||
|
| ↳ `ownedByMe` | boolean | Whether owned by current user |
|
||||||
|
| ↳ `writersCanShare` | boolean | Whether writers can share |
|
||||||
|
| ↳ `viewersCanCopyContent` | boolean | Whether viewers can copy |
|
||||||
|
| ↳ `copyRequiresWriterPermission` | boolean | Whether copy requires writer permission |
|
||||||
|
| ↳ `sharingUser` | json | User who shared the file |
|
||||||
|
| ↳ `starred` | boolean | Whether file is starred |
|
||||||
|
| ↳ `trashed` | boolean | Whether file is in trash |
|
||||||
|
| ↳ `explicitlyTrashed` | boolean | Whether explicitly trashed |
|
||||||
|
| ↳ `appProperties` | json | App-specific properties |
|
||||||
|
| ↳ `createdTime` | string | File creation time |
|
||||||
|
| ↳ `modifiedTime` | string | Last modification time |
|
||||||
|
| ↳ `modifiedByMeTime` | string | When modified by current user |
|
||||||
|
| ↳ `viewedByMeTime` | string | When last viewed by current user |
|
||||||
|
| ↳ `sharedWithMeTime` | string | When shared with current user |
|
||||||
|
| ↳ `lastModifyingUser` | json | User who last modified the file |
|
||||||
|
| ↳ `viewedByMe` | boolean | Whether viewed by current user |
|
||||||
|
| ↳ `modifiedByMe` | boolean | Whether modified by current user |
|
||||||
|
| ↳ `webViewLink` | string | URL to view in browser |
|
||||||
|
| ↳ `webContentLink` | string | Direct download URL |
|
||||||
|
| ↳ `iconLink` | string | URL to file icon |
|
||||||
|
| ↳ `thumbnailLink` | string | URL to thumbnail |
|
||||||
|
| ↳ `exportLinks` | json | Export format links |
|
||||||
|
| ↳ `size` | string | File size in bytes |
|
||||||
|
| ↳ `quotaBytesUsed` | string | Storage quota used |
|
||||||
|
| ↳ `md5Checksum` | string | MD5 hash |
|
||||||
|
| ↳ `sha1Checksum` | string | SHA-1 hash |
|
||||||
|
| ↳ `sha256Checksum` | string | SHA-256 hash |
|
||||||
|
| ↳ `parents` | json | Parent folder IDs |
|
||||||
|
| ↳ `spaces` | json | Spaces containing file |
|
||||||
|
| ↳ `driveId` | string | Shared drive ID |
|
||||||
|
| ↳ `capabilities` | json | User capabilities on file |
|
||||||
|
| ↳ `version` | string | Version number |
|
||||||
|
| ↳ `headRevisionId` | string | Head revision ID |
|
||||||
|
| ↳ `hasThumbnail` | boolean | Whether has thumbnail |
|
||||||
|
| ↳ `thumbnailVersion` | string | Thumbnail version |
|
||||||
|
| ↳ `imageMediaMetadata` | json | Image-specific metadata |
|
||||||
|
| ↳ `videoMediaMetadata` | json | Video-specific metadata |
|
||||||
|
| ↳ `isAppAuthorized` | boolean | Whether created by requesting app |
|
||||||
|
| ↳ `contentRestrictions` | json | Content restrictions |
|
||||||
|
| ↳ `linkShareMetadata` | json | Link share metadata |
|
||||||
|
|
||||||
|
### `google_drive_download`
|
||||||
|
|
||||||
|
Download a file from Google Drive with complete metadata (exports Google Workspace files automatically)
|
||||||
|
|
||||||
|
#### Input
|
||||||
|
|
||||||
|
| Parameter | Type | Required | Description |
|
||||||
|
| --------- | ---- | -------- | ----------- |
|
||||||
|
| `fileId` | string | Yes | The ID of the file to download |
|
||||||
|
| `mimeType` | string | No | The MIME type to export Google Workspace files to \(optional\) |
|
||||||
|
| `fileName` | string | No | Optional filename override |
|
||||||
|
| `includeRevisions` | boolean | No | Whether to include revision history in the metadata \(default: true, returns first 100 revisions\) |
|
||||||
|
|
||||||
|
#### Output
|
||||||
|
|
||||||
|
| Parameter | Type | Description |
|
||||||
|
| --------- | ---- | ----------- |
|
||||||
|
| `file` | object | Downloaded file data |
|
||||||
|
| ↳ `name` | string | File name |
|
||||||
|
| ↳ `mimeType` | string | MIME type of the file |
|
||||||
|
| ↳ `data` | string | File content as base64-encoded string |
|
||||||
|
| ↳ `size` | number | File size in bytes |
|
||||||
|
| `metadata` | object | Complete file metadata from Google Drive |
|
||||||
|
| ↳ `id` | string | Google Drive file ID |
|
||||||
|
| ↳ `kind` | string | Resource type identifier |
|
||||||
|
| ↳ `name` | string | File name |
|
||||||
|
| ↳ `mimeType` | string | MIME type |
|
||||||
|
| ↳ `description` | string | File description |
|
||||||
|
| ↳ `originalFilename` | string | Original uploaded filename |
|
||||||
|
| ↳ `fullFileExtension` | string | Full file extension |
|
||||||
|
| ↳ `fileExtension` | string | File extension |
|
||||||
|
| ↳ `owners` | json | List of file owners |
|
||||||
|
| ↳ `permissions` | json | File permissions |
|
||||||
|
| ↳ `permissionIds` | json | Permission IDs |
|
||||||
|
| ↳ `shared` | boolean | Whether file is shared |
|
||||||
|
| ↳ `ownedByMe` | boolean | Whether owned by current user |
|
||||||
|
| ↳ `writersCanShare` | boolean | Whether writers can share |
|
||||||
|
| ↳ `viewersCanCopyContent` | boolean | Whether viewers can copy |
|
||||||
|
| ↳ `copyRequiresWriterPermission` | boolean | Whether copy requires writer permission |
|
||||||
|
| ↳ `sharingUser` | json | User who shared the file |
|
||||||
|
| ↳ `starred` | boolean | Whether file is starred |
|
||||||
|
| ↳ `trashed` | boolean | Whether file is in trash |
|
||||||
|
| ↳ `explicitlyTrashed` | boolean | Whether explicitly trashed |
|
||||||
|
| ↳ `appProperties` | json | App-specific properties |
|
||||||
|
| ↳ `createdTime` | string | File creation time |
|
||||||
|
| ↳ `modifiedTime` | string | Last modification time |
|
||||||
|
| ↳ `modifiedByMeTime` | string | When modified by current user |
|
||||||
|
| ↳ `viewedByMeTime` | string | When last viewed by current user |
|
||||||
|
| ↳ `sharedWithMeTime` | string | When shared with current user |
|
||||||
|
| ↳ `lastModifyingUser` | json | User who last modified the file |
|
||||||
|
| ↳ `viewedByMe` | boolean | Whether viewed by current user |
|
||||||
|
| ↳ `modifiedByMe` | boolean | Whether modified by current user |
|
||||||
|
| ↳ `webViewLink` | string | URL to view in browser |
|
||||||
|
| ↳ `webContentLink` | string | Direct download URL |
|
||||||
|
| ↳ `iconLink` | string | URL to file icon |
|
||||||
|
| ↳ `thumbnailLink` | string | URL to thumbnail |
|
||||||
|
| ↳ `exportLinks` | json | Export format links |
|
||||||
|
| ↳ `size` | string | File size in bytes |
|
||||||
|
| ↳ `quotaBytesUsed` | string | Storage quota used |
|
||||||
|
| ↳ `md5Checksum` | string | MD5 hash |
|
||||||
|
| ↳ `sha1Checksum` | string | SHA-1 hash |
|
||||||
|
| ↳ `sha256Checksum` | string | SHA-256 hash |
|
||||||
|
| ↳ `parents` | json | Parent folder IDs |
|
||||||
|
| ↳ `spaces` | json | Spaces containing file |
|
||||||
|
| ↳ `driveId` | string | Shared drive ID |
|
||||||
|
| ↳ `capabilities` | json | User capabilities on file |
|
||||||
|
| ↳ `version` | string | Version number |
|
||||||
|
| ↳ `headRevisionId` | string | Head revision ID |
|
||||||
|
| ↳ `hasThumbnail` | boolean | Whether has thumbnail |
|
||||||
|
| ↳ `thumbnailVersion` | string | Thumbnail version |
|
||||||
|
| ↳ `imageMediaMetadata` | json | Image-specific metadata |
|
||||||
|
| ↳ `videoMediaMetadata` | json | Video-specific metadata |
|
||||||
|
| ↳ `isAppAuthorized` | boolean | Whether created by requesting app |
|
||||||
|
| ↳ `contentRestrictions` | json | Content restrictions |
|
||||||
|
| ↳ `linkShareMetadata` | json | Link share metadata |
|
||||||
|
| ↳ `revisions` | json | File revision history \(first 100 revisions only\) |
|
||||||
|
|
||||||
|
### `google_drive_copy`
|
||||||
|
|
||||||
|
Create a copy of a file in Google Drive
|
||||||
|
|
||||||
|
#### Input
|
||||||
|
|
||||||
|
| Parameter | Type | Required | Description |
|
||||||
|
| --------- | ---- | -------- | ----------- |
|
||||||
|
| `fileId` | string | Yes | The ID of the file to copy |
|
||||||
|
| `newName` | string | No | Name for the copied file \(defaults to "Copy of \[original name\]"\) |
|
||||||
|
| `destinationFolderId` | string | No | ID of the folder to place the copy in \(defaults to same location as original\) |
|
||||||
|
|
||||||
|
#### Output
|
||||||
|
|
||||||
|
| Parameter | Type | Description |
|
||||||
|
| --------- | ---- | ----------- |
|
||||||
|
| `file` | json | The copied file metadata |
|
||||||
|
| ↳ `id` | string | Google Drive file ID of the copy |
|
||||||
|
| ↳ `kind` | string | Resource type identifier |
|
||||||
|
| ↳ `name` | string | File name |
|
||||||
|
| ↳ `mimeType` | string | MIME type |
|
||||||
|
| ↳ `webViewLink` | string | URL to view in browser |
|
||||||
|
| ↳ `parents` | json | Parent folder IDs |
|
||||||
|
| ↳ `createdTime` | string | File creation time |
|
||||||
|
| ↳ `modifiedTime` | string | Last modification time |
|
||||||
|
| ↳ `owners` | json | List of file owners |
|
||||||
|
| ↳ `size` | string | File size in bytes |
|
||||||
|
|
||||||
|
### `google_drive_update`
|
||||||
|
|
||||||
|
Update file metadata in Google Drive (rename, move, star, add description)
|
||||||
|
|
||||||
|
#### Input
|
||||||
|
|
||||||
|
| Parameter | Type | Required | Description |
|
||||||
|
| --------- | ---- | -------- | ----------- |
|
||||||
|
| `fileId` | string | Yes | The ID of the file to update |
|
||||||
|
| `name` | string | No | New name for the file |
|
||||||
|
| `description` | string | No | New description for the file |
|
||||||
|
| `addParents` | string | No | Comma-separated list of parent folder IDs to add \(moves file to these folders\) |
|
||||||
|
| `removeParents` | string | No | Comma-separated list of parent folder IDs to remove |
|
||||||
|
| `starred` | boolean | No | Whether to star or unstar the file |
|
||||||
|
|
||||||
|
#### Output
|
||||||
|
|
||||||
|
| Parameter | Type | Description |
|
||||||
|
| --------- | ---- | ----------- |
|
||||||
|
| `file` | json | The updated file metadata |
|
||||||
|
| ↳ `id` | string | Google Drive file ID |
|
||||||
|
| ↳ `kind` | string | Resource type identifier |
|
||||||
|
| ↳ `name` | string | File name |
|
||||||
|
| ↳ `mimeType` | string | MIME type |
|
||||||
|
| ↳ `description` | string | File description |
|
||||||
|
| ↳ `starred` | boolean | Whether file is starred |
|
||||||
|
| ↳ `webViewLink` | string | URL to view in browser |
|
||||||
|
| ↳ `parents` | json | Parent folder IDs |
|
||||||
|
| ↳ `modifiedTime` | string | Last modification time |
|
||||||
|
|
||||||
|
### `google_drive_trash`
|
||||||
|
|
||||||
|
Move a file to the trash in Google Drive (can be restored later)
|
||||||
|
|
||||||
|
#### Input
|
||||||
|
|
||||||
|
| Parameter | Type | Required | Description |
|
||||||
|
| --------- | ---- | -------- | ----------- |
|
||||||
|
| `fileId` | string | Yes | The ID of the file to move to trash |
|
||||||
|
|
||||||
|
#### Output
|
||||||
|
|
||||||
|
| Parameter | Type | Description |
|
||||||
|
| --------- | ---- | ----------- |
|
||||||
|
| `file` | json | The trashed file metadata |
|
||||||
|
| ↳ `id` | string | Google Drive file ID |
|
||||||
|
| ↳ `kind` | string | Resource type identifier |
|
||||||
|
| ↳ `name` | string | File name |
|
||||||
|
| ↳ `mimeType` | string | MIME type |
|
||||||
|
| ↳ `trashed` | boolean | Whether file is in trash \(should be true\) |
|
||||||
|
| ↳ `trashedTime` | string | When file was trashed |
|
||||||
|
| ↳ `webViewLink` | string | URL to view in browser |
|
||||||
|
|
||||||
|
### `google_drive_delete`
|
||||||
|
|
||||||
|
Permanently delete a file from Google Drive (bypasses trash)
|
||||||
|
|
||||||
|
#### Input
|
||||||
|
|
||||||
|
| Parameter | Type | Required | Description |
|
||||||
|
| --------- | ---- | -------- | ----------- |
|
||||||
|
| `fileId` | string | Yes | The ID of the file to permanently delete |
|
||||||
|
|
||||||
|
#### Output
|
||||||
|
|
||||||
|
| Parameter | Type | Description |
|
||||||
|
| --------- | ---- | ----------- |
|
||||||
|
| `deleted` | boolean | Whether the file was successfully deleted |
|
||||||
|
| `fileId` | string | The ID of the deleted file |
|
||||||
|
|
||||||
|
### `google_drive_share`
|
||||||
|
|
||||||
|
Share a file with a user, group, domain, or make it public
|
||||||
|
|
||||||
|
#### Input
|
||||||
|
|
||||||
|
| Parameter | Type | Required | Description |
|
||||||
|
| --------- | ---- | -------- | ----------- |
|
||||||
|
| `fileId` | string | Yes | The ID of the file to share |
|
||||||
|
| `type` | string | Yes | Type of grantee: user, group, domain, or anyone |
|
||||||
|
| `role` | string | Yes | Permission role: owner \(transfer ownership\), organizer \(shared drive only\), fileOrganizer \(shared drive only\), writer \(edit\), commenter \(view and comment\), reader \(view only\) |
|
||||||
|
| `email` | string | No | Email address of the user or group \(required for type=user or type=group\) |
|
||||||
|
| `domain` | string | No | Domain to share with \(required for type=domain\) |
|
||||||
|
| `transferOwnership` | boolean | No | Required when role is owner. Transfers ownership to the specified user. |
|
||||||
|
| `moveToNewOwnersRoot` | boolean | No | When transferring ownership, move the file to the new owner's My Drive root folder. |
|
||||||
|
| `sendNotification` | boolean | No | Whether to send an email notification \(default: true\) |
|
||||||
|
| `emailMessage` | string | No | Custom message to include in the notification email |
|
||||||
|
|
||||||
|
#### Output
|
||||||
|
|
||||||
|
| Parameter | Type | Description |
|
||||||
|
| --------- | ---- | ----------- |
|
||||||
|
| `permission` | json | The created permission details |
|
||||||
|
| ↳ `id` | string | Permission ID |
|
||||||
|
| ↳ `type` | string | Grantee type \(user, group, domain, anyone\) |
|
||||||
|
| ↳ `role` | string | Permission role |
|
||||||
|
| ↳ `emailAddress` | string | Email of the grantee |
|
||||||
|
| ↳ `displayName` | string | Display name of the grantee |
|
||||||
|
| ↳ `domain` | string | Domain of the grantee |
|
||||||
|
| ↳ `expirationTime` | string | Expiration time |
|
||||||
|
| ↳ `deleted` | boolean | Whether grantee is deleted |
|
||||||
|
|
||||||
|
### `google_drive_unshare`
|
||||||
|
|
||||||
|
Remove a permission from a file (revoke access)
|
||||||
|
|
||||||
|
#### Input
|
||||||
|
|
||||||
|
| Parameter | Type | Required | Description |
|
||||||
|
| --------- | ---- | -------- | ----------- |
|
||||||
|
| `fileId` | string | Yes | The ID of the file to modify permissions on |
|
||||||
|
| `permissionId` | string | Yes | The ID of the permission to remove \(use list_permissions to find this\) |
|
||||||
|
|
||||||
|
#### Output
|
||||||
|
|
||||||
|
| Parameter | Type | Description |
|
||||||
|
| --------- | ---- | ----------- |
|
||||||
|
| `removed` | boolean | Whether the permission was successfully removed |
|
||||||
|
| `fileId` | string | The ID of the file |
|
||||||
|
| `permissionId` | string | The ID of the removed permission |
|
||||||
|
|
||||||
|
### `google_drive_list_permissions`
|
||||||
|
|
||||||
|
List all permissions (who has access) for a file in Google Drive
|
||||||
|
|
||||||
|
#### Input
|
||||||
|
|
||||||
|
| Parameter | Type | Required | Description |
|
||||||
|
| --------- | ---- | -------- | ----------- |
|
||||||
|
| `fileId` | string | Yes | The ID of the file to list permissions for |
|
||||||
|
|
||||||
|
#### Output
|
||||||
|
|
||||||
|
| Parameter | Type | Description |
|
||||||
|
| --------- | ---- | ----------- |
|
||||||
|
| `permissions` | array | List of permissions on the file |
|
||||||
|
| ↳ `id` | string | Permission ID \(use to remove permission\) |
|
||||||
|
| ↳ `type` | string | Grantee type \(user, group, domain, anyone\) |
|
||||||
|
| ↳ `role` | string | Permission role \(owner, organizer, fileOrganizer, writer, commenter, reader\) |
|
||||||
|
| ↳ `emailAddress` | string | Email of the grantee |
|
||||||
|
| ↳ `displayName` | string | Display name of the grantee |
|
||||||
|
| ↳ `photoLink` | string | Photo URL of the grantee |
|
||||||
|
| ↳ `domain` | string | Domain of the grantee |
|
||||||
|
| ↳ `expirationTime` | string | When permission expires |
|
||||||
|
| ↳ `deleted` | boolean | Whether grantee account is deleted |
|
||||||
|
| ↳ `allowFileDiscovery` | boolean | Whether file is discoverable by grantee |
|
||||||
|
| ↳ `pendingOwner` | boolean | Whether ownership transfer is pending |
|
||||||
|
| ↳ `permissionDetails` | json | Details about inherited permissions |
|
||||||
|
| `nextPageToken` | string | Token for fetching the next page of permissions |
|
||||||
|
|
||||||
|
### `google_drive_get_about`
|
||||||
|
|
||||||
|
Get information about the user and their Google Drive (storage quota, capabilities)
|
||||||
|
|
||||||
|
#### Input
|
||||||
|
|
||||||
|
| Parameter | Type | Required | Description |
|
||||||
|
| --------- | ---- | -------- | ----------- |
|
||||||
|
|
||||||
|
#### Output
|
||||||
|
|
||||||
|
| Parameter | Type | Description |
|
||||||
|
| --------- | ---- | ----------- |
|
||||||
|
| `user` | json | Information about the authenticated user |
|
||||||
|
| ↳ `displayName` | string | User display name |
|
||||||
|
| ↳ `emailAddress` | string | User email address |
|
||||||
|
| ↳ `photoLink` | string | URL to user profile photo |
|
||||||
|
| ↳ `permissionId` | string | User permission ID |
|
||||||
|
| ↳ `me` | boolean | Whether this is the authenticated user |
|
||||||
|
| `storageQuota` | json | Storage quota information in bytes |
|
||||||
|
| ↳ `limit` | string | Total storage limit in bytes \(null for unlimited\) |
|
||||||
|
| ↳ `usage` | string | Total storage used in bytes |
|
||||||
|
| ↳ `usageInDrive` | string | Storage used by Drive files in bytes |
|
||||||
|
| ↳ `usageInDriveTrash` | string | Storage used by trashed files in bytes |
|
||||||
|
| `canCreateDrives` | boolean | Whether user can create shared drives |
|
||||||
|
| `importFormats` | json | Map of MIME types that can be imported and their target formats |
|
||||||
|
| `exportFormats` | json | Map of Google Workspace MIME types and their exportable formats |
|
||||||
|
| `maxUploadSize` | string | Maximum upload size in bytes |
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
---
|
---
|
||||||
title: Google Forms
|
title: Google Forms
|
||||||
description: Read responses from a Google Form
|
description: Manage Google Forms and responses
|
||||||
---
|
---
|
||||||
|
|
||||||
import { BlockInfoCard } from "@/components/ui/block-info-card"
|
import { BlockInfoCard } from "@/components/ui/block-info-card"
|
||||||
@@ -29,7 +29,7 @@ In Sim, the Google Forms integration enables your agents to programmatically acc
|
|||||||
|
|
||||||
## Usage Instructions
|
## Usage Instructions
|
||||||
|
|
||||||
Integrate Google Forms into your workflow. Provide a Form ID to list responses, or specify a Response ID to fetch a single response. Requires OAuth.
|
Integrate Google Forms into your workflow. Read form structure, get responses, create forms, update content, and manage notification watches.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -37,15 +37,246 @@ Integrate Google Forms into your workflow. Provide a Form ID to list responses,
|
|||||||
|
|
||||||
### `google_forms_get_responses`
|
### `google_forms_get_responses`
|
||||||
|
|
||||||
|
Retrieve a single response or list responses from a Google Form
|
||||||
|
|
||||||
#### Input
|
#### Input
|
||||||
|
|
||||||
| Parameter | Type | Required | Description |
|
| Parameter | Type | Required | Description |
|
||||||
| --------- | ---- | -------- | ----------- |
|
| --------- | ---- | -------- | ----------- |
|
||||||
|
| `formId` | string | Yes | The ID of the Google Form |
|
||||||
|
| `responseId` | string | No | If provided, returns this specific response |
|
||||||
|
| `pageSize` | number | No | Maximum number of responses to return \(service may return fewer\). Defaults to 5000. |
|
||||||
|
|
||||||
#### Output
|
#### Output
|
||||||
|
|
||||||
| Parameter | Type | Description |
|
| Parameter | Type | Description |
|
||||||
| --------- | ---- | ----------- |
|
| --------- | ---- | ----------- |
|
||||||
| `data` | json | Response or list of responses |
|
| `responses` | array | Array of form responses \(when no responseId provided\) |
|
||||||
|
| ↳ `responseId` | string | Unique response ID |
|
||||||
|
| ↳ `createTime` | string | When the response was created |
|
||||||
|
| ↳ `lastSubmittedTime` | string | When the response was last submitted |
|
||||||
|
| ↳ `answers` | json | Map of question IDs to answer values |
|
||||||
|
| `response` | object | Single form response \(when responseId is provided\) |
|
||||||
|
| ↳ `responseId` | string | Unique response ID |
|
||||||
|
| ↳ `createTime` | string | When the response was created |
|
||||||
|
| ↳ `lastSubmittedTime` | string | When the response was last submitted |
|
||||||
|
| ↳ `answers` | json | Map of question IDs to answer values |
|
||||||
|
| `raw` | json | Raw API response data |
|
||||||
|
|
||||||
|
### `google_forms_get_form`
|
||||||
|
|
||||||
|
Retrieve a form structure including its items, settings, and metadata
|
||||||
|
|
||||||
|
#### Input
|
||||||
|
|
||||||
|
| Parameter | Type | Required | Description |
|
||||||
|
| --------- | ---- | -------- | ----------- |
|
||||||
|
| `formId` | string | Yes | The ID of the Google Form to retrieve |
|
||||||
|
|
||||||
|
#### Output
|
||||||
|
|
||||||
|
| Parameter | Type | Description |
|
||||||
|
| --------- | ---- | ----------- |
|
||||||
|
| `formId` | string | The form ID |
|
||||||
|
| `title` | string | The form title visible to responders |
|
||||||
|
| `description` | string | The form description |
|
||||||
|
| `documentTitle` | string | The document title visible in Drive |
|
||||||
|
| `responderUri` | string | The URI to share with responders |
|
||||||
|
| `linkedSheetId` | string | The ID of the linked Google Sheet |
|
||||||
|
| `revisionId` | string | The revision ID of the form |
|
||||||
|
| `items` | array | The form items \(questions, sections, etc.\) |
|
||||||
|
| ↳ `itemId` | string | Item ID |
|
||||||
|
| ↳ `title` | string | Item title |
|
||||||
|
| ↳ `description` | string | Item description |
|
||||||
|
| `settings` | json | Form settings |
|
||||||
|
| `publishSettings` | json | Form publish settings |
|
||||||
|
|
||||||
|
### `google_forms_create_form`
|
||||||
|
|
||||||
|
Create a new Google Form with a title
|
||||||
|
|
||||||
|
#### Input
|
||||||
|
|
||||||
|
| Parameter | Type | Required | Description |
|
||||||
|
| --------- | ---- | -------- | ----------- |
|
||||||
|
| `title` | string | Yes | The title of the form visible to responders |
|
||||||
|
| `documentTitle` | string | No | The document title visible in Drive \(defaults to form title\) |
|
||||||
|
| `unpublished` | boolean | No | If true, create an unpublished form that does not accept responses |
|
||||||
|
|
||||||
|
#### Output
|
||||||
|
|
||||||
|
| Parameter | Type | Description |
|
||||||
|
| --------- | ---- | ----------- |
|
||||||
|
| `formId` | string | The ID of the created form |
|
||||||
|
| `title` | string | The form title |
|
||||||
|
| `documentTitle` | string | The document title in Drive |
|
||||||
|
| `responderUri` | string | The URI to share with responders |
|
||||||
|
| `revisionId` | string | The revision ID of the form |
|
||||||
|
|
||||||
|
### `google_forms_batch_update`
|
||||||
|
|
||||||
|
Apply multiple updates to a form (add items, update info, change settings, etc.)
|
||||||
|
|
||||||
|
#### Input
|
||||||
|
|
||||||
|
| Parameter | Type | Required | Description |
|
||||||
|
| --------- | ---- | -------- | ----------- |
|
||||||
|
| `formId` | string | Yes | The ID of the Google Form to update |
|
||||||
|
| `requests` | json | Yes | Array of update requests \(updateFormInfo, updateSettings, createItem, updateItem, moveItem, deleteItem\) |
|
||||||
|
| `includeFormInResponse` | boolean | No | Whether to return the updated form in the response |
|
||||||
|
|
||||||
|
#### Output
|
||||||
|
|
||||||
|
| Parameter | Type | Description |
|
||||||
|
| --------- | ---- | ----------- |
|
||||||
|
| `replies` | array | The replies from each update request |
|
||||||
|
| `writeControl` | object | Write control information with revision IDs |
|
||||||
|
| ↳ `requiredRevisionId` | string | Required revision ID for conflict detection |
|
||||||
|
| ↳ `targetRevisionId` | string | Target revision ID |
|
||||||
|
| `form` | object | The updated form \(if includeFormInResponse was true\) |
|
||||||
|
| ↳ `formId` | string | The form ID |
|
||||||
|
| ↳ `info` | object | Form info containing title and description |
|
||||||
|
| ↳ `title` | string | The form title visible to responders |
|
||||||
|
| ↳ `description` | string | The form description |
|
||||||
|
| ↳ `documentTitle` | string | The document title visible in Drive |
|
||||||
|
| ↳ `title` | string | Item title |
|
||||||
|
| ↳ `description` | string | Item description |
|
||||||
|
| ↳ `documentTitle` | string | The document title visible in Drive |
|
||||||
|
| ↳ `settings` | object | Form settings |
|
||||||
|
| ↳ `quizSettings` | object | Quiz settings |
|
||||||
|
| ↳ `isQuiz` | boolean | Whether the form is a quiz |
|
||||||
|
| ↳ `isQuiz` | boolean | Whether the form is a quiz |
|
||||||
|
| ↳ `emailCollectionType` | string | Email collection type |
|
||||||
|
| ↳ `quizSettings` | object | Quiz settings |
|
||||||
|
| ↳ `isQuiz` | boolean | Whether the form is a quiz |
|
||||||
|
| ↳ `isQuiz` | boolean | Whether the form is a quiz |
|
||||||
|
| ↳ `emailCollectionType` | string | Email collection type |
|
||||||
|
| ↳ `itemId` | string | Item ID |
|
||||||
|
| ↳ `questionItem` | json | Question item configuration |
|
||||||
|
| ↳ `questionGroupItem` | json | Question group configuration |
|
||||||
|
| ↳ `pageBreakItem` | json | Page break configuration |
|
||||||
|
| ↳ `textItem` | json | Text item configuration |
|
||||||
|
| ↳ `imageItem` | json | Image item configuration |
|
||||||
|
| ↳ `videoItem` | json | Video item configuration |
|
||||||
|
| ↳ `revisionId` | string | The revision ID of the form |
|
||||||
|
| ↳ `responderUri` | string | The URI to share with responders |
|
||||||
|
| ↳ `linkedSheetId` | string | The ID of the linked Google Sheet |
|
||||||
|
| ↳ `publishSettings` | object | Form publish settings |
|
||||||
|
| ↳ `publishState` | object | Current publish state |
|
||||||
|
| ↳ `isPublished` | boolean | Whether the form is published |
|
||||||
|
| ↳ `isAcceptingResponses` | boolean | Whether the form is accepting responses |
|
||||||
|
| ↳ `isPublished` | boolean | Whether the form is published |
|
||||||
|
| ↳ `isAcceptingResponses` | boolean | Whether the form is accepting responses |
|
||||||
|
| ↳ `publishState` | object | Current publish state |
|
||||||
|
| ↳ `isPublished` | boolean | Whether the form is published |
|
||||||
|
| ↳ `isAcceptingResponses` | boolean | Whether the form is accepting responses |
|
||||||
|
| ↳ `isPublished` | boolean | Whether the form is published |
|
||||||
|
| ↳ `isAcceptingResponses` | boolean | Whether the form is accepting responses |
|
||||||
|
|
||||||
|
### `google_forms_set_publish_settings`
|
||||||
|
|
||||||
|
Update the publish settings of a form (publish/unpublish, accept responses)
|
||||||
|
|
||||||
|
#### Input
|
||||||
|
|
||||||
|
| Parameter | Type | Required | Description |
|
||||||
|
| --------- | ---- | -------- | ----------- |
|
||||||
|
| `formId` | string | Yes | The ID of the Google Form |
|
||||||
|
| `isPublished` | boolean | Yes | Whether the form is published and visible to others |
|
||||||
|
| `isAcceptingResponses` | boolean | No | Whether the form accepts responses \(forced to false if isPublished is false\) |
|
||||||
|
|
||||||
|
#### Output
|
||||||
|
|
||||||
|
| Parameter | Type | Description |
|
||||||
|
| --------- | ---- | ----------- |
|
||||||
|
| `formId` | string | The form ID |
|
||||||
|
| `publishSettings` | json | The updated publish settings |
|
||||||
|
| ↳ `publishState` | object | The publish state |
|
||||||
|
| ↳ `isPublished` | boolean | Whether the form is published |
|
||||||
|
| ↳ `isAcceptingResponses` | boolean | Whether the form accepts responses |
|
||||||
|
| ↳ `isPublished` | boolean | Whether the form is published |
|
||||||
|
| ↳ `isAcceptingResponses` | boolean | Whether the form accepts responses |
|
||||||
|
|
||||||
|
### `google_forms_create_watch`
|
||||||
|
|
||||||
|
Create a notification watch for form changes (schema changes or new responses)
|
||||||
|
|
||||||
|
#### Input
|
||||||
|
|
||||||
|
| Parameter | Type | Required | Description |
|
||||||
|
| --------- | ---- | -------- | ----------- |
|
||||||
|
| `formId` | string | Yes | The ID of the Google Form to watch |
|
||||||
|
| `eventType` | string | Yes | Event type to watch: SCHEMA \(form changes\) or RESPONSES \(new submissions\) |
|
||||||
|
| `topicName` | string | Yes | The Cloud Pub/Sub topic name \(format: projects/\{project\}/topics/\{topic\}\) |
|
||||||
|
| `watchId` | string | No | Custom watch ID \(4-63 chars, lowercase letters, numbers, hyphens\) |
|
||||||
|
|
||||||
|
#### Output
|
||||||
|
|
||||||
|
| Parameter | Type | Description |
|
||||||
|
| --------- | ---- | ----------- |
|
||||||
|
| `id` | string | The watch ID |
|
||||||
|
| `eventType` | string | The event type being watched |
|
||||||
|
| `topicName` | string | The Cloud Pub/Sub topic |
|
||||||
|
| `createTime` | string | When the watch was created |
|
||||||
|
| `expireTime` | string | When the watch expires \(7 days after creation\) |
|
||||||
|
| `state` | string | The watch state \(ACTIVE, SUSPENDED\) |
|
||||||
|
|
||||||
|
### `google_forms_list_watches`
|
||||||
|
|
||||||
|
List all notification watches for a form
|
||||||
|
|
||||||
|
#### Input
|
||||||
|
|
||||||
|
| Parameter | Type | Required | Description |
|
||||||
|
| --------- | ---- | -------- | ----------- |
|
||||||
|
| `formId` | string | Yes | The ID of the Google Form |
|
||||||
|
|
||||||
|
#### Output
|
||||||
|
|
||||||
|
| Parameter | Type | Description |
|
||||||
|
| --------- | ---- | ----------- |
|
||||||
|
| `watches` | array | List of watches for the form |
|
||||||
|
| ↳ `id` | string | Watch ID |
|
||||||
|
| ↳ `eventType` | string | Event type \(SCHEMA or RESPONSES\) |
|
||||||
|
| ↳ `createTime` | string | When the watch was created |
|
||||||
|
| ↳ `expireTime` | string | When the watch expires |
|
||||||
|
| ↳ `state` | string | Watch state |
|
||||||
|
|
||||||
|
### `google_forms_delete_watch`
|
||||||
|
|
||||||
|
Delete a notification watch from a form
|
||||||
|
|
||||||
|
#### Input
|
||||||
|
|
||||||
|
| Parameter | Type | Required | Description |
|
||||||
|
| --------- | ---- | -------- | ----------- |
|
||||||
|
| `formId` | string | Yes | The ID of the Google Form |
|
||||||
|
| `watchId` | string | Yes | The ID of the watch to delete |
|
||||||
|
|
||||||
|
#### Output
|
||||||
|
|
||||||
|
| Parameter | Type | Description |
|
||||||
|
| --------- | ---- | ----------- |
|
||||||
|
| `deleted` | boolean | Whether the watch was successfully deleted |
|
||||||
|
|
||||||
|
### `google_forms_renew_watch`
|
||||||
|
|
||||||
|
Renew a notification watch for another 7 days
|
||||||
|
|
||||||
|
#### Input
|
||||||
|
|
||||||
|
| Parameter | Type | Required | Description |
|
||||||
|
| --------- | ---- | -------- | ----------- |
|
||||||
|
| `formId` | string | Yes | The ID of the Google Form |
|
||||||
|
| `watchId` | string | Yes | The ID of the watch to renew |
|
||||||
|
|
||||||
|
#### Output
|
||||||
|
|
||||||
|
| Parameter | Type | Description |
|
||||||
|
| --------- | ---- | ----------- |
|
||||||
|
| `id` | string | The watch ID |
|
||||||
|
| `eventType` | string | The event type being watched |
|
||||||
|
| `expireTime` | string | The new expiration time |
|
||||||
|
| `state` | string | The watch state |
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -215,4 +215,191 @@ Check if a user is a member of a Google Group
|
|||||||
| --------- | ---- | ----------- |
|
| --------- | ---- | ----------- |
|
||||||
| `isMember` | boolean | Whether the user is a member of the group |
|
| `isMember` | boolean | Whether the user is a member of the group |
|
||||||
|
|
||||||
|
### `google_groups_list_aliases`
|
||||||
|
|
||||||
|
List all email aliases for a Google Group
|
||||||
|
|
||||||
|
#### Input
|
||||||
|
|
||||||
|
| Parameter | Type | Required | Description |
|
||||||
|
| --------- | ---- | -------- | ----------- |
|
||||||
|
| `groupKey` | string | Yes | Group email address or unique group ID |
|
||||||
|
|
||||||
|
#### Output
|
||||||
|
|
||||||
|
| Parameter | Type | Description |
|
||||||
|
| --------- | ---- | ----------- |
|
||||||
|
| `aliases` | array | List of email aliases for the group |
|
||||||
|
| ↳ `id` | string | Unique group identifier |
|
||||||
|
| ↳ `primaryEmail` | string | Group |
|
||||||
|
| ↳ `alias` | string | Alias email address |
|
||||||
|
| ↳ `kind` | string | API resource type |
|
||||||
|
| ↳ `etag` | string | Resource version identifier |
|
||||||
|
|
||||||
|
### `google_groups_add_alias`
|
||||||
|
|
||||||
|
Add an email alias to a Google Group
|
||||||
|
|
||||||
|
#### Input
|
||||||
|
|
||||||
|
| Parameter | Type | Required | Description |
|
||||||
|
| --------- | ---- | -------- | ----------- |
|
||||||
|
| `groupKey` | string | Yes | Group email address or unique group ID |
|
||||||
|
| `alias` | string | Yes | The email alias to add to the group |
|
||||||
|
|
||||||
|
#### Output
|
||||||
|
|
||||||
|
| Parameter | Type | Description |
|
||||||
|
| --------- | ---- | ----------- |
|
||||||
|
| `id` | string | Unique group identifier |
|
||||||
|
| `primaryEmail` | string | Group |
|
||||||
|
| `alias` | string | The alias that was added |
|
||||||
|
| `kind` | string | API resource type |
|
||||||
|
| `etag` | string | Resource version identifier |
|
||||||
|
|
||||||
|
### `google_groups_remove_alias`
|
||||||
|
|
||||||
|
Remove an email alias from a Google Group
|
||||||
|
|
||||||
|
#### Input
|
||||||
|
|
||||||
|
| Parameter | Type | Required | Description |
|
||||||
|
| --------- | ---- | -------- | ----------- |
|
||||||
|
| `groupKey` | string | Yes | Group email address or unique group ID |
|
||||||
|
| `alias` | string | Yes | The email alias to remove from the group |
|
||||||
|
|
||||||
|
#### Output
|
||||||
|
|
||||||
|
| Parameter | Type | Description |
|
||||||
|
| --------- | ---- | ----------- |
|
||||||
|
| `deleted` | boolean | Whether the alias was successfully deleted |
|
||||||
|
|
||||||
|
### `google_groups_get_settings`
|
||||||
|
|
||||||
|
Get the settings for a Google Group including access permissions, moderation, and posting options
|
||||||
|
|
||||||
|
#### Input
|
||||||
|
|
||||||
|
| Parameter | Type | Required | Description |
|
||||||
|
| --------- | ---- | -------- | ----------- |
|
||||||
|
| `groupEmail` | string | Yes | The email address of the group |
|
||||||
|
|
||||||
|
#### Output
|
||||||
|
|
||||||
|
| Parameter | Type | Description |
|
||||||
|
| --------- | ---- | ----------- |
|
||||||
|
| `email` | string | The group |
|
||||||
|
| `name` | string | The group name \(max 75 characters\) |
|
||||||
|
| `description` | string | The group description \(max 4096 characters\) |
|
||||||
|
| `whoCanJoin` | string | Who can join the group \(ANYONE_CAN_JOIN, ALL_IN_DOMAIN_CAN_JOIN, INVITED_CAN_JOIN, CAN_REQUEST_TO_JOIN\) |
|
||||||
|
| `whoCanViewMembership` | string | Who can view group membership |
|
||||||
|
| `whoCanViewGroup` | string | Who can view group messages |
|
||||||
|
| `whoCanPostMessage` | string | Who can post messages to the group |
|
||||||
|
| `allowExternalMembers` | string | Whether external users can be members |
|
||||||
|
| `allowWebPosting` | string | Whether web posting is allowed |
|
||||||
|
| `primaryLanguage` | string | The group |
|
||||||
|
| `isArchived` | string | Whether messages are archived |
|
||||||
|
| `archiveOnly` | string | Whether the group is archive-only \(inactive\) |
|
||||||
|
| `messageModerationLevel` | string | Message moderation level |
|
||||||
|
| `spamModerationLevel` | string | Spam handling level \(ALLOW, MODERATE, SILENTLY_MODERATE, REJECT\) |
|
||||||
|
| `replyTo` | string | Default reply destination |
|
||||||
|
| `customReplyTo` | string | Custom email for replies |
|
||||||
|
| `includeCustomFooter` | string | Whether to include custom footer |
|
||||||
|
| `customFooterText` | string | Custom footer text \(max 1000 characters\) |
|
||||||
|
| `sendMessageDenyNotification` | string | Whether to send rejection notifications |
|
||||||
|
| `defaultMessageDenyNotificationText` | string | Default rejection message text |
|
||||||
|
| `membersCanPostAsTheGroup` | string | Whether members can post as the group |
|
||||||
|
| `includeInGlobalAddressList` | string | Whether included in Global Address List |
|
||||||
|
| `whoCanLeaveGroup` | string | Who can leave the group |
|
||||||
|
| `whoCanContactOwner` | string | Who can contact the group owner |
|
||||||
|
| `favoriteRepliesOnTop` | string | Whether favorite replies appear at top |
|
||||||
|
| `whoCanApproveMembers` | string | Who can approve new members |
|
||||||
|
| `whoCanBanUsers` | string | Who can ban users |
|
||||||
|
| `whoCanModerateMembers` | string | Who can manage members |
|
||||||
|
| `whoCanModerateContent` | string | Who can moderate content |
|
||||||
|
| `whoCanAssistContent` | string | Who can assist with content metadata |
|
||||||
|
| `enableCollaborativeInbox` | string | Whether collaborative inbox is enabled |
|
||||||
|
| `whoCanDiscoverGroup` | string | Who can discover the group |
|
||||||
|
| `defaultSender` | string | Default sender identity \(DEFAULT_SELF or GROUP\) |
|
||||||
|
|
||||||
|
### `google_groups_update_settings`
|
||||||
|
|
||||||
|
Update the settings for a Google Group including access permissions, moderation, and posting options
|
||||||
|
|
||||||
|
#### Input
|
||||||
|
|
||||||
|
| Parameter | Type | Required | Description |
|
||||||
|
| --------- | ---- | -------- | ----------- |
|
||||||
|
| `groupEmail` | string | Yes | The email address of the group |
|
||||||
|
| `name` | string | No | The group name \(max 75 characters\) |
|
||||||
|
| `description` | string | No | The group description \(max 4096 characters\) |
|
||||||
|
| `whoCanJoin` | string | No | Who can join: ANYONE_CAN_JOIN, ALL_IN_DOMAIN_CAN_JOIN, INVITED_CAN_JOIN, CAN_REQUEST_TO_JOIN |
|
||||||
|
| `whoCanViewMembership` | string | No | Who can view membership: ALL_IN_DOMAIN_CAN_VIEW, ALL_MEMBERS_CAN_VIEW, ALL_MANAGERS_CAN_VIEW |
|
||||||
|
| `whoCanViewGroup` | string | No | Who can view group messages: ANYONE_CAN_VIEW, ALL_IN_DOMAIN_CAN_VIEW, ALL_MEMBERS_CAN_VIEW, ALL_MANAGERS_CAN_VIEW |
|
||||||
|
| `whoCanPostMessage` | string | No | Who can post: NONE_CAN_POST, ALL_MANAGERS_CAN_POST, ALL_MEMBERS_CAN_POST, ALL_OWNERS_CAN_POST, ALL_IN_DOMAIN_CAN_POST, ANYONE_CAN_POST |
|
||||||
|
| `allowExternalMembers` | string | No | Whether external users can be members: true or false |
|
||||||
|
| `allowWebPosting` | string | No | Whether web posting is allowed: true or false |
|
||||||
|
| `primaryLanguage` | string | No | The group's primary language \(e.g., en\) |
|
||||||
|
| `isArchived` | string | No | Whether messages are archived: true or false |
|
||||||
|
| `archiveOnly` | string | No | Whether the group is archive-only \(inactive\): true or false |
|
||||||
|
| `messageModerationLevel` | string | No | Message moderation: MODERATE_ALL_MESSAGES, MODERATE_NON_MEMBERS, MODERATE_NEW_MEMBERS, MODERATE_NONE |
|
||||||
|
| `spamModerationLevel` | string | No | Spam handling: ALLOW, MODERATE, SILENTLY_MODERATE, REJECT |
|
||||||
|
| `replyTo` | string | No | Default reply: REPLY_TO_CUSTOM, REPLY_TO_SENDER, REPLY_TO_LIST, REPLY_TO_OWNER, REPLY_TO_IGNORE, REPLY_TO_MANAGERS |
|
||||||
|
| `customReplyTo` | string | No | Custom email for replies \(when replyTo is REPLY_TO_CUSTOM\) |
|
||||||
|
| `includeCustomFooter` | string | No | Whether to include custom footer: true or false |
|
||||||
|
| `customFooterText` | string | No | Custom footer text \(max 1000 characters\) |
|
||||||
|
| `sendMessageDenyNotification` | string | No | Whether to send rejection notifications: true or false |
|
||||||
|
| `defaultMessageDenyNotificationText` | string | No | Default rejection message text |
|
||||||
|
| `membersCanPostAsTheGroup` | string | No | Whether members can post as the group: true or false |
|
||||||
|
| `includeInGlobalAddressList` | string | No | Whether included in Global Address List: true or false |
|
||||||
|
| `whoCanLeaveGroup` | string | No | Who can leave: ALL_MANAGERS_CAN_LEAVE, ALL_MEMBERS_CAN_LEAVE, NONE_CAN_LEAVE |
|
||||||
|
| `whoCanContactOwner` | string | No | Who can contact owner: ALL_IN_DOMAIN_CAN_CONTACT, ALL_MANAGERS_CAN_CONTACT, ALL_MEMBERS_CAN_CONTACT, ANYONE_CAN_CONTACT |
|
||||||
|
| `favoriteRepliesOnTop` | string | No | Whether favorite replies appear at top: true or false |
|
||||||
|
| `whoCanApproveMembers` | string | No | Who can approve members: ALL_OWNERS_CAN_APPROVE, ALL_MANAGERS_CAN_APPROVE, ALL_MEMBERS_CAN_APPROVE, NONE_CAN_APPROVE |
|
||||||
|
| `whoCanBanUsers` | string | No | Who can ban users: OWNERS_ONLY, OWNERS_AND_MANAGERS, NONE |
|
||||||
|
| `whoCanModerateMembers` | string | No | Who can manage members: OWNERS_ONLY, OWNERS_AND_MANAGERS, ALL_MEMBERS, NONE |
|
||||||
|
| `whoCanModerateContent` | string | No | Who can moderate content: OWNERS_ONLY, OWNERS_AND_MANAGERS, ALL_MEMBERS, NONE |
|
||||||
|
| `whoCanAssistContent` | string | No | Who can assist with content metadata: OWNERS_ONLY, OWNERS_AND_MANAGERS, ALL_MEMBERS, NONE |
|
||||||
|
| `enableCollaborativeInbox` | string | No | Whether collaborative inbox is enabled: true or false |
|
||||||
|
| `whoCanDiscoverGroup` | string | No | Who can discover: ANYONE_CAN_DISCOVER, ALL_IN_DOMAIN_CAN_DISCOVER, ALL_MEMBERS_CAN_DISCOVER |
|
||||||
|
| `defaultSender` | string | No | Default sender: DEFAULT_SELF or GROUP |
|
||||||
|
|
||||||
|
#### Output
|
||||||
|
|
||||||
|
| Parameter | Type | Description |
|
||||||
|
| --------- | ---- | ----------- |
|
||||||
|
| `email` | string | The group |
|
||||||
|
| `name` | string | The group name |
|
||||||
|
| `description` | string | The group description |
|
||||||
|
| `whoCanJoin` | string | Who can join the group |
|
||||||
|
| `whoCanViewMembership` | string | Who can view group membership |
|
||||||
|
| `whoCanViewGroup` | string | Who can view group messages |
|
||||||
|
| `whoCanPostMessage` | string | Who can post messages to the group |
|
||||||
|
| `allowExternalMembers` | string | Whether external users can be members |
|
||||||
|
| `allowWebPosting` | string | Whether web posting is allowed |
|
||||||
|
| `primaryLanguage` | string | The group |
|
||||||
|
| `isArchived` | string | Whether messages are archived |
|
||||||
|
| `archiveOnly` | string | Whether the group is archive-only |
|
||||||
|
| `messageModerationLevel` | string | Message moderation level |
|
||||||
|
| `spamModerationLevel` | string | Spam handling level |
|
||||||
|
| `replyTo` | string | Default reply destination |
|
||||||
|
| `customReplyTo` | string | Custom email for replies |
|
||||||
|
| `includeCustomFooter` | string | Whether to include custom footer |
|
||||||
|
| `customFooterText` | string | Custom footer text |
|
||||||
|
| `sendMessageDenyNotification` | string | Whether to send rejection notifications |
|
||||||
|
| `defaultMessageDenyNotificationText` | string | Default rejection message text |
|
||||||
|
| `membersCanPostAsTheGroup` | string | Whether members can post as the group |
|
||||||
|
| `includeInGlobalAddressList` | string | Whether included in Global Address List |
|
||||||
|
| `whoCanLeaveGroup` | string | Who can leave the group |
|
||||||
|
| `whoCanContactOwner` | string | Who can contact the group owner |
|
||||||
|
| `favoriteRepliesOnTop` | string | Whether favorite replies appear at top |
|
||||||
|
| `whoCanApproveMembers` | string | Who can approve new members |
|
||||||
|
| `whoCanBanUsers` | string | Who can ban users |
|
||||||
|
| `whoCanModerateMembers` | string | Who can manage members |
|
||||||
|
| `whoCanModerateContent` | string | Who can moderate content |
|
||||||
|
| `whoCanAssistContent` | string | Who can assist with content metadata |
|
||||||
|
| `enableCollaborativeInbox` | string | Whether collaborative inbox is enabled |
|
||||||
|
| `whoCanDiscoverGroup` | string | Who can discover the group |
|
||||||
|
| `defaultSender` | string | Default sender identity |
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ In Sim, the Google Sheets integration empowers your agents to automate reading f
|
|||||||
|
|
||||||
## Usage Instructions
|
## Usage Instructions
|
||||||
|
|
||||||
Integrate Google Sheets into the workflow with explicit sheet selection. Can read, write, append, and update data in specific sheets.
|
Integrate Google Sheets into the workflow with explicit sheet selection. Can read, write, append, update, clear data, create spreadsheets, get spreadsheet info, and copy sheets.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -42,9 +42,8 @@ Read data from a specific sheet in a Google Sheets spreadsheet
|
|||||||
|
|
||||||
| Parameter | Type | Required | Description |
|
| Parameter | Type | Required | Description |
|
||||||
| --------- | ---- | -------- | ----------- |
|
| --------- | ---- | -------- | ----------- |
|
||||||
| `spreadsheetId` | string | Yes | The ID of the spreadsheet |
|
| `spreadsheetId` | string | Yes | The ID of the spreadsheet \(found in the URL: docs.google.com/spreadsheets/d/\{SPREADSHEET_ID\}/edit\). |
|
||||||
| `sheetName` | string | Yes | The name of the sheet/tab to read from |
|
| `range` | string | No | The A1 notation range to read \(e.g. "Sheet1!A1:D10", "A1:B5"\). Defaults to first sheet A1:Z1000 if not specified. |
|
||||||
| `cellRange` | string | No | The cell range to read \(e.g. "A1:D10"\). Defaults to "A1:Z1000" if not specified. |
|
|
||||||
|
|
||||||
#### Output
|
#### Output
|
||||||
|
|
||||||
@@ -66,8 +65,7 @@ Write data to a specific sheet in a Google Sheets spreadsheet
|
|||||||
| Parameter | Type | Required | Description |
|
| Parameter | Type | Required | Description |
|
||||||
| --------- | ---- | -------- | ----------- |
|
| --------- | ---- | -------- | ----------- |
|
||||||
| `spreadsheetId` | string | Yes | The ID of the spreadsheet |
|
| `spreadsheetId` | string | Yes | The ID of the spreadsheet |
|
||||||
| `sheetName` | string | Yes | The name of the sheet/tab to write to |
|
| `range` | string | No | The A1 notation range to write to \(e.g. "Sheet1!A1:D10", "A1:B5"\) |
|
||||||
| `cellRange` | string | No | The cell range to write to \(e.g. "A1:D10", "A1"\). Defaults to "A1" if not specified. |
|
|
||||||
| `values` | array | Yes | The data to write as a 2D array \(e.g. \[\["Name", "Age"\], \["Alice", 30\], \["Bob", 25\]\]\) or array of objects. |
|
| `values` | array | Yes | The data to write as a 2D array \(e.g. \[\["Name", "Age"\], \["Alice", 30\], \["Bob", 25\]\]\) or array of objects. |
|
||||||
| `valueInputOption` | string | No | The format of the data to write |
|
| `valueInputOption` | string | No | The format of the data to write |
|
||||||
| `includeValuesInResponse` | boolean | No | Whether to include the written values in the response |
|
| `includeValuesInResponse` | boolean | No | Whether to include the written values in the response |
|
||||||
@@ -93,8 +91,7 @@ Update data in a specific sheet in a Google Sheets spreadsheet
|
|||||||
| Parameter | Type | Required | Description |
|
| Parameter | Type | Required | Description |
|
||||||
| --------- | ---- | -------- | ----------- |
|
| --------- | ---- | -------- | ----------- |
|
||||||
| `spreadsheetId` | string | Yes | The ID of the spreadsheet to update |
|
| `spreadsheetId` | string | Yes | The ID of the spreadsheet to update |
|
||||||
| `sheetName` | string | Yes | The name of the sheet/tab to update |
|
| `range` | string | No | The A1 notation range to update \(e.g. "Sheet1!A1:D10", "A1:B5"\) |
|
||||||
| `cellRange` | string | No | The cell range to update \(e.g. "A1:D10", "A1"\). Defaults to "A1" if not specified. |
|
|
||||||
| `values` | array | Yes | The data to update as a 2D array \(e.g. \[\["Name", "Age"\], \["Alice", 30\]\]\) or array of objects. |
|
| `values` | array | Yes | The data to update as a 2D array \(e.g. \[\["Name", "Age"\], \["Alice", 30\]\]\) or array of objects. |
|
||||||
| `valueInputOption` | string | No | The format of the data to update |
|
| `valueInputOption` | string | No | The format of the data to update |
|
||||||
| `includeValuesInResponse` | boolean | No | Whether to include the updated values in the response |
|
| `includeValuesInResponse` | boolean | No | Whether to include the updated values in the response |
|
||||||
@@ -120,7 +117,7 @@ Append data to the end of a specific sheet in a Google Sheets spreadsheet
|
|||||||
| Parameter | Type | Required | Description |
|
| Parameter | Type | Required | Description |
|
||||||
| --------- | ---- | -------- | ----------- |
|
| --------- | ---- | -------- | ----------- |
|
||||||
| `spreadsheetId` | string | Yes | The ID of the spreadsheet to append to |
|
| `spreadsheetId` | string | Yes | The ID of the spreadsheet to append to |
|
||||||
| `sheetName` | string | Yes | The name of the sheet/tab to append to |
|
| `range` | string | No | The A1 notation range to append after \(e.g. "Sheet1", "Sheet1!A:D"\) |
|
||||||
| `values` | array | Yes | The data to append as a 2D array \(e.g. \[\["Alice", 30\], \["Bob", 25\]\]\) or array of objects. |
|
| `values` | array | Yes | The data to append as a 2D array \(e.g. \[\["Alice", 30\], \["Bob", 25\]\]\) or array of objects. |
|
||||||
| `valueInputOption` | string | No | The format of the data to append |
|
| `valueInputOption` | string | No | The format of the data to append |
|
||||||
| `insertDataOption` | string | No | How to insert the data \(OVERWRITE or INSERT_ROWS\) |
|
| `insertDataOption` | string | No | How to insert the data \(OVERWRITE or INSERT_ROWS\) |
|
||||||
@@ -139,4 +136,180 @@ Append data to the end of a specific sheet in a Google Sheets spreadsheet
|
|||||||
| ↳ `spreadsheetId` | string | Google Sheets spreadsheet ID |
|
| ↳ `spreadsheetId` | string | Google Sheets spreadsheet ID |
|
||||||
| ↳ `spreadsheetUrl` | string | Spreadsheet URL |
|
| ↳ `spreadsheetUrl` | string | Spreadsheet URL |
|
||||||
|
|
||||||
|
### `google_sheets_clear`
|
||||||
|
|
||||||
|
Clear values from a specific range in a Google Sheets spreadsheet
|
||||||
|
|
||||||
|
#### Input
|
||||||
|
|
||||||
|
| Parameter | Type | Required | Description |
|
||||||
|
| --------- | ---- | -------- | ----------- |
|
||||||
|
| `spreadsheetId` | string | Yes | The ID of the spreadsheet |
|
||||||
|
| `sheetName` | string | Yes | The name of the sheet/tab to clear |
|
||||||
|
| `cellRange` | string | No | The cell range to clear \(e.g. "A1:D10"\). Clears entire sheet if not specified. |
|
||||||
|
|
||||||
|
#### Output
|
||||||
|
|
||||||
|
| Parameter | Type | Description |
|
||||||
|
| --------- | ---- | ----------- |
|
||||||
|
| `clearedRange` | string | The range that was cleared |
|
||||||
|
| `sheetName` | string | Name of the sheet that was cleared |
|
||||||
|
| `metadata` | json | Spreadsheet metadata including ID and URL |
|
||||||
|
| ↳ `spreadsheetId` | string | Google Sheets spreadsheet ID |
|
||||||
|
| ↳ `spreadsheetUrl` | string | Spreadsheet URL |
|
||||||
|
|
||||||
|
### `google_sheets_get_spreadsheet`
|
||||||
|
|
||||||
|
Get metadata about a Google Sheets spreadsheet including title and sheet list
|
||||||
|
|
||||||
|
#### Input
|
||||||
|
|
||||||
|
| Parameter | Type | Required | Description |
|
||||||
|
| --------- | ---- | -------- | ----------- |
|
||||||
|
| `spreadsheetId` | string | Yes | The ID of the spreadsheet |
|
||||||
|
| `includeGridData` | boolean | No | Whether to include grid data \(cell values\). Defaults to false. |
|
||||||
|
|
||||||
|
#### Output
|
||||||
|
|
||||||
|
| Parameter | Type | Description |
|
||||||
|
| --------- | ---- | ----------- |
|
||||||
|
| `spreadsheetId` | string | The spreadsheet ID |
|
||||||
|
| `title` | string | The title of the spreadsheet |
|
||||||
|
| `locale` | string | The locale of the spreadsheet |
|
||||||
|
| `timeZone` | string | The time zone of the spreadsheet |
|
||||||
|
| `spreadsheetUrl` | string | URL to the spreadsheet |
|
||||||
|
| `sheets` | array | List of sheets in the spreadsheet |
|
||||||
|
| ↳ `sheetId` | number | The sheet ID |
|
||||||
|
| ↳ `title` | string | The sheet title/name |
|
||||||
|
| ↳ `index` | number | The sheet index \(position\) |
|
||||||
|
| ↳ `rowCount` | number | Number of rows in the sheet |
|
||||||
|
| ↳ `columnCount` | number | Number of columns in the sheet |
|
||||||
|
| ↳ `hidden` | boolean | Whether the sheet is hidden |
|
||||||
|
|
||||||
|
### `google_sheets_create_spreadsheet`
|
||||||
|
|
||||||
|
Create a new Google Sheets spreadsheet
|
||||||
|
|
||||||
|
#### Input
|
||||||
|
|
||||||
|
| Parameter | Type | Required | Description |
|
||||||
|
| --------- | ---- | -------- | ----------- |
|
||||||
|
| `title` | string | Yes | The title of the new spreadsheet |
|
||||||
|
| `sheetTitles` | json | No | Array of sheet names to create \(e.g., \["Sheet1", "Data", "Summary"\]\). Defaults to a single "Sheet1". |
|
||||||
|
| `locale` | string | No | The locale of the spreadsheet \(e.g., "en_US"\) |
|
||||||
|
| `timeZone` | string | No | The time zone of the spreadsheet \(e.g., "America/New_York"\) |
|
||||||
|
|
||||||
|
#### Output
|
||||||
|
|
||||||
|
| Parameter | Type | Description |
|
||||||
|
| --------- | ---- | ----------- |
|
||||||
|
| `spreadsheetId` | string | The ID of the created spreadsheet |
|
||||||
|
| `title` | string | The title of the created spreadsheet |
|
||||||
|
| `spreadsheetUrl` | string | URL to the created spreadsheet |
|
||||||
|
| `sheets` | array | List of sheets created in the spreadsheet |
|
||||||
|
| ↳ `sheetId` | number | The sheet ID |
|
||||||
|
| ↳ `title` | string | The sheet title/name |
|
||||||
|
| ↳ `index` | number | The sheet index \(position\) |
|
||||||
|
|
||||||
|
### `google_sheets_batch_get`
|
||||||
|
|
||||||
|
Read multiple ranges from a Google Sheets spreadsheet in a single request
|
||||||
|
|
||||||
|
#### Input
|
||||||
|
|
||||||
|
| Parameter | Type | Required | Description |
|
||||||
|
| --------- | ---- | -------- | ----------- |
|
||||||
|
| `spreadsheetId` | string | Yes | The ID of the spreadsheet |
|
||||||
|
| `ranges` | json | Yes | Array of ranges to read \(e.g., \["Sheet1!A1:D10", "Sheet2!A1:B5"\]\). Each range should include sheet name. |
|
||||||
|
| `majorDimension` | string | No | The major dimension of values: "ROWS" \(default\) or "COLUMNS" |
|
||||||
|
| `valueRenderOption` | string | No | How values should be rendered: "FORMATTED_VALUE" \(default\), "UNFORMATTED_VALUE", or "FORMULA" |
|
||||||
|
|
||||||
|
#### Output
|
||||||
|
|
||||||
|
| Parameter | Type | Description |
|
||||||
|
| --------- | ---- | ----------- |
|
||||||
|
| `spreadsheetId` | string | The spreadsheet ID |
|
||||||
|
| `valueRanges` | array | Array of value ranges read from the spreadsheet |
|
||||||
|
| ↳ `range` | string | The range that was read |
|
||||||
|
| ↳ `majorDimension` | string | Major dimension \(ROWS or COLUMNS\) |
|
||||||
|
| ↳ `values` | array | The cell values as a 2D array |
|
||||||
|
| `metadata` | json | Spreadsheet metadata including ID and URL |
|
||||||
|
| ↳ `spreadsheetId` | string | Google Sheets spreadsheet ID |
|
||||||
|
| ↳ `spreadsheetUrl` | string | Spreadsheet URL |
|
||||||
|
|
||||||
|
### `google_sheets_batch_update`
|
||||||
|
|
||||||
|
Update multiple ranges in a Google Sheets spreadsheet in a single request
|
||||||
|
|
||||||
|
#### Input
|
||||||
|
|
||||||
|
| Parameter | Type | Required | Description |
|
||||||
|
| --------- | ---- | -------- | ----------- |
|
||||||
|
| `spreadsheetId` | string | Yes | The ID of the spreadsheet |
|
||||||
|
| `data` | json | Yes | Array of value ranges to update. Each item should have "range" \(e.g., "Sheet1!A1:D10"\) and "values" \(2D array\). |
|
||||||
|
| `valueInputOption` | string | No | How input data should be interpreted: "RAW" or "USER_ENTERED" \(default\). USER_ENTERED parses formulas. |
|
||||||
|
|
||||||
|
#### Output
|
||||||
|
|
||||||
|
| Parameter | Type | Description |
|
||||||
|
| --------- | ---- | ----------- |
|
||||||
|
| `spreadsheetId` | string | The spreadsheet ID |
|
||||||
|
| `totalUpdatedRows` | number | Total number of rows updated |
|
||||||
|
| `totalUpdatedColumns` | number | Total number of columns updated |
|
||||||
|
| `totalUpdatedCells` | number | Total number of cells updated |
|
||||||
|
| `totalUpdatedSheets` | number | Total number of sheets updated |
|
||||||
|
| `responses` | array | Array of update responses for each range |
|
||||||
|
| ↳ `spreadsheetId` | string | The spreadsheet ID |
|
||||||
|
| ↳ `updatedRange` | string | The range that was updated |
|
||||||
|
| ↳ `updatedRows` | number | Number of rows updated in this range |
|
||||||
|
| ↳ `updatedColumns` | number | Number of columns updated in this range |
|
||||||
|
| ↳ `updatedCells` | number | Number of cells updated in this range |
|
||||||
|
| `metadata` | json | Spreadsheet metadata including ID and URL |
|
||||||
|
| ↳ `spreadsheetId` | string | Google Sheets spreadsheet ID |
|
||||||
|
| ↳ `spreadsheetUrl` | string | Spreadsheet URL |
|
||||||
|
|
||||||
|
### `google_sheets_batch_clear`
|
||||||
|
|
||||||
|
Clear multiple ranges in a Google Sheets spreadsheet in a single request
|
||||||
|
|
||||||
|
#### Input
|
||||||
|
|
||||||
|
| Parameter | Type | Required | Description |
|
||||||
|
| --------- | ---- | -------- | ----------- |
|
||||||
|
| `spreadsheetId` | string | Yes | The ID of the spreadsheet |
|
||||||
|
| `ranges` | json | Yes | Array of ranges to clear \(e.g., \["Sheet1!A1:D10", "Sheet2!A1:B5"\]\). Each range should include sheet name. |
|
||||||
|
|
||||||
|
#### Output
|
||||||
|
|
||||||
|
| Parameter | Type | Description |
|
||||||
|
| --------- | ---- | ----------- |
|
||||||
|
| `spreadsheetId` | string | The spreadsheet ID |
|
||||||
|
| `clearedRanges` | array | Array of ranges that were cleared |
|
||||||
|
| `metadata` | json | Spreadsheet metadata including ID and URL |
|
||||||
|
| ↳ `spreadsheetId` | string | Google Sheets spreadsheet ID |
|
||||||
|
| ↳ `spreadsheetUrl` | string | Spreadsheet URL |
|
||||||
|
|
||||||
|
### `google_sheets_copy_sheet`
|
||||||
|
|
||||||
|
Copy a sheet from one spreadsheet to another
|
||||||
|
|
||||||
|
#### Input
|
||||||
|
|
||||||
|
| Parameter | Type | Required | Description |
|
||||||
|
| --------- | ---- | -------- | ----------- |
|
||||||
|
| `sourceSpreadsheetId` | string | Yes | The ID of the source spreadsheet |
|
||||||
|
| `sheetId` | number | Yes | The ID of the sheet to copy \(numeric ID, not the sheet name\). Use Get Spreadsheet to find sheet IDs. |
|
||||||
|
| `destinationSpreadsheetId` | string | Yes | The ID of the destination spreadsheet where the sheet will be copied |
|
||||||
|
|
||||||
|
#### Output
|
||||||
|
|
||||||
|
| Parameter | Type | Description |
|
||||||
|
| --------- | ---- | ----------- |
|
||||||
|
| `sheetId` | number | The ID of the newly created sheet in the destination |
|
||||||
|
| `title` | string | The title of the copied sheet |
|
||||||
|
| `index` | number | The index \(position\) of the copied sheet |
|
||||||
|
| `sheetType` | string | The type of the sheet \(GRID, CHART, etc.\) |
|
||||||
|
| `destinationSpreadsheetId` | string | The ID of the destination spreadsheet |
|
||||||
|
| `destinationSpreadsheetUrl` | string | URL to the destination spreadsheet |
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ In Sim, the Google Slides integration enables your agents to interact directly w
|
|||||||
|
|
||||||
## Usage Instructions
|
## Usage Instructions
|
||||||
|
|
||||||
Integrate Google Slides into the workflow. Can read, write, create presentations, replace text, add slides, add images, and get thumbnails.
|
Integrate Google Slides into the workflow. Can read, write, create presentations, replace text, add slides, add images, get thumbnails, get page details, delete objects, duplicate objects, reorder slides, create tables, create shapes, and insert text.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -52,6 +52,15 @@ Read content from a Google Slides presentation
|
|||||||
| --------- | ---- | ----------- |
|
| --------- | ---- | ----------- |
|
||||||
| `slides` | json | Array of slides with their content |
|
| `slides` | json | Array of slides with their content |
|
||||||
| `metadata` | json | Presentation metadata including ID, title, and URL |
|
| `metadata` | json | Presentation metadata including ID, title, and URL |
|
||||||
|
| ↳ `presentationId` | string | The presentation ID |
|
||||||
|
| ↳ `title` | string | The presentation title |
|
||||||
|
| ↳ `pageSize` | object | Presentation page size |
|
||||||
|
| ↳ `width` | json | Page width as a Dimension object |
|
||||||
|
| ↳ `height` | json | Page height as a Dimension object |
|
||||||
|
| ↳ `width` | json | Page width as a Dimension object |
|
||||||
|
| ↳ `height` | json | Page height as a Dimension object |
|
||||||
|
| ↳ `mimeType` | string | The mime type of the presentation |
|
||||||
|
| ↳ `url` | string | URL to open the presentation |
|
||||||
|
|
||||||
### `google_slides_write`
|
### `google_slides_write`
|
||||||
|
|
||||||
@@ -71,6 +80,10 @@ Write or update content in a Google Slides presentation
|
|||||||
| --------- | ---- | ----------- |
|
| --------- | ---- | ----------- |
|
||||||
| `updatedContent` | boolean | Indicates if presentation content was updated successfully |
|
| `updatedContent` | boolean | Indicates if presentation content was updated successfully |
|
||||||
| `metadata` | json | Updated presentation metadata including ID, title, and URL |
|
| `metadata` | json | Updated presentation metadata including ID, title, and URL |
|
||||||
|
| ↳ `presentationId` | string | The presentation ID |
|
||||||
|
| ↳ `title` | string | The presentation title |
|
||||||
|
| ↳ `mimeType` | string | The mime type of the presentation |
|
||||||
|
| ↳ `url` | string | URL to open the presentation |
|
||||||
|
|
||||||
### `google_slides_create`
|
### `google_slides_create`
|
||||||
|
|
||||||
@@ -90,6 +103,10 @@ Create a new Google Slides presentation
|
|||||||
| Parameter | Type | Description |
|
| Parameter | Type | Description |
|
||||||
| --------- | ---- | ----------- |
|
| --------- | ---- | ----------- |
|
||||||
| `metadata` | json | Created presentation metadata including ID, title, and URL |
|
| `metadata` | json | Created presentation metadata including ID, title, and URL |
|
||||||
|
| ↳ `presentationId` | string | The presentation ID |
|
||||||
|
| ↳ `title` | string | The presentation title |
|
||||||
|
| ↳ `mimeType` | string | The mime type of the presentation |
|
||||||
|
| ↳ `url` | string | URL to open the presentation |
|
||||||
|
|
||||||
### `google_slides_replace_all_text`
|
### `google_slides_replace_all_text`
|
||||||
|
|
||||||
@@ -111,6 +128,10 @@ Find and replace all occurrences of text throughout a Google Slides presentation
|
|||||||
| --------- | ---- | ----------- |
|
| --------- | ---- | ----------- |
|
||||||
| `occurrencesChanged` | number | Number of text occurrences that were replaced |
|
| `occurrencesChanged` | number | Number of text occurrences that were replaced |
|
||||||
| `metadata` | json | Operation metadata including presentation ID and URL |
|
| `metadata` | json | Operation metadata including presentation ID and URL |
|
||||||
|
| ↳ `presentationId` | string | The presentation ID |
|
||||||
|
| ↳ `findText` | string | The text that was searched for |
|
||||||
|
| ↳ `replaceText` | string | The text that replaced the matches |
|
||||||
|
| ↳ `url` | string | URL to open the presentation |
|
||||||
|
|
||||||
### `google_slides_add_slide`
|
### `google_slides_add_slide`
|
||||||
|
|
||||||
@@ -131,6 +152,10 @@ Add a new slide to a Google Slides presentation with a specified layout
|
|||||||
| --------- | ---- | ----------- |
|
| --------- | ---- | ----------- |
|
||||||
| `slideId` | string | The object ID of the newly created slide |
|
| `slideId` | string | The object ID of the newly created slide |
|
||||||
| `metadata` | json | Operation metadata including presentation ID, layout, and URL |
|
| `metadata` | json | Operation metadata including presentation ID, layout, and URL |
|
||||||
|
| ↳ `presentationId` | string | The presentation ID |
|
||||||
|
| ↳ `layout` | string | The layout used for the new slide |
|
||||||
|
| ↳ `insertionIndex` | number | The zero-based index where the slide was inserted |
|
||||||
|
| ↳ `url` | string | URL to open the presentation |
|
||||||
|
|
||||||
### `google_slides_add_image`
|
### `google_slides_add_image`
|
||||||
|
|
||||||
@@ -154,6 +179,10 @@ Insert an image into a specific slide in a Google Slides presentation
|
|||||||
| --------- | ---- | ----------- |
|
| --------- | ---- | ----------- |
|
||||||
| `imageId` | string | The object ID of the newly created image |
|
| `imageId` | string | The object ID of the newly created image |
|
||||||
| `metadata` | json | Operation metadata including presentation ID and image URL |
|
| `metadata` | json | Operation metadata including presentation ID and image URL |
|
||||||
|
| ↳ `presentationId` | string | The presentation ID |
|
||||||
|
| ↳ `pageObjectId` | string | The page object ID where the image was inserted |
|
||||||
|
| ↳ `imageUrl` | string | The source image URL |
|
||||||
|
| ↳ `url` | string | URL to open the presentation |
|
||||||
|
|
||||||
### `google_slides_get_thumbnail`
|
### `google_slides_get_thumbnail`
|
||||||
|
|
||||||
@@ -176,5 +205,182 @@ Generate a thumbnail image of a specific slide in a Google Slides presentation
|
|||||||
| `width` | number | Width of the thumbnail in pixels |
|
| `width` | number | Width of the thumbnail in pixels |
|
||||||
| `height` | number | Height of the thumbnail in pixels |
|
| `height` | number | Height of the thumbnail in pixels |
|
||||||
| `metadata` | json | Operation metadata including presentation ID and page object ID |
|
| `metadata` | json | Operation metadata including presentation ID and page object ID |
|
||||||
|
| ↳ `presentationId` | string | The presentation ID |
|
||||||
|
| ↳ `pageObjectId` | string | The page object ID for the thumbnail |
|
||||||
|
| ↳ `thumbnailSize` | string | The requested thumbnail size |
|
||||||
|
| ↳ `mimeType` | string | The thumbnail MIME type |
|
||||||
|
|
||||||
|
### `google_slides_get_page`
|
||||||
|
|
||||||
|
Get detailed information about a specific slide/page in a Google Slides presentation
|
||||||
|
|
||||||
|
#### Input
|
||||||
|
|
||||||
|
| Parameter | Type | Required | Description |
|
||||||
|
| --------- | ---- | -------- | ----------- |
|
||||||
|
| `presentationId` | string | Yes | The ID of the presentation |
|
||||||
|
| `pageObjectId` | string | Yes | The object ID of the slide/page to retrieve |
|
||||||
|
|
||||||
|
#### Output
|
||||||
|
|
||||||
|
| Parameter | Type | Description |
|
||||||
|
| --------- | ---- | ----------- |
|
||||||
|
| `objectId` | string | The object ID of the page |
|
||||||
|
| `pageType` | string | The type of page \(SLIDE, MASTER, LAYOUT, NOTES, NOTES_MASTER\) |
|
||||||
|
| `pageElements` | array | Array of page elements \(shapes, images, tables, etc.\) on this page |
|
||||||
|
| `slideProperties` | object | Properties specific to slides \(layout, master, notes\) |
|
||||||
|
| ↳ `layoutObjectId` | string | Object ID of the layout this slide is based on |
|
||||||
|
| ↳ `masterObjectId` | string | Object ID of the master this slide is based on |
|
||||||
|
| ↳ `notesPage` | json | The notes page associated with the slide |
|
||||||
|
| `metadata` | object | Operation metadata including presentation ID and URL |
|
||||||
|
| ↳ `presentationId` | string | The presentation ID |
|
||||||
|
| ↳ `url` | string | URL to the presentation |
|
||||||
|
|
||||||
|
### `google_slides_delete_object`
|
||||||
|
|
||||||
|
Delete a page element (shape, image, table, etc.) or an entire slide from a Google Slides presentation
|
||||||
|
|
||||||
|
#### Input
|
||||||
|
|
||||||
|
| Parameter | Type | Required | Description |
|
||||||
|
| --------- | ---- | -------- | ----------- |
|
||||||
|
| `presentationId` | string | Yes | The ID of the presentation |
|
||||||
|
| `objectId` | string | Yes | The object ID of the element or slide to delete |
|
||||||
|
|
||||||
|
#### Output
|
||||||
|
|
||||||
|
| Parameter | Type | Description |
|
||||||
|
| --------- | ---- | ----------- |
|
||||||
|
| `deleted` | boolean | Whether the object was successfully deleted |
|
||||||
|
| `objectId` | string | The object ID that was deleted |
|
||||||
|
| `metadata` | object | Operation metadata including presentation ID and URL |
|
||||||
|
| ↳ `presentationId` | string | The presentation ID |
|
||||||
|
| ↳ `url` | string | URL to the presentation |
|
||||||
|
|
||||||
|
### `google_slides_duplicate_object`
|
||||||
|
|
||||||
|
Duplicate an object (slide, shape, image, table, etc.) in a Google Slides presentation
|
||||||
|
|
||||||
|
#### Input
|
||||||
|
|
||||||
|
| Parameter | Type | Required | Description |
|
||||||
|
| --------- | ---- | -------- | ----------- |
|
||||||
|
| `presentationId` | string | Yes | The ID of the presentation |
|
||||||
|
| `objectId` | string | Yes | The object ID of the element or slide to duplicate |
|
||||||
|
| `objectIds` | string | No | Optional JSON object mapping source object IDs \(within the slide being duplicated\) to new object IDs for the duplicates. Format: \{"sourceId1":"newId1","sourceId2":"newId2"\} |
|
||||||
|
| `Format` | string | No | No description |
|
||||||
|
|
||||||
|
#### Output
|
||||||
|
|
||||||
|
| Parameter | Type | Description |
|
||||||
|
| --------- | ---- | ----------- |
|
||||||
|
| `duplicatedObjectId` | string | The object ID of the newly created duplicate |
|
||||||
|
| `metadata` | object | Operation metadata including presentation ID and source object ID |
|
||||||
|
| ↳ `presentationId` | string | The presentation ID |
|
||||||
|
| ↳ `sourceObjectId` | string | The original object ID that was duplicated |
|
||||||
|
| ↳ `url` | string | URL to the presentation |
|
||||||
|
|
||||||
|
### `google_slides_update_slides_position`
|
||||||
|
|
||||||
|
Move one or more slides to a new position in a Google Slides presentation
|
||||||
|
|
||||||
|
#### Input
|
||||||
|
|
||||||
|
| Parameter | Type | Required | Description |
|
||||||
|
| --------- | ---- | -------- | ----------- |
|
||||||
|
| `presentationId` | string | Yes | The ID of the presentation |
|
||||||
|
| `slideObjectIds` | string | Yes | Comma-separated list of slide object IDs to move. The slides will maintain their relative order. |
|
||||||
|
| `insertionIndex` | number | Yes | The zero-based index where the slides should be moved. All slides with indices greater than or equal to this will be shifted right. |
|
||||||
|
|
||||||
|
#### Output
|
||||||
|
|
||||||
|
| Parameter | Type | Description |
|
||||||
|
| --------- | ---- | ----------- |
|
||||||
|
| `moved` | boolean | Whether the slides were successfully moved |
|
||||||
|
| `slideObjectIds` | array | The slide object IDs that were moved |
|
||||||
|
| `insertionIndex` | number | The index where the slides were moved to |
|
||||||
|
| `metadata` | object | Operation metadata including presentation ID and URL |
|
||||||
|
| ↳ `presentationId` | string | The presentation ID |
|
||||||
|
| ↳ `url` | string | URL to the presentation |
|
||||||
|
|
||||||
|
### `google_slides_create_table`
|
||||||
|
|
||||||
|
Create a new table on a slide in a Google Slides presentation
|
||||||
|
|
||||||
|
#### Input
|
||||||
|
|
||||||
|
| Parameter | Type | Required | Description |
|
||||||
|
| --------- | ---- | -------- | ----------- |
|
||||||
|
| `presentationId` | string | Yes | The ID of the presentation |
|
||||||
|
| `pageObjectId` | string | Yes | The object ID of the slide/page to add the table to |
|
||||||
|
| `rows` | number | Yes | Number of rows in the table \(minimum 1\) |
|
||||||
|
| `columns` | number | Yes | Number of columns in the table \(minimum 1\) |
|
||||||
|
| `width` | number | No | Width of the table in points \(default: 400\) |
|
||||||
|
| `height` | number | No | Height of the table in points \(default: 200\) |
|
||||||
|
| `positionX` | number | No | X position from the left edge in points \(default: 100\) |
|
||||||
|
| `positionY` | number | No | Y position from the top edge in points \(default: 100\) |
|
||||||
|
|
||||||
|
#### Output
|
||||||
|
|
||||||
|
| Parameter | Type | Description |
|
||||||
|
| --------- | ---- | ----------- |
|
||||||
|
| `tableId` | string | The object ID of the newly created table |
|
||||||
|
| `rows` | number | Number of rows in the table |
|
||||||
|
| `columns` | number | Number of columns in the table |
|
||||||
|
| `metadata` | object | Operation metadata including presentation ID and page object ID |
|
||||||
|
| ↳ `presentationId` | string | The presentation ID |
|
||||||
|
| ↳ `pageObjectId` | string | The page object ID where the table was created |
|
||||||
|
| ↳ `url` | string | URL to the presentation |
|
||||||
|
|
||||||
|
### `google_slides_create_shape`
|
||||||
|
|
||||||
|
Create a shape (rectangle, ellipse, text box, arrow, etc.) on a slide in a Google Slides presentation
|
||||||
|
|
||||||
|
#### Input
|
||||||
|
|
||||||
|
| Parameter | Type | Required | Description |
|
||||||
|
| --------- | ---- | -------- | ----------- |
|
||||||
|
| `presentationId` | string | Yes | The ID of the presentation |
|
||||||
|
| `pageObjectId` | string | Yes | The object ID of the slide/page to add the shape to |
|
||||||
|
| `shapeType` | string | Yes | The type of shape to create. Common types: TEXT_BOX, RECTANGLE, ROUND_RECTANGLE, ELLIPSE, TRIANGLE, DIAMOND, STAR_5, ARROW_EAST, HEART, CLOUD |
|
||||||
|
| `width` | number | No | Width of the shape in points \(default: 200\) |
|
||||||
|
| `height` | number | No | Height of the shape in points \(default: 100\) |
|
||||||
|
| `positionX` | number | No | X position from the left edge in points \(default: 100\) |
|
||||||
|
| `positionY` | number | No | Y position from the top edge in points \(default: 100\) |
|
||||||
|
|
||||||
|
#### Output
|
||||||
|
|
||||||
|
| Parameter | Type | Description |
|
||||||
|
| --------- | ---- | ----------- |
|
||||||
|
| `shapeId` | string | The object ID of the newly created shape |
|
||||||
|
| `shapeType` | string | The type of shape that was created |
|
||||||
|
| `metadata` | object | Operation metadata including presentation ID and page object ID |
|
||||||
|
| ↳ `presentationId` | string | The presentation ID |
|
||||||
|
| ↳ `pageObjectId` | string | The page object ID where the shape was created |
|
||||||
|
| ↳ `url` | string | URL to the presentation |
|
||||||
|
|
||||||
|
### `google_slides_insert_text`
|
||||||
|
|
||||||
|
Insert text into a shape or table cell in a Google Slides presentation. Use this to add text to text boxes, shapes, or table cells.
|
||||||
|
|
||||||
|
#### Input
|
||||||
|
|
||||||
|
| Parameter | Type | Required | Description |
|
||||||
|
| --------- | ---- | -------- | ----------- |
|
||||||
|
| `presentationId` | string | Yes | The ID of the presentation |
|
||||||
|
| `objectId` | string | Yes | The object ID of the shape or table cell to insert text into. For table cells, use the cell object ID. |
|
||||||
|
| `text` | string | Yes | The text to insert |
|
||||||
|
| `insertionIndex` | number | No | The zero-based index at which to insert the text. If not specified, text is inserted at the beginning \(index 0\). |
|
||||||
|
|
||||||
|
#### Output
|
||||||
|
|
||||||
|
| Parameter | Type | Description |
|
||||||
|
| --------- | ---- | ----------- |
|
||||||
|
| `inserted` | boolean | Whether the text was successfully inserted |
|
||||||
|
| `objectId` | string | The object ID where text was inserted |
|
||||||
|
| `text` | string | The text that was inserted |
|
||||||
|
| `metadata` | object | Operation metadata including presentation ID and URL |
|
||||||
|
| ↳ `presentationId` | string | The presentation ID |
|
||||||
|
| ↳ `url` | string | URL to the presentation |
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -36,43 +36,47 @@ Connect Google Vault to create exports, list exports, and manage holds within ma
|
|||||||
|
|
||||||
### `google_vault_create_matters_export`
|
### `google_vault_create_matters_export`
|
||||||
|
|
||||||
|
Create an export in a matter
|
||||||
|
|
||||||
#### Input
|
#### Input
|
||||||
|
|
||||||
| Parameter | Type | Required | Description |
|
| Parameter | Type | Required | Description |
|
||||||
| --------- | ---- | -------- | ----------- |
|
| --------- | ---- | -------- | ----------- |
|
||||||
|
| `matterId` | string | Yes | The matter ID |
|
||||||
|
| `exportName` | string | Yes | Name for the export \(avoid special characters\) |
|
||||||
|
| `corpus` | string | Yes | Data corpus to export \(MAIL, DRIVE, GROUPS, HANGOUTS_CHAT, VOICE\) |
|
||||||
|
| `accountEmails` | string | No | Comma-separated list of user emails to scope export |
|
||||||
|
| `orgUnitId` | string | No | Organization unit ID to scope export \(alternative to emails\) |
|
||||||
|
| `startTime` | string | No | Start time for date filtering \(ISO 8601 format, e.g., 2024-01-01T00:00:00Z\) |
|
||||||
|
| `endTime` | string | No | End time for date filtering \(ISO 8601 format, e.g., 2024-12-31T23:59:59Z\) |
|
||||||
|
| `terms` | string | No | Search query terms to filter exported content |
|
||||||
|
|
||||||
#### Output
|
#### Output
|
||||||
|
|
||||||
| Parameter | Type | Description |
|
| Parameter | Type | Description |
|
||||||
| --------- | ---- | ----------- |
|
| --------- | ---- | ----------- |
|
||||||
| `matters` | json | Array of matter objects \(for list_matters\) |
|
| `export` | json | Created export object |
|
||||||
| `exports` | json | Array of export objects \(for list_matters_export\) |
|
|
||||||
| `holds` | json | Array of hold objects \(for list_matters_holds\) |
|
|
||||||
| `matter` | json | Created matter object \(for create_matters\) |
|
|
||||||
| `export` | json | Created export object \(for create_matters_export\) |
|
|
||||||
| `hold` | json | Created hold object \(for create_matters_holds\) |
|
|
||||||
| `file` | json | Downloaded export file \(UserFile\) from execution files |
|
|
||||||
| `nextPageToken` | string | Token for fetching next page of results \(for list operations\) |
|
|
||||||
|
|
||||||
### `google_vault_list_matters_export`
|
### `google_vault_list_matters_export`
|
||||||
|
|
||||||
|
List exports for a matter
|
||||||
|
|
||||||
#### Input
|
#### Input
|
||||||
|
|
||||||
| Parameter | Type | Required | Description |
|
| Parameter | Type | Required | Description |
|
||||||
| --------- | ---- | -------- | ----------- |
|
| --------- | ---- | -------- | ----------- |
|
||||||
|
| `matterId` | string | Yes | The matter ID |
|
||||||
|
| `pageSize` | number | No | Number of exports to return per page |
|
||||||
|
| `pageToken` | string | No | Token for pagination |
|
||||||
|
| `exportId` | string | No | Optional export ID to fetch a specific export |
|
||||||
|
|
||||||
#### Output
|
#### Output
|
||||||
|
|
||||||
| Parameter | Type | Description |
|
| Parameter | Type | Description |
|
||||||
| --------- | ---- | ----------- |
|
| --------- | ---- | ----------- |
|
||||||
| `matters` | json | Array of matter objects \(for list_matters\) |
|
| `exports` | json | Array of export objects |
|
||||||
| `exports` | json | Array of export objects \(for list_matters_export\) |
|
| `export` | json | Single export object \(when exportId is provided\) |
|
||||||
| `holds` | json | Array of hold objects \(for list_matters_holds\) |
|
| `nextPageToken` | string | Token for fetching next page of results |
|
||||||
| `matter` | json | Created matter object \(for create_matters\) |
|
|
||||||
| `export` | json | Created export object \(for create_matters_export\) |
|
|
||||||
| `hold` | json | Created hold object \(for create_matters_holds\) |
|
|
||||||
| `file` | json | Downloaded export file \(UserFile\) from execution files |
|
|
||||||
| `nextPageToken` | string | Token for fetching next page of results \(for list operations\) |
|
|
||||||
|
|
||||||
### `google_vault_download_export_file`
|
### `google_vault_download_export_file`
|
||||||
|
|
||||||
@@ -82,10 +86,10 @@ Download a single file from a Google Vault export (GCS object)
|
|||||||
|
|
||||||
| Parameter | Type | Required | Description |
|
| Parameter | Type | Required | Description |
|
||||||
| --------- | ---- | -------- | ----------- |
|
| --------- | ---- | -------- | ----------- |
|
||||||
| `matterId` | string | Yes | No description |
|
| `matterId` | string | Yes | The matter ID |
|
||||||
| `bucketName` | string | Yes | No description |
|
| `bucketName` | string | Yes | GCS bucket name from cloudStorageSink.files.bucketName |
|
||||||
| `objectName` | string | Yes | No description |
|
| `objectName` | string | Yes | GCS object name from cloudStorageSink.files.objectName |
|
||||||
| `fileName` | string | No | No description |
|
| `fileName` | string | No | Optional filename override for the downloaded file |
|
||||||
|
|
||||||
#### Output
|
#### Output
|
||||||
|
|
||||||
@@ -95,82 +99,84 @@ Download a single file from a Google Vault export (GCS object)
|
|||||||
|
|
||||||
### `google_vault_create_matters_holds`
|
### `google_vault_create_matters_holds`
|
||||||
|
|
||||||
|
Create a hold in a matter
|
||||||
|
|
||||||
#### Input
|
#### Input
|
||||||
|
|
||||||
| Parameter | Type | Required | Description |
|
| Parameter | Type | Required | Description |
|
||||||
| --------- | ---- | -------- | ----------- |
|
| --------- | ---- | -------- | ----------- |
|
||||||
|
| `matterId` | string | Yes | The matter ID |
|
||||||
|
| `holdName` | string | Yes | Name for the hold |
|
||||||
|
| `corpus` | string | Yes | Data corpus to hold \(MAIL, DRIVE, GROUPS, HANGOUTS_CHAT, VOICE\) |
|
||||||
|
| `accountEmails` | string | No | Comma-separated list of user emails to put on hold |
|
||||||
|
| `orgUnitId` | string | No | Organization unit ID to put on hold \(alternative to accounts\) |
|
||||||
|
| `terms` | string | No | Search terms to filter held content \(for MAIL and GROUPS corpus\) |
|
||||||
|
| `startTime` | string | No | Start time for date filtering \(ISO 8601 format, for MAIL and GROUPS corpus\) |
|
||||||
|
| `endTime` | string | No | End time for date filtering \(ISO 8601 format, for MAIL and GROUPS corpus\) |
|
||||||
|
| `includeSharedDrives` | boolean | No | Include files in shared drives \(for DRIVE corpus\) |
|
||||||
|
|
||||||
#### Output
|
#### Output
|
||||||
|
|
||||||
| Parameter | Type | Description |
|
| Parameter | Type | Description |
|
||||||
| --------- | ---- | ----------- |
|
| --------- | ---- | ----------- |
|
||||||
| `matters` | json | Array of matter objects \(for list_matters\) |
|
| `hold` | json | Created hold object |
|
||||||
| `exports` | json | Array of export objects \(for list_matters_export\) |
|
|
||||||
| `holds` | json | Array of hold objects \(for list_matters_holds\) |
|
|
||||||
| `matter` | json | Created matter object \(for create_matters\) |
|
|
||||||
| `export` | json | Created export object \(for create_matters_export\) |
|
|
||||||
| `hold` | json | Created hold object \(for create_matters_holds\) |
|
|
||||||
| `file` | json | Downloaded export file \(UserFile\) from execution files |
|
|
||||||
| `nextPageToken` | string | Token for fetching next page of results \(for list operations\) |
|
|
||||||
|
|
||||||
### `google_vault_list_matters_holds`
|
### `google_vault_list_matters_holds`
|
||||||
|
|
||||||
|
List holds for a matter
|
||||||
|
|
||||||
#### Input
|
#### Input
|
||||||
|
|
||||||
| Parameter | Type | Required | Description |
|
| Parameter | Type | Required | Description |
|
||||||
| --------- | ---- | -------- | ----------- |
|
| --------- | ---- | -------- | ----------- |
|
||||||
|
| `matterId` | string | Yes | The matter ID |
|
||||||
|
| `pageSize` | number | No | Number of holds to return per page |
|
||||||
|
| `pageToken` | string | No | Token for pagination |
|
||||||
|
| `holdId` | string | No | Optional hold ID to fetch a specific hold |
|
||||||
|
|
||||||
#### Output
|
#### Output
|
||||||
|
|
||||||
| Parameter | Type | Description |
|
| Parameter | Type | Description |
|
||||||
| --------- | ---- | ----------- |
|
| --------- | ---- | ----------- |
|
||||||
| `matters` | json | Array of matter objects \(for list_matters\) |
|
| `holds` | json | Array of hold objects |
|
||||||
| `exports` | json | Array of export objects \(for list_matters_export\) |
|
| `hold` | json | Single hold object \(when holdId is provided\) |
|
||||||
| `holds` | json | Array of hold objects \(for list_matters_holds\) |
|
| `nextPageToken` | string | Token for fetching next page of results |
|
||||||
| `matter` | json | Created matter object \(for create_matters\) |
|
|
||||||
| `export` | json | Created export object \(for create_matters_export\) |
|
|
||||||
| `hold` | json | Created hold object \(for create_matters_holds\) |
|
|
||||||
| `file` | json | Downloaded export file \(UserFile\) from execution files |
|
|
||||||
| `nextPageToken` | string | Token for fetching next page of results \(for list operations\) |
|
|
||||||
|
|
||||||
### `google_vault_create_matters`
|
### `google_vault_create_matters`
|
||||||
|
|
||||||
|
Create a new matter in Google Vault
|
||||||
|
|
||||||
#### Input
|
#### Input
|
||||||
|
|
||||||
| Parameter | Type | Required | Description |
|
| Parameter | Type | Required | Description |
|
||||||
| --------- | ---- | -------- | ----------- |
|
| --------- | ---- | -------- | ----------- |
|
||||||
|
| `name` | string | Yes | Name for the new matter |
|
||||||
|
| `description` | string | No | Optional description for the matter |
|
||||||
|
|
||||||
#### Output
|
#### Output
|
||||||
|
|
||||||
| Parameter | Type | Description |
|
| Parameter | Type | Description |
|
||||||
| --------- | ---- | ----------- |
|
| --------- | ---- | ----------- |
|
||||||
| `matters` | json | Array of matter objects \(for list_matters\) |
|
| `matter` | json | Created matter object |
|
||||||
| `exports` | json | Array of export objects \(for list_matters_export\) |
|
|
||||||
| `holds` | json | Array of hold objects \(for list_matters_holds\) |
|
|
||||||
| `matter` | json | Created matter object \(for create_matters\) |
|
|
||||||
| `export` | json | Created export object \(for create_matters_export\) |
|
|
||||||
| `hold` | json | Created hold object \(for create_matters_holds\) |
|
|
||||||
| `file` | json | Downloaded export file \(UserFile\) from execution files |
|
|
||||||
| `nextPageToken` | string | Token for fetching next page of results \(for list operations\) |
|
|
||||||
|
|
||||||
### `google_vault_list_matters`
|
### `google_vault_list_matters`
|
||||||
|
|
||||||
|
List matters, or get a specific matter if matterId is provided
|
||||||
|
|
||||||
#### Input
|
#### Input
|
||||||
|
|
||||||
| Parameter | Type | Required | Description |
|
| Parameter | Type | Required | Description |
|
||||||
| --------- | ---- | -------- | ----------- |
|
| --------- | ---- | -------- | ----------- |
|
||||||
|
| `pageSize` | number | No | Number of matters to return per page |
|
||||||
|
| `pageToken` | string | No | Token for pagination |
|
||||||
|
| `matterId` | string | No | Optional matter ID to fetch a specific matter |
|
||||||
|
|
||||||
#### Output
|
#### Output
|
||||||
|
|
||||||
| Parameter | Type | Description |
|
| Parameter | Type | Description |
|
||||||
| --------- | ---- | ----------- |
|
| --------- | ---- | ----------- |
|
||||||
| `matters` | json | Array of matter objects \(for list_matters\) |
|
| `matters` | json | Array of matter objects |
|
||||||
| `exports` | json | Array of export objects \(for list_matters_export\) |
|
| `matter` | json | Single matter object \(when matterId is provided\) |
|
||||||
| `holds` | json | Array of hold objects \(for list_matters_holds\) |
|
| `nextPageToken` | string | Token for fetching next page of results |
|
||||||
| `matter` | json | Created matter object \(for create_matters\) |
|
|
||||||
| `export` | json | Created export object \(for create_matters_export\) |
|
|
||||||
| `hold` | json | Created hold object \(for create_matters_holds\) |
|
|
||||||
| `file` | json | Downloaded export file \(UserFile\) from execution files |
|
|
||||||
| `nextPageToken` | string | Token for fetching next page of results \(for list operations\) |
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -51,6 +51,7 @@ Search for similar content in a knowledge base using vector similarity
|
|||||||
| `properties` | string | No | No description |
|
| `properties` | string | No | No description |
|
||||||
| `tagName` | string | No | No description |
|
| `tagName` | string | No | No description |
|
||||||
| `tagValue` | string | No | No description |
|
| `tagValue` | string | No | No description |
|
||||||
|
| `tagFilters` | string | No | No description |
|
||||||
|
|
||||||
#### Output
|
#### Output
|
||||||
|
|
||||||
@@ -108,19 +109,8 @@ Create a new document in a knowledge base
|
|||||||
| `knowledgeBaseId` | string | Yes | ID of the knowledge base containing the document |
|
| `knowledgeBaseId` | string | Yes | ID of the knowledge base containing the document |
|
||||||
| `name` | string | Yes | Name of the document |
|
| `name` | string | Yes | Name of the document |
|
||||||
| `content` | string | Yes | Content of the document |
|
| `content` | string | Yes | Content of the document |
|
||||||
| `tag1` | string | No | Tag 1 value for the document |
|
| `documentTags` | object | No | Document tags |
|
||||||
| `tag2` | string | No | Tag 2 value for the document |
|
| `documentTags` | string | No | No description |
|
||||||
| `tag3` | string | No | Tag 3 value for the document |
|
|
||||||
| `tag4` | string | No | Tag 4 value for the document |
|
|
||||||
| `tag5` | string | No | Tag 5 value for the document |
|
|
||||||
| `tag6` | string | No | Tag 6 value for the document |
|
|
||||||
| `tag7` | string | No | Tag 7 value for the document |
|
|
||||||
| `documentTagsData` | array | No | Structured tag data with names, types, and values |
|
|
||||||
| `items` | object | No | No description |
|
|
||||||
| `properties` | string | No | No description |
|
|
||||||
| `tagName` | string | No | No description |
|
|
||||||
| `tagValue` | string | No | No description |
|
|
||||||
| `tagType` | string | No | No description |
|
|
||||||
|
|
||||||
#### Output
|
#### Output
|
||||||
|
|
||||||
|
|||||||
@@ -45,8 +45,7 @@ Read data from a specific sheet in a Microsoft Excel spreadsheet
|
|||||||
| Parameter | Type | Required | Description |
|
| Parameter | Type | Required | Description |
|
||||||
| --------- | ---- | -------- | ----------- |
|
| --------- | ---- | -------- | ----------- |
|
||||||
| `spreadsheetId` | string | Yes | The ID of the spreadsheet to read from |
|
| `spreadsheetId` | string | Yes | The ID of the spreadsheet to read from |
|
||||||
| `sheetName` | string | Yes | The name of the sheet/tab to read from |
|
| `range` | string | No | The range of cells to read from. Accepts "SheetName!A1:B2" for explicit ranges or just "SheetName" to read the used range of that sheet. If omitted, reads the used range of the first sheet. |
|
||||||
| `cellRange` | string | No | The cell range to read \(e.g., "A1:D10"\). If not specified, reads the entire used range. |
|
|
||||||
|
|
||||||
#### Output
|
#### Output
|
||||||
|
|
||||||
@@ -68,9 +67,8 @@ Write data to a specific sheet in a Microsoft Excel spreadsheet
|
|||||||
| Parameter | Type | Required | Description |
|
| Parameter | Type | Required | Description |
|
||||||
| --------- | ---- | -------- | ----------- |
|
| --------- | ---- | -------- | ----------- |
|
||||||
| `spreadsheetId` | string | Yes | The ID of the spreadsheet to write to |
|
| `spreadsheetId` | string | Yes | The ID of the spreadsheet to write to |
|
||||||
| `sheetName` | string | Yes | The name of the sheet/tab to write to |
|
| `range` | string | No | The range of cells to write to |
|
||||||
| `cellRange` | string | No | The cell range to write to \(e.g., "A1:D10", "A1"\). Defaults to "A1" if not specified. |
|
| `values` | array | Yes | The data to write to the spreadsheet |
|
||||||
| `values` | array | Yes | The data to write as a 2D array \(e.g. \[\["Name", "Age"\], \["Alice", 30\], \["Bob", 25\]\]\) or array of objects. |
|
|
||||||
| `valueInputOption` | string | No | The format of the data to write |
|
| `valueInputOption` | string | No | The format of the data to write |
|
||||||
| `includeValuesInResponse` | boolean | No | Whether to include the written values in the response |
|
| `includeValuesInResponse` | boolean | No | Whether to include the written values in the response |
|
||||||
|
|
||||||
|
|||||||
@@ -84,9 +84,10 @@ Send messages to Slack channels or direct messages. Supports Slack mrkdwn format
|
|||||||
| Parameter | Type | Required | Description |
|
| Parameter | Type | Required | Description |
|
||||||
| --------- | ---- | -------- | ----------- |
|
| --------- | ---- | -------- | ----------- |
|
||||||
| `authMethod` | string | No | Authentication method: oauth or bot_token |
|
| `authMethod` | string | No | Authentication method: oauth or bot_token |
|
||||||
|
| `destinationType` | string | No | Destination type: channel or dm |
|
||||||
| `botToken` | string | No | Bot token for Custom Bot |
|
| `botToken` | string | No | Bot token for Custom Bot |
|
||||||
| `channel` | string | No | Target Slack channel \(e.g., #general\) |
|
| `channel` | string | No | Target Slack channel \(e.g., #general\) |
|
||||||
| `userId` | string | No | Target Slack user ID for direct messages \(e.g., U1234567890\) |
|
| `dmUserId` | string | No | Target Slack user for direct messages |
|
||||||
| `text` | string | Yes | Message text to send \(supports Slack mrkdwn formatting\) |
|
| `text` | string | Yes | Message text to send \(supports Slack mrkdwn formatting\) |
|
||||||
| `thread_ts` | string | No | Thread timestamp to reply to \(creates thread reply\) |
|
| `thread_ts` | string | No | Thread timestamp to reply to \(creates thread reply\) |
|
||||||
| `files` | file[] | No | Files to attach to the message |
|
| `files` | file[] | No | Files to attach to the message |
|
||||||
@@ -132,9 +133,10 @@ Read the latest messages from Slack channels. Retrieve conversation history with
|
|||||||
| Parameter | Type | Required | Description |
|
| Parameter | Type | Required | Description |
|
||||||
| --------- | ---- | -------- | ----------- |
|
| --------- | ---- | -------- | ----------- |
|
||||||
| `authMethod` | string | No | Authentication method: oauth or bot_token |
|
| `authMethod` | string | No | Authentication method: oauth or bot_token |
|
||||||
|
| `destinationType` | string | No | Destination type: channel or dm |
|
||||||
| `botToken` | string | No | Bot token for Custom Bot |
|
| `botToken` | string | No | Bot token for Custom Bot |
|
||||||
| `channel` | string | No | Slack channel to read messages from \(e.g., #general\) |
|
| `channel` | string | No | Slack channel to read messages from \(e.g., #general\) |
|
||||||
| `userId` | string | No | User ID for DM conversation \(e.g., U1234567890\) |
|
| `dmUserId` | string | No | Target Slack user for DM conversation |
|
||||||
| `limit` | number | No | Number of messages to retrieve \(default: 10, max: 15\) |
|
| `limit` | number | No | Number of messages to retrieve \(default: 10, max: 15\) |
|
||||||
| `oldest` | string | No | Start of time range \(timestamp\) |
|
| `oldest` | string | No | Start of time range \(timestamp\) |
|
||||||
| `latest` | string | No | End of time range \(timestamp\) |
|
| `latest` | string | No | End of time range \(timestamp\) |
|
||||||
|
|||||||
@@ -11,10 +11,8 @@
|
|||||||
"next-env.d.ts",
|
"next-env.d.ts",
|
||||||
"**/*.ts",
|
"**/*.ts",
|
||||||
"**/*.tsx",
|
"**/*.tsx",
|
||||||
".next/types/**/*.ts",
|
|
||||||
"content/docs/execution/index.mdx",
|
"content/docs/execution/index.mdx",
|
||||||
"content/docs/connections/index.mdx",
|
"content/docs/connections/index.mdx"
|
||||||
".next/dev/types/**/*.ts"
|
|
||||||
],
|
],
|
||||||
"exclude": ["node_modules"]
|
"exclude": ["node_modules", ".next"]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import { getSession } from '@/lib/auth'
|
|||||||
import { generateChatTitle } from '@/lib/copilot/chat-title'
|
import { generateChatTitle } from '@/lib/copilot/chat-title'
|
||||||
import { getCopilotModel } from '@/lib/copilot/config'
|
import { getCopilotModel } from '@/lib/copilot/config'
|
||||||
import { SIM_AGENT_API_URL_DEFAULT, SIM_AGENT_VERSION } from '@/lib/copilot/constants'
|
import { SIM_AGENT_API_URL_DEFAULT, SIM_AGENT_VERSION } from '@/lib/copilot/constants'
|
||||||
|
import { COPILOT_MODEL_IDS, COPILOT_REQUEST_MODES } from '@/lib/copilot/models'
|
||||||
import {
|
import {
|
||||||
authenticateCopilotRequestSessionOnly,
|
authenticateCopilotRequestSessionOnly,
|
||||||
createBadRequestResponse,
|
createBadRequestResponse,
|
||||||
@@ -40,34 +41,8 @@ const ChatMessageSchema = z.object({
|
|||||||
userMessageId: z.string().optional(), // ID from frontend for the user message
|
userMessageId: z.string().optional(), // ID from frontend for the user message
|
||||||
chatId: z.string().optional(),
|
chatId: z.string().optional(),
|
||||||
workflowId: z.string().min(1, 'Workflow ID is required'),
|
workflowId: z.string().min(1, 'Workflow ID is required'),
|
||||||
model: z
|
model: z.enum(COPILOT_MODEL_IDS).optional().default('claude-4.5-opus'),
|
||||||
.enum([
|
mode: z.enum(COPILOT_REQUEST_MODES).optional().default('agent'),
|
||||||
'gpt-5-fast',
|
|
||||||
'gpt-5',
|
|
||||||
'gpt-5-medium',
|
|
||||||
'gpt-5-high',
|
|
||||||
'gpt-5.1-fast',
|
|
||||||
'gpt-5.1',
|
|
||||||
'gpt-5.1-medium',
|
|
||||||
'gpt-5.1-high',
|
|
||||||
'gpt-5-codex',
|
|
||||||
'gpt-5.1-codex',
|
|
||||||
'gpt-5.2',
|
|
||||||
'gpt-5.2-codex',
|
|
||||||
'gpt-5.2-pro',
|
|
||||||
'gpt-4o',
|
|
||||||
'gpt-4.1',
|
|
||||||
'o3',
|
|
||||||
'claude-4-sonnet',
|
|
||||||
'claude-4.5-haiku',
|
|
||||||
'claude-4.5-sonnet',
|
|
||||||
'claude-4.5-opus',
|
|
||||||
'claude-4.1-opus',
|
|
||||||
'gemini-3-pro',
|
|
||||||
])
|
|
||||||
.optional()
|
|
||||||
.default('claude-4.5-opus'),
|
|
||||||
mode: z.enum(['ask', 'agent', 'plan']).optional().default('agent'),
|
|
||||||
prefetch: z.boolean().optional(),
|
prefetch: z.boolean().optional(),
|
||||||
createNewChat: z.boolean().optional().default(false),
|
createNewChat: z.boolean().optional().default(false),
|
||||||
stream: z.boolean().optional().default(true),
|
stream: z.boolean().optional().default(true),
|
||||||
@@ -295,7 +270,8 @@ export async function POST(req: NextRequest) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const defaults = getCopilotModel('chat')
|
const defaults = getCopilotModel('chat')
|
||||||
const modelToUse = env.COPILOT_MODEL || defaults.model
|
const selectedModel = model || defaults.model
|
||||||
|
const envModel = env.COPILOT_MODEL || defaults.model
|
||||||
|
|
||||||
let providerConfig: CopilotProviderConfig | undefined
|
let providerConfig: CopilotProviderConfig | undefined
|
||||||
const providerEnv = env.COPILOT_PROVIDER as any
|
const providerEnv = env.COPILOT_PROVIDER as any
|
||||||
@@ -304,7 +280,7 @@ export async function POST(req: NextRequest) {
|
|||||||
if (providerEnv === 'azure-openai') {
|
if (providerEnv === 'azure-openai') {
|
||||||
providerConfig = {
|
providerConfig = {
|
||||||
provider: 'azure-openai',
|
provider: 'azure-openai',
|
||||||
model: modelToUse,
|
model: envModel,
|
||||||
apiKey: env.AZURE_OPENAI_API_KEY,
|
apiKey: env.AZURE_OPENAI_API_KEY,
|
||||||
apiVersion: 'preview',
|
apiVersion: 'preview',
|
||||||
endpoint: env.AZURE_OPENAI_ENDPOINT,
|
endpoint: env.AZURE_OPENAI_ENDPOINT,
|
||||||
@@ -312,7 +288,7 @@ export async function POST(req: NextRequest) {
|
|||||||
} else if (providerEnv === 'vertex') {
|
} else if (providerEnv === 'vertex') {
|
||||||
providerConfig = {
|
providerConfig = {
|
||||||
provider: 'vertex',
|
provider: 'vertex',
|
||||||
model: modelToUse,
|
model: envModel,
|
||||||
apiKey: env.COPILOT_API_KEY,
|
apiKey: env.COPILOT_API_KEY,
|
||||||
vertexProject: env.VERTEX_PROJECT,
|
vertexProject: env.VERTEX_PROJECT,
|
||||||
vertexLocation: env.VERTEX_LOCATION,
|
vertexLocation: env.VERTEX_LOCATION,
|
||||||
@@ -320,12 +296,15 @@ export async function POST(req: NextRequest) {
|
|||||||
} else {
|
} else {
|
||||||
providerConfig = {
|
providerConfig = {
|
||||||
provider: providerEnv,
|
provider: providerEnv,
|
||||||
model: modelToUse,
|
model: selectedModel,
|
||||||
apiKey: env.COPILOT_API_KEY,
|
apiKey: env.COPILOT_API_KEY,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const effectiveMode = mode === 'agent' ? 'build' : mode
|
||||||
|
const transportMode = effectiveMode === 'build' ? 'agent' : effectiveMode
|
||||||
|
|
||||||
// Determine conversationId to use for this request
|
// Determine conversationId to use for this request
|
||||||
const effectiveConversationId =
|
const effectiveConversationId =
|
||||||
(currentChat?.conversationId as string | undefined) || conversationId
|
(currentChat?.conversationId as string | undefined) || conversationId
|
||||||
@@ -345,7 +324,7 @@ export async function POST(req: NextRequest) {
|
|||||||
}
|
}
|
||||||
} | null = null
|
} | null = null
|
||||||
|
|
||||||
if (mode === 'agent') {
|
if (effectiveMode === 'build') {
|
||||||
// Build base tools (executed locally, not deferred)
|
// Build base tools (executed locally, not deferred)
|
||||||
// Include function_execute for code execution capability
|
// Include function_execute for code execution capability
|
||||||
baseTools = [
|
baseTools = [
|
||||||
@@ -452,8 +431,8 @@ export async function POST(req: NextRequest) {
|
|||||||
userId: authenticatedUserId,
|
userId: authenticatedUserId,
|
||||||
stream: stream,
|
stream: stream,
|
||||||
streamToolCalls: true,
|
streamToolCalls: true,
|
||||||
model: model,
|
model: selectedModel,
|
||||||
mode: mode,
|
mode: transportMode,
|
||||||
messageId: userMessageIdToUse,
|
messageId: userMessageIdToUse,
|
||||||
version: SIM_AGENT_VERSION,
|
version: SIM_AGENT_VERSION,
|
||||||
...(providerConfig ? { provider: providerConfig } : {}),
|
...(providerConfig ? { provider: providerConfig } : {}),
|
||||||
@@ -477,7 +456,7 @@ export async function POST(req: NextRequest) {
|
|||||||
hasConversationId: !!effectiveConversationId,
|
hasConversationId: !!effectiveConversationId,
|
||||||
hasFileAttachments: processedFileContents.length > 0,
|
hasFileAttachments: processedFileContents.length > 0,
|
||||||
messageLength: message.length,
|
messageLength: message.length,
|
||||||
mode,
|
mode: effectiveMode,
|
||||||
hasTools: integrationTools.length > 0,
|
hasTools: integrationTools.length > 0,
|
||||||
toolCount: integrationTools.length,
|
toolCount: integrationTools.length,
|
||||||
hasBaseTools: baseTools.length > 0,
|
hasBaseTools: baseTools.length > 0,
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import { createLogger } from '@sim/logger'
|
|||||||
import { and, eq } from 'drizzle-orm'
|
import { and, eq } from 'drizzle-orm'
|
||||||
import { type NextRequest, NextResponse } from 'next/server'
|
import { type NextRequest, NextResponse } from 'next/server'
|
||||||
import { z } from 'zod'
|
import { z } from 'zod'
|
||||||
|
import { COPILOT_MODES } from '@/lib/copilot/models'
|
||||||
import {
|
import {
|
||||||
authenticateCopilotRequestSessionOnly,
|
authenticateCopilotRequestSessionOnly,
|
||||||
createInternalServerErrorResponse,
|
createInternalServerErrorResponse,
|
||||||
@@ -45,7 +46,7 @@ const UpdateMessagesSchema = z.object({
|
|||||||
planArtifact: z.string().nullable().optional(),
|
planArtifact: z.string().nullable().optional(),
|
||||||
config: z
|
config: z
|
||||||
.object({
|
.object({
|
||||||
mode: z.enum(['ask', 'build', 'plan']).optional(),
|
mode: z.enum(COPILOT_MODES).optional(),
|
||||||
model: z.string().optional(),
|
model: z.string().optional(),
|
||||||
})
|
})
|
||||||
.nullable()
|
.nullable()
|
||||||
|
|||||||
@@ -14,8 +14,7 @@ import {
|
|||||||
import { generateRequestId } from '@/lib/core/utils/request'
|
import { generateRequestId } from '@/lib/core/utils/request'
|
||||||
import { getEffectiveDecryptedEnv } from '@/lib/environment/utils'
|
import { getEffectiveDecryptedEnv } from '@/lib/environment/utils'
|
||||||
import { refreshTokenIfNeeded } from '@/app/api/auth/oauth/utils'
|
import { refreshTokenIfNeeded } from '@/app/api/auth/oauth/utils'
|
||||||
import { REFERENCE } from '@/executor/constants'
|
import { resolveEnvVarReferences } from '@/executor/utils/reference-validation'
|
||||||
import { createEnvVarPattern } from '@/executor/utils/reference-validation'
|
|
||||||
import { executeTool } from '@/tools'
|
import { executeTool } from '@/tools'
|
||||||
import { getTool, resolveToolId } from '@/tools/utils'
|
import { getTool, resolveToolId } from '@/tools/utils'
|
||||||
|
|
||||||
@@ -28,45 +27,6 @@ const ExecuteToolSchema = z.object({
|
|||||||
workflowId: z.string().optional(),
|
workflowId: z.string().optional(),
|
||||||
})
|
})
|
||||||
|
|
||||||
/**
|
|
||||||
* Resolves all {{ENV_VAR}} references in a value recursively
|
|
||||||
* Works with strings, arrays, and objects
|
|
||||||
*/
|
|
||||||
function resolveEnvVarReferences(value: any, envVars: Record<string, string>): any {
|
|
||||||
if (typeof value === 'string') {
|
|
||||||
// Check for exact match: entire string is "{{VAR_NAME}}"
|
|
||||||
const exactMatchPattern = new RegExp(
|
|
||||||
`^\\${REFERENCE.ENV_VAR_START}([^}]+)\\${REFERENCE.ENV_VAR_END}$`
|
|
||||||
)
|
|
||||||
const exactMatch = exactMatchPattern.exec(value)
|
|
||||||
if (exactMatch) {
|
|
||||||
const envVarName = exactMatch[1].trim()
|
|
||||||
return envVars[envVarName] ?? value
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check for embedded references: "prefix {{VAR}} suffix"
|
|
||||||
const envVarPattern = createEnvVarPattern()
|
|
||||||
return value.replace(envVarPattern, (match, varName) => {
|
|
||||||
const trimmedName = varName.trim()
|
|
||||||
return envVars[trimmedName] ?? match
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Array.isArray(value)) {
|
|
||||||
return value.map((item) => resolveEnvVarReferences(item, envVars))
|
|
||||||
}
|
|
||||||
|
|
||||||
if (value !== null && typeof value === 'object') {
|
|
||||||
const resolved: Record<string, any> = {}
|
|
||||||
for (const [key, val] of Object.entries(value)) {
|
|
||||||
resolved[key] = resolveEnvVarReferences(val, envVars)
|
|
||||||
}
|
|
||||||
return resolved
|
|
||||||
}
|
|
||||||
|
|
||||||
return value
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function POST(req: NextRequest) {
|
export async function POST(req: NextRequest) {
|
||||||
const tracker = createRequestTracker()
|
const tracker = createRequestTracker()
|
||||||
|
|
||||||
@@ -145,7 +105,17 @@ export async function POST(req: NextRequest) {
|
|||||||
|
|
||||||
// Build execution params starting with LLM-provided arguments
|
// Build execution params starting with LLM-provided arguments
|
||||||
// Resolve all {{ENV_VAR}} references in the arguments
|
// Resolve all {{ENV_VAR}} references in the arguments
|
||||||
const executionParams: Record<string, any> = resolveEnvVarReferences(toolArgs, decryptedEnvVars)
|
const executionParams: Record<string, any> = resolveEnvVarReferences(
|
||||||
|
toolArgs,
|
||||||
|
decryptedEnvVars,
|
||||||
|
{
|
||||||
|
resolveExactMatch: true,
|
||||||
|
allowEmbedded: true,
|
||||||
|
trimKeys: true,
|
||||||
|
onMissing: 'keep',
|
||||||
|
deep: true,
|
||||||
|
}
|
||||||
|
) as Record<string, any>
|
||||||
|
|
||||||
logger.info(`[${tracker.requestId}] Resolved env var references in arguments`, {
|
logger.info(`[${tracker.requestId}] Resolved env var references in arguments`, {
|
||||||
toolName,
|
toolName,
|
||||||
|
|||||||
@@ -2,12 +2,13 @@ import { createLogger } from '@sim/logger'
|
|||||||
import { eq } from 'drizzle-orm'
|
import { eq } from 'drizzle-orm'
|
||||||
import { type NextRequest, NextResponse } from 'next/server'
|
import { type NextRequest, NextResponse } from 'next/server'
|
||||||
import { getSession } from '@/lib/auth'
|
import { getSession } from '@/lib/auth'
|
||||||
|
import type { CopilotModelId } from '@/lib/copilot/models'
|
||||||
import { db } from '@/../../packages/db'
|
import { db } from '@/../../packages/db'
|
||||||
import { settings } from '@/../../packages/db/schema'
|
import { settings } from '@/../../packages/db/schema'
|
||||||
|
|
||||||
const logger = createLogger('CopilotUserModelsAPI')
|
const logger = createLogger('CopilotUserModelsAPI')
|
||||||
|
|
||||||
const DEFAULT_ENABLED_MODELS: Record<string, boolean> = {
|
const DEFAULT_ENABLED_MODELS: Record<CopilotModelId, boolean> = {
|
||||||
'gpt-4o': false,
|
'gpt-4o': false,
|
||||||
'gpt-4.1': false,
|
'gpt-4.1': false,
|
||||||
'gpt-5-fast': false,
|
'gpt-5-fast': false,
|
||||||
@@ -28,7 +29,7 @@ const DEFAULT_ENABLED_MODELS: Record<string, boolean> = {
|
|||||||
'claude-4.5-haiku': true,
|
'claude-4.5-haiku': true,
|
||||||
'claude-4.5-sonnet': true,
|
'claude-4.5-sonnet': true,
|
||||||
'claude-4.5-opus': true,
|
'claude-4.5-opus': true,
|
||||||
// 'claude-4.1-opus': true,
|
'claude-4.1-opus': false,
|
||||||
'gemini-3-pro': true,
|
'gemini-3-pro': true,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -54,7 +55,9 @@ export async function GET(request: NextRequest) {
|
|||||||
|
|
||||||
const mergedModels = { ...DEFAULT_ENABLED_MODELS }
|
const mergedModels = { ...DEFAULT_ENABLED_MODELS }
|
||||||
for (const [modelId, enabled] of Object.entries(userModelsMap)) {
|
for (const [modelId, enabled] of Object.entries(userModelsMap)) {
|
||||||
mergedModels[modelId] = enabled
|
if (modelId in mergedModels) {
|
||||||
|
mergedModels[modelId as CopilotModelId] = enabled
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const hasNewModels = Object.keys(DEFAULT_ENABLED_MODELS).some(
|
const hasNewModels = Object.keys(DEFAULT_ENABLED_MODELS).some(
|
||||||
|
|||||||
@@ -1,10 +1,11 @@
|
|||||||
import { db } from '@sim/db'
|
import { db } from '@sim/db'
|
||||||
import { templateCreators, user } from '@sim/db/schema'
|
import { templateCreators } from '@sim/db/schema'
|
||||||
import { createLogger } from '@sim/logger'
|
import { createLogger } from '@sim/logger'
|
||||||
import { eq } from 'drizzle-orm'
|
import { eq } from 'drizzle-orm'
|
||||||
import { type NextRequest, NextResponse } from 'next/server'
|
import { type NextRequest, NextResponse } from 'next/server'
|
||||||
import { getSession } from '@/lib/auth'
|
import { getSession } from '@/lib/auth'
|
||||||
import { generateRequestId } from '@/lib/core/utils/request'
|
import { generateRequestId } from '@/lib/core/utils/request'
|
||||||
|
import { verifyEffectiveSuperUser } from '@/lib/templates/permissions'
|
||||||
|
|
||||||
const logger = createLogger('CreatorVerificationAPI')
|
const logger = createLogger('CreatorVerificationAPI')
|
||||||
|
|
||||||
@@ -23,9 +24,8 @@ export async function POST(request: NextRequest, { params }: { params: Promise<{
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Check if user is a super user
|
// Check if user is a super user
|
||||||
const currentUser = await db.select().from(user).where(eq(user.id, session.user.id)).limit(1)
|
const { effectiveSuperUser } = await verifyEffectiveSuperUser(session.user.id)
|
||||||
|
if (!effectiveSuperUser) {
|
||||||
if (!currentUser[0]?.isSuperUser) {
|
|
||||||
logger.warn(`[${requestId}] Non-super user attempted to verify creator: ${id}`)
|
logger.warn(`[${requestId}] Non-super user attempted to verify creator: ${id}`)
|
||||||
return NextResponse.json({ error: 'Only super users can verify creators' }, { status: 403 })
|
return NextResponse.json({ error: 'Only super users can verify creators' }, { status: 403 })
|
||||||
}
|
}
|
||||||
@@ -76,9 +76,8 @@ export async function DELETE(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Check if user is a super user
|
// Check if user is a super user
|
||||||
const currentUser = await db.select().from(user).where(eq(user.id, session.user.id)).limit(1)
|
const { effectiveSuperUser } = await verifyEffectiveSuperUser(session.user.id)
|
||||||
|
if (!effectiveSuperUser) {
|
||||||
if (!currentUser[0]?.isSuperUser) {
|
|
||||||
logger.warn(`[${requestId}] Non-super user attempted to unverify creator: ${id}`)
|
logger.warn(`[${requestId}] Non-super user attempted to unverify creator: ${id}`)
|
||||||
return NextResponse.json({ error: 'Only super users can unverify creators' }, { status: 403 })
|
return NextResponse.json({ error: 'Only super users can unverify creators' }, { status: 403 })
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ import { preprocessExecution } from '@/lib/execution/preprocessing'
|
|||||||
import { LoggingSession } from '@/lib/logs/execution/logging-session'
|
import { LoggingSession } from '@/lib/logs/execution/logging-session'
|
||||||
import { normalizeInputFormatValue } from '@/lib/workflows/input-format'
|
import { normalizeInputFormatValue } from '@/lib/workflows/input-format'
|
||||||
import { createStreamingResponse } from '@/lib/workflows/streaming/streaming'
|
import { createStreamingResponse } from '@/lib/workflows/streaming/streaming'
|
||||||
|
import { isValidStartBlockType } from '@/lib/workflows/triggers/start-block-types'
|
||||||
import { setFormAuthCookie, validateFormAuth } from '@/app/api/form/utils'
|
import { setFormAuthCookie, validateFormAuth } from '@/app/api/form/utils'
|
||||||
import { createErrorResponse, createSuccessResponse } from '@/app/api/workflows/utils'
|
import { createErrorResponse, createSuccessResponse } from '@/app/api/workflows/utils'
|
||||||
|
|
||||||
@@ -35,10 +36,7 @@ async function getWorkflowInputSchema(workflowId: string): Promise<any[]> {
|
|||||||
.from(workflowBlocks)
|
.from(workflowBlocks)
|
||||||
.where(eq(workflowBlocks.workflowId, workflowId))
|
.where(eq(workflowBlocks.workflowId, workflowId))
|
||||||
|
|
||||||
const startBlock = blocks.find(
|
const startBlock = blocks.find((block) => isValidStartBlockType(block.type))
|
||||||
(block) =>
|
|
||||||
block.type === 'starter' || block.type === 'start_trigger' || block.type === 'input_trigger'
|
|
||||||
)
|
|
||||||
|
|
||||||
if (!startBlock) {
|
if (!startBlock) {
|
||||||
return []
|
return []
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import { escapeRegExp, normalizeName, REFERENCE } from '@/executor/constants'
|
|||||||
import {
|
import {
|
||||||
createEnvVarPattern,
|
createEnvVarPattern,
|
||||||
createWorkflowVariablePattern,
|
createWorkflowVariablePattern,
|
||||||
|
resolveEnvVarReferences,
|
||||||
} from '@/executor/utils/reference-validation'
|
} from '@/executor/utils/reference-validation'
|
||||||
export const dynamic = 'force-dynamic'
|
export const dynamic = 'force-dynamic'
|
||||||
export const runtime = 'nodejs'
|
export const runtime = 'nodejs'
|
||||||
@@ -479,9 +480,29 @@ function resolveEnvironmentVariables(
|
|||||||
const replacements: Array<{ match: string; index: number; varName: string; varValue: string }> =
|
const replacements: Array<{ match: string; index: number; varName: string; varValue: string }> =
|
||||||
[]
|
[]
|
||||||
|
|
||||||
|
const resolverVars: Record<string, string> = {}
|
||||||
|
Object.entries(params).forEach(([key, value]) => {
|
||||||
|
if (value) {
|
||||||
|
resolverVars[key] = String(value)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
Object.entries(envVars).forEach(([key, value]) => {
|
||||||
|
if (value) {
|
||||||
|
resolverVars[key] = value
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
while ((match = regex.exec(code)) !== null) {
|
while ((match = regex.exec(code)) !== null) {
|
||||||
const varName = match[1].trim()
|
const varName = match[1].trim()
|
||||||
const varValue = envVars[varName] || params[varName] || ''
|
const resolved = resolveEnvVarReferences(match[0], resolverVars, {
|
||||||
|
allowEmbedded: true,
|
||||||
|
resolveExactMatch: true,
|
||||||
|
trimKeys: true,
|
||||||
|
onMissing: 'empty',
|
||||||
|
deep: false,
|
||||||
|
})
|
||||||
|
const varValue =
|
||||||
|
typeof resolved === 'string' ? resolved : resolved == null ? '' : String(resolved)
|
||||||
replacements.push({
|
replacements.push({
|
||||||
match: match[0],
|
match: match[0],
|
||||||
index: match.index,
|
index: match.index,
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import { randomUUID } from 'crypto'
|
|||||||
import { createLogger } from '@sim/logger'
|
import { createLogger } from '@sim/logger'
|
||||||
import { type NextRequest, NextResponse } from 'next/server'
|
import { type NextRequest, NextResponse } from 'next/server'
|
||||||
import { z } from 'zod'
|
import { z } from 'zod'
|
||||||
import { getSession } from '@/lib/auth'
|
import { checkHybridAuth } from '@/lib/auth/hybrid'
|
||||||
import { SUPPORTED_FIELD_TYPES } from '@/lib/knowledge/constants'
|
import { SUPPORTED_FIELD_TYPES } from '@/lib/knowledge/constants'
|
||||||
import { createTagDefinition, getTagDefinitions } from '@/lib/knowledge/tags/service'
|
import { createTagDefinition, getTagDefinitions } from '@/lib/knowledge/tags/service'
|
||||||
import { checkKnowledgeBaseAccess } from '@/app/api/knowledge/utils'
|
import { checkKnowledgeBaseAccess } from '@/app/api/knowledge/utils'
|
||||||
@@ -19,19 +19,32 @@ export async function GET(req: NextRequest, { params }: { params: Promise<{ id:
|
|||||||
try {
|
try {
|
||||||
logger.info(`[${requestId}] Getting tag definitions for knowledge base ${knowledgeBaseId}`)
|
logger.info(`[${requestId}] Getting tag definitions for knowledge base ${knowledgeBaseId}`)
|
||||||
|
|
||||||
const session = await getSession()
|
const auth = await checkHybridAuth(req, { requireWorkflowId: false })
|
||||||
if (!session?.user?.id) {
|
if (!auth.success) {
|
||||||
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 })
|
return NextResponse.json({ error: auth.error || 'Unauthorized' }, { status: 401 })
|
||||||
}
|
}
|
||||||
|
|
||||||
const accessCheck = await checkKnowledgeBaseAccess(knowledgeBaseId, session.user.id)
|
// Only allow session and internal JWT auth (not API key)
|
||||||
if (!accessCheck.hasAccess) {
|
if (auth.authType === 'api_key') {
|
||||||
return NextResponse.json({ error: 'Forbidden' }, { status: 403 })
|
return NextResponse.json(
|
||||||
|
{ error: 'API key auth not supported for this endpoint' },
|
||||||
|
{ status: 401 }
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
// For session auth, verify KB access. Internal JWT is trusted.
|
||||||
|
if (auth.authType === 'session' && auth.userId) {
|
||||||
|
const accessCheck = await checkKnowledgeBaseAccess(knowledgeBaseId, auth.userId)
|
||||||
|
if (!accessCheck.hasAccess) {
|
||||||
|
return NextResponse.json({ error: 'Forbidden' }, { status: 403 })
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const tagDefinitions = await getTagDefinitions(knowledgeBaseId)
|
const tagDefinitions = await getTagDefinitions(knowledgeBaseId)
|
||||||
|
|
||||||
logger.info(`[${requestId}] Retrieved ${tagDefinitions.length} tag definitions`)
|
logger.info(
|
||||||
|
`[${requestId}] Retrieved ${tagDefinitions.length} tag definitions (${auth.authType})`
|
||||||
|
)
|
||||||
|
|
||||||
return NextResponse.json({
|
return NextResponse.json({
|
||||||
success: true,
|
success: true,
|
||||||
@@ -51,14 +64,25 @@ export async function POST(req: NextRequest, { params }: { params: Promise<{ id:
|
|||||||
try {
|
try {
|
||||||
logger.info(`[${requestId}] Creating tag definition for knowledge base ${knowledgeBaseId}`)
|
logger.info(`[${requestId}] Creating tag definition for knowledge base ${knowledgeBaseId}`)
|
||||||
|
|
||||||
const session = await getSession()
|
const auth = await checkHybridAuth(req, { requireWorkflowId: false })
|
||||||
if (!session?.user?.id) {
|
if (!auth.success) {
|
||||||
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 })
|
return NextResponse.json({ error: auth.error || 'Unauthorized' }, { status: 401 })
|
||||||
}
|
}
|
||||||
|
|
||||||
const accessCheck = await checkKnowledgeBaseAccess(knowledgeBaseId, session.user.id)
|
// Only allow session and internal JWT auth (not API key)
|
||||||
if (!accessCheck.hasAccess) {
|
if (auth.authType === 'api_key') {
|
||||||
return NextResponse.json({ error: 'Forbidden' }, { status: 403 })
|
return NextResponse.json(
|
||||||
|
{ error: 'API key auth not supported for this endpoint' },
|
||||||
|
{ status: 401 }
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
// For session auth, verify KB access. Internal JWT is trusted.
|
||||||
|
if (auth.authType === 'session' && auth.userId) {
|
||||||
|
const accessCheck = await checkKnowledgeBaseAccess(knowledgeBaseId, auth.userId)
|
||||||
|
if (!accessCheck.hasAccess) {
|
||||||
|
return NextResponse.json({ error: 'Forbidden' }, { status: 403 })
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const body = await req.json()
|
const body = await req.json()
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ import { createLogger } from '@sim/logger'
|
|||||||
import { and, eq } from 'drizzle-orm'
|
import { and, eq } from 'drizzle-orm'
|
||||||
import { type NextRequest, NextResponse } from 'next/server'
|
import { type NextRequest, NextResponse } from 'next/server'
|
||||||
import { checkHybridAuth } from '@/lib/auth/hybrid'
|
import { checkHybridAuth } from '@/lib/auth/hybrid'
|
||||||
|
import { generateInternalToken } from '@/lib/auth/internal'
|
||||||
import { getBaseUrl } from '@/lib/core/utils/urls'
|
import { getBaseUrl } from '@/lib/core/utils/urls'
|
||||||
|
|
||||||
const logger = createLogger('WorkflowMcpServeAPI')
|
const logger = createLogger('WorkflowMcpServeAPI')
|
||||||
@@ -52,6 +53,8 @@ async function getServer(serverId: string) {
|
|||||||
id: workflowMcpServer.id,
|
id: workflowMcpServer.id,
|
||||||
name: workflowMcpServer.name,
|
name: workflowMcpServer.name,
|
||||||
workspaceId: workflowMcpServer.workspaceId,
|
workspaceId: workflowMcpServer.workspaceId,
|
||||||
|
isPublic: workflowMcpServer.isPublic,
|
||||||
|
createdBy: workflowMcpServer.createdBy,
|
||||||
})
|
})
|
||||||
.from(workflowMcpServer)
|
.from(workflowMcpServer)
|
||||||
.where(eq(workflowMcpServer.id, serverId))
|
.where(eq(workflowMcpServer.id, serverId))
|
||||||
@@ -90,9 +93,11 @@ export async function POST(request: NextRequest, { params }: { params: Promise<R
|
|||||||
return NextResponse.json({ error: 'Server not found' }, { status: 404 })
|
return NextResponse.json({ error: 'Server not found' }, { status: 404 })
|
||||||
}
|
}
|
||||||
|
|
||||||
const auth = await checkHybridAuth(request, { requireWorkflowId: false })
|
if (!server.isPublic) {
|
||||||
if (!auth.success || !auth.userId) {
|
const auth = await checkHybridAuth(request, { requireWorkflowId: false })
|
||||||
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 })
|
if (!auth.success || !auth.userId) {
|
||||||
|
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 })
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const body = await request.json()
|
const body = await request.json()
|
||||||
@@ -138,7 +143,8 @@ export async function POST(request: NextRequest, { params }: { params: Promise<R
|
|||||||
id,
|
id,
|
||||||
serverId,
|
serverId,
|
||||||
rpcParams as { name: string; arguments?: Record<string, unknown> },
|
rpcParams as { name: string; arguments?: Record<string, unknown> },
|
||||||
apiKey
|
apiKey,
|
||||||
|
server.isPublic ? server.createdBy : undefined
|
||||||
)
|
)
|
||||||
|
|
||||||
default:
|
default:
|
||||||
@@ -200,7 +206,8 @@ async function handleToolsCall(
|
|||||||
id: RequestId,
|
id: RequestId,
|
||||||
serverId: string,
|
serverId: string,
|
||||||
params: { name: string; arguments?: Record<string, unknown> } | undefined,
|
params: { name: string; arguments?: Record<string, unknown> } | undefined,
|
||||||
apiKey?: string | null
|
apiKey?: string | null,
|
||||||
|
publicServerOwnerId?: string
|
||||||
): Promise<NextResponse> {
|
): Promise<NextResponse> {
|
||||||
try {
|
try {
|
||||||
if (!params?.name) {
|
if (!params?.name) {
|
||||||
@@ -243,7 +250,13 @@ async function handleToolsCall(
|
|||||||
|
|
||||||
const executeUrl = `${getBaseUrl()}/api/workflows/${tool.workflowId}/execute`
|
const executeUrl = `${getBaseUrl()}/api/workflows/${tool.workflowId}/execute`
|
||||||
const headers: Record<string, string> = { 'Content-Type': 'application/json' }
|
const headers: Record<string, string> = { 'Content-Type': 'application/json' }
|
||||||
if (apiKey) headers['X-API-Key'] = apiKey
|
|
||||||
|
if (publicServerOwnerId) {
|
||||||
|
const internalToken = await generateInternalToken(publicServerOwnerId)
|
||||||
|
headers.Authorization = `Bearer ${internalToken}`
|
||||||
|
} else if (apiKey) {
|
||||||
|
headers['X-API-Key'] = apiKey
|
||||||
|
}
|
||||||
|
|
||||||
logger.info(`Executing workflow ${tool.workflowId} via MCP tool ${params.name}`)
|
logger.info(`Executing workflow ${tool.workflowId} via MCP tool ${params.name}`)
|
||||||
|
|
||||||
|
|||||||
@@ -5,8 +5,7 @@ import { McpClient } from '@/lib/mcp/client'
|
|||||||
import { getParsedBody, withMcpAuth } from '@/lib/mcp/middleware'
|
import { getParsedBody, withMcpAuth } from '@/lib/mcp/middleware'
|
||||||
import type { McpServerConfig, McpTransport } from '@/lib/mcp/types'
|
import type { McpServerConfig, McpTransport } from '@/lib/mcp/types'
|
||||||
import { createMcpErrorResponse, createMcpSuccessResponse } from '@/lib/mcp/utils'
|
import { createMcpErrorResponse, createMcpSuccessResponse } from '@/lib/mcp/utils'
|
||||||
import { REFERENCE } from '@/executor/constants'
|
import { resolveEnvVarReferences } from '@/executor/utils/reference-validation'
|
||||||
import { createEnvVarPattern } from '@/executor/utils/reference-validation'
|
|
||||||
|
|
||||||
const logger = createLogger('McpServerTestAPI')
|
const logger = createLogger('McpServerTestAPI')
|
||||||
|
|
||||||
@@ -24,22 +23,23 @@ function isUrlBasedTransport(transport: McpTransport): boolean {
|
|||||||
* Resolve environment variables in strings
|
* Resolve environment variables in strings
|
||||||
*/
|
*/
|
||||||
function resolveEnvVars(value: string, envVars: Record<string, string>): string {
|
function resolveEnvVars(value: string, envVars: Record<string, string>): string {
|
||||||
const envVarPattern = createEnvVarPattern()
|
const missingVars: string[] = []
|
||||||
const envMatches = value.match(envVarPattern)
|
const resolvedValue = resolveEnvVarReferences(value, envVars, {
|
||||||
if (!envMatches) return value
|
allowEmbedded: true,
|
||||||
|
resolveExactMatch: true,
|
||||||
|
trimKeys: true,
|
||||||
|
onMissing: 'keep',
|
||||||
|
deep: false,
|
||||||
|
missingKeys: missingVars,
|
||||||
|
}) as string
|
||||||
|
|
||||||
let resolvedValue = value
|
if (missingVars.length > 0) {
|
||||||
for (const match of envMatches) {
|
const uniqueMissing = Array.from(new Set(missingVars))
|
||||||
const envKey = match.slice(REFERENCE.ENV_VAR_START.length, -REFERENCE.ENV_VAR_END.length).trim()
|
uniqueMissing.forEach((envKey) => {
|
||||||
const envValue = envVars[envKey]
|
|
||||||
|
|
||||||
if (envValue === undefined) {
|
|
||||||
logger.warn(`Environment variable "${envKey}" not found in MCP server test`)
|
logger.warn(`Environment variable "${envKey}" not found in MCP server test`)
|
||||||
continue
|
})
|
||||||
}
|
|
||||||
|
|
||||||
resolvedValue = resolvedValue.replace(match, envValue)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return resolvedValue
|
return resolvedValue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ export const GET = withMcpAuth<RouteParams>('read')(
|
|||||||
createdBy: workflowMcpServer.createdBy,
|
createdBy: workflowMcpServer.createdBy,
|
||||||
name: workflowMcpServer.name,
|
name: workflowMcpServer.name,
|
||||||
description: workflowMcpServer.description,
|
description: workflowMcpServer.description,
|
||||||
|
isPublic: workflowMcpServer.isPublic,
|
||||||
createdAt: workflowMcpServer.createdAt,
|
createdAt: workflowMcpServer.createdAt,
|
||||||
updatedAt: workflowMcpServer.updatedAt,
|
updatedAt: workflowMcpServer.updatedAt,
|
||||||
})
|
})
|
||||||
@@ -98,6 +99,9 @@ export const PATCH = withMcpAuth<RouteParams>('write')(
|
|||||||
if (body.description !== undefined) {
|
if (body.description !== undefined) {
|
||||||
updateData.description = body.description?.trim() || null
|
updateData.description = body.description?.trim() || null
|
||||||
}
|
}
|
||||||
|
if (body.isPublic !== undefined) {
|
||||||
|
updateData.isPublic = body.isPublic
|
||||||
|
}
|
||||||
|
|
||||||
const [updatedServer] = await db
|
const [updatedServer] = await db
|
||||||
.update(workflowMcpServer)
|
.update(workflowMcpServer)
|
||||||
|
|||||||
@@ -26,7 +26,6 @@ export const GET = withMcpAuth<RouteParams>('read')(
|
|||||||
|
|
||||||
logger.info(`[${requestId}] Getting tool ${toolId} from server ${serverId}`)
|
logger.info(`[${requestId}] Getting tool ${toolId} from server ${serverId}`)
|
||||||
|
|
||||||
// Verify server exists and belongs to workspace
|
|
||||||
const [server] = await db
|
const [server] = await db
|
||||||
.select({ id: workflowMcpServer.id })
|
.select({ id: workflowMcpServer.id })
|
||||||
.from(workflowMcpServer)
|
.from(workflowMcpServer)
|
||||||
@@ -72,7 +71,6 @@ export const PATCH = withMcpAuth<RouteParams>('write')(
|
|||||||
|
|
||||||
logger.info(`[${requestId}] Updating tool ${toolId} in server ${serverId}`)
|
logger.info(`[${requestId}] Updating tool ${toolId} in server ${serverId}`)
|
||||||
|
|
||||||
// Verify server exists and belongs to workspace
|
|
||||||
const [server] = await db
|
const [server] = await db
|
||||||
.select({ id: workflowMcpServer.id })
|
.select({ id: workflowMcpServer.id })
|
||||||
.from(workflowMcpServer)
|
.from(workflowMcpServer)
|
||||||
@@ -139,7 +137,6 @@ export const DELETE = withMcpAuth<RouteParams>('write')(
|
|||||||
|
|
||||||
logger.info(`[${requestId}] Deleting tool ${toolId} from server ${serverId}`)
|
logger.info(`[${requestId}] Deleting tool ${toolId} from server ${serverId}`)
|
||||||
|
|
||||||
// Verify server exists and belongs to workspace
|
|
||||||
const [server] = await db
|
const [server] = await db
|
||||||
.select({ id: workflowMcpServer.id })
|
.select({ id: workflowMcpServer.id })
|
||||||
.from(workflowMcpServer)
|
.from(workflowMcpServer)
|
||||||
|
|||||||
@@ -6,24 +6,10 @@ import type { NextRequest } from 'next/server'
|
|||||||
import { getParsedBody, withMcpAuth } from '@/lib/mcp/middleware'
|
import { getParsedBody, withMcpAuth } from '@/lib/mcp/middleware'
|
||||||
import { createMcpErrorResponse, createMcpSuccessResponse } from '@/lib/mcp/utils'
|
import { createMcpErrorResponse, createMcpSuccessResponse } from '@/lib/mcp/utils'
|
||||||
import { sanitizeToolName } from '@/lib/mcp/workflow-tool-schema'
|
import { sanitizeToolName } from '@/lib/mcp/workflow-tool-schema'
|
||||||
import { loadWorkflowFromNormalizedTables } from '@/lib/workflows/persistence/utils'
|
import { hasValidStartBlock } from '@/lib/workflows/triggers/trigger-utils.server'
|
||||||
import { hasValidStartBlockInState } from '@/lib/workflows/triggers/trigger-utils'
|
|
||||||
|
|
||||||
const logger = createLogger('WorkflowMcpToolsAPI')
|
const logger = createLogger('WorkflowMcpToolsAPI')
|
||||||
|
|
||||||
/**
|
|
||||||
* Check if a workflow has a valid start block by loading from database
|
|
||||||
*/
|
|
||||||
async function hasValidStartBlock(workflowId: string): Promise<boolean> {
|
|
||||||
try {
|
|
||||||
const normalizedData = await loadWorkflowFromNormalizedTables(workflowId)
|
|
||||||
return hasValidStartBlockInState(normalizedData)
|
|
||||||
} catch (error) {
|
|
||||||
logger.warn('Error checking for start block:', error)
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export const dynamic = 'force-dynamic'
|
export const dynamic = 'force-dynamic'
|
||||||
|
|
||||||
interface RouteParams {
|
interface RouteParams {
|
||||||
@@ -40,7 +26,6 @@ export const GET = withMcpAuth<RouteParams>('read')(
|
|||||||
|
|
||||||
logger.info(`[${requestId}] Listing tools for workflow MCP server: ${serverId}`)
|
logger.info(`[${requestId}] Listing tools for workflow MCP server: ${serverId}`)
|
||||||
|
|
||||||
// Verify server exists and belongs to workspace
|
|
||||||
const [server] = await db
|
const [server] = await db
|
||||||
.select({ id: workflowMcpServer.id })
|
.select({ id: workflowMcpServer.id })
|
||||||
.from(workflowMcpServer)
|
.from(workflowMcpServer)
|
||||||
@@ -53,7 +38,6 @@ export const GET = withMcpAuth<RouteParams>('read')(
|
|||||||
return createMcpErrorResponse(new Error('Server not found'), 'Server not found', 404)
|
return createMcpErrorResponse(new Error('Server not found'), 'Server not found', 404)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get tools with workflow details
|
|
||||||
const tools = await db
|
const tools = await db
|
||||||
.select({
|
.select({
|
||||||
id: workflowMcpTool.id,
|
id: workflowMcpTool.id,
|
||||||
@@ -107,7 +91,6 @@ export const POST = withMcpAuth<RouteParams>('write')(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Verify server exists and belongs to workspace
|
|
||||||
const [server] = await db
|
const [server] = await db
|
||||||
.select({ id: workflowMcpServer.id })
|
.select({ id: workflowMcpServer.id })
|
||||||
.from(workflowMcpServer)
|
.from(workflowMcpServer)
|
||||||
@@ -120,7 +103,6 @@ export const POST = withMcpAuth<RouteParams>('write')(
|
|||||||
return createMcpErrorResponse(new Error('Server not found'), 'Server not found', 404)
|
return createMcpErrorResponse(new Error('Server not found'), 'Server not found', 404)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Verify workflow exists and is deployed
|
|
||||||
const [workflowRecord] = await db
|
const [workflowRecord] = await db
|
||||||
.select({
|
.select({
|
||||||
id: workflow.id,
|
id: workflow.id,
|
||||||
@@ -137,7 +119,6 @@ export const POST = withMcpAuth<RouteParams>('write')(
|
|||||||
return createMcpErrorResponse(new Error('Workflow not found'), 'Workflow not found', 404)
|
return createMcpErrorResponse(new Error('Workflow not found'), 'Workflow not found', 404)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Verify workflow belongs to the same workspace
|
|
||||||
if (workflowRecord.workspaceId !== workspaceId) {
|
if (workflowRecord.workspaceId !== workspaceId) {
|
||||||
return createMcpErrorResponse(
|
return createMcpErrorResponse(
|
||||||
new Error('Workflow does not belong to this workspace'),
|
new Error('Workflow does not belong to this workspace'),
|
||||||
@@ -154,7 +135,6 @@ export const POST = withMcpAuth<RouteParams>('write')(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Verify workflow has a valid start block
|
|
||||||
const hasStartBlock = await hasValidStartBlock(body.workflowId)
|
const hasStartBlock = await hasValidStartBlock(body.workflowId)
|
||||||
if (!hasStartBlock) {
|
if (!hasStartBlock) {
|
||||||
return createMcpErrorResponse(
|
return createMcpErrorResponse(
|
||||||
@@ -164,7 +144,6 @@ export const POST = withMcpAuth<RouteParams>('write')(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if tool already exists for this workflow
|
|
||||||
const [existingTool] = await db
|
const [existingTool] = await db
|
||||||
.select({ id: workflowMcpTool.id })
|
.select({ id: workflowMcpTool.id })
|
||||||
.from(workflowMcpTool)
|
.from(workflowMcpTool)
|
||||||
@@ -190,7 +169,6 @@ export const POST = withMcpAuth<RouteParams>('write')(
|
|||||||
workflowRecord.description ||
|
workflowRecord.description ||
|
||||||
`Execute ${workflowRecord.name} workflow`
|
`Execute ${workflowRecord.name} workflow`
|
||||||
|
|
||||||
// Create the tool
|
|
||||||
const toolId = crypto.randomUUID()
|
const toolId = crypto.randomUUID()
|
||||||
const [tool] = await db
|
const [tool] = await db
|
||||||
.insert(workflowMcpTool)
|
.insert(workflowMcpTool)
|
||||||
|
|||||||
@@ -1,10 +1,12 @@
|
|||||||
import { db } from '@sim/db'
|
import { db } from '@sim/db'
|
||||||
import { workflowMcpServer, workflowMcpTool } from '@sim/db/schema'
|
import { workflow, workflowMcpServer, workflowMcpTool } from '@sim/db/schema'
|
||||||
import { createLogger } from '@sim/logger'
|
import { createLogger } from '@sim/logger'
|
||||||
import { eq, inArray, sql } from 'drizzle-orm'
|
import { eq, inArray, sql } from 'drizzle-orm'
|
||||||
import type { NextRequest } from 'next/server'
|
import type { NextRequest } from 'next/server'
|
||||||
import { getParsedBody, withMcpAuth } from '@/lib/mcp/middleware'
|
import { getParsedBody, withMcpAuth } from '@/lib/mcp/middleware'
|
||||||
import { createMcpErrorResponse, createMcpSuccessResponse } from '@/lib/mcp/utils'
|
import { createMcpErrorResponse, createMcpSuccessResponse } from '@/lib/mcp/utils'
|
||||||
|
import { sanitizeToolName } from '@/lib/mcp/workflow-tool-schema'
|
||||||
|
import { hasValidStartBlock } from '@/lib/workflows/triggers/trigger-utils.server'
|
||||||
|
|
||||||
const logger = createLogger('WorkflowMcpServersAPI')
|
const logger = createLogger('WorkflowMcpServersAPI')
|
||||||
|
|
||||||
@@ -25,18 +27,18 @@ export const GET = withMcpAuth('read')(
|
|||||||
createdBy: workflowMcpServer.createdBy,
|
createdBy: workflowMcpServer.createdBy,
|
||||||
name: workflowMcpServer.name,
|
name: workflowMcpServer.name,
|
||||||
description: workflowMcpServer.description,
|
description: workflowMcpServer.description,
|
||||||
|
isPublic: workflowMcpServer.isPublic,
|
||||||
createdAt: workflowMcpServer.createdAt,
|
createdAt: workflowMcpServer.createdAt,
|
||||||
updatedAt: workflowMcpServer.updatedAt,
|
updatedAt: workflowMcpServer.updatedAt,
|
||||||
toolCount: sql<number>`(
|
toolCount: sql<number>`(
|
||||||
SELECT COUNT(*)::int
|
SELECT COUNT(*)::int
|
||||||
FROM "workflow_mcp_tool"
|
FROM "workflow_mcp_tool"
|
||||||
WHERE "workflow_mcp_tool"."server_id" = "workflow_mcp_server"."id"
|
WHERE "workflow_mcp_tool"."server_id" = "workflow_mcp_server"."id"
|
||||||
)`.as('tool_count'),
|
)`.as('tool_count'),
|
||||||
})
|
})
|
||||||
.from(workflowMcpServer)
|
.from(workflowMcpServer)
|
||||||
.where(eq(workflowMcpServer.workspaceId, workspaceId))
|
.where(eq(workflowMcpServer.workspaceId, workspaceId))
|
||||||
|
|
||||||
// Fetch all tools for these servers
|
|
||||||
const serverIds = servers.map((s) => s.id)
|
const serverIds = servers.map((s) => s.id)
|
||||||
const tools =
|
const tools =
|
||||||
serverIds.length > 0
|
serverIds.length > 0
|
||||||
@@ -49,7 +51,6 @@ export const GET = withMcpAuth('read')(
|
|||||||
.where(inArray(workflowMcpTool.serverId, serverIds))
|
.where(inArray(workflowMcpTool.serverId, serverIds))
|
||||||
: []
|
: []
|
||||||
|
|
||||||
// Group tool names by server
|
|
||||||
const toolNamesByServer: Record<string, string[]> = {}
|
const toolNamesByServer: Record<string, string[]> = {}
|
||||||
for (const tool of tools) {
|
for (const tool of tools) {
|
||||||
if (!toolNamesByServer[tool.serverId]) {
|
if (!toolNamesByServer[tool.serverId]) {
|
||||||
@@ -58,7 +59,6 @@ export const GET = withMcpAuth('read')(
|
|||||||
toolNamesByServer[tool.serverId].push(tool.toolName)
|
toolNamesByServer[tool.serverId].push(tool.toolName)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Attach tool names to servers
|
|
||||||
const serversWithToolNames = servers.map((server) => ({
|
const serversWithToolNames = servers.map((server) => ({
|
||||||
...server,
|
...server,
|
||||||
toolNames: toolNamesByServer[server.id] || [],
|
toolNames: toolNamesByServer[server.id] || [],
|
||||||
@@ -90,6 +90,7 @@ export const POST = withMcpAuth('write')(
|
|||||||
logger.info(`[${requestId}] Creating workflow MCP server:`, {
|
logger.info(`[${requestId}] Creating workflow MCP server:`, {
|
||||||
name: body.name,
|
name: body.name,
|
||||||
workspaceId,
|
workspaceId,
|
||||||
|
workflowIds: body.workflowIds,
|
||||||
})
|
})
|
||||||
|
|
||||||
if (!body.name) {
|
if (!body.name) {
|
||||||
@@ -110,16 +111,76 @@ export const POST = withMcpAuth('write')(
|
|||||||
createdBy: userId,
|
createdBy: userId,
|
||||||
name: body.name.trim(),
|
name: body.name.trim(),
|
||||||
description: body.description?.trim() || null,
|
description: body.description?.trim() || null,
|
||||||
|
isPublic: body.isPublic ?? false,
|
||||||
createdAt: new Date(),
|
createdAt: new Date(),
|
||||||
updatedAt: new Date(),
|
updatedAt: new Date(),
|
||||||
})
|
})
|
||||||
.returning()
|
.returning()
|
||||||
|
|
||||||
|
const workflowIds: string[] = body.workflowIds || []
|
||||||
|
const addedTools: Array<{ workflowId: string; toolName: string }> = []
|
||||||
|
|
||||||
|
if (workflowIds.length > 0) {
|
||||||
|
const workflows = await db
|
||||||
|
.select({
|
||||||
|
id: workflow.id,
|
||||||
|
name: workflow.name,
|
||||||
|
description: workflow.description,
|
||||||
|
isDeployed: workflow.isDeployed,
|
||||||
|
workspaceId: workflow.workspaceId,
|
||||||
|
})
|
||||||
|
.from(workflow)
|
||||||
|
.where(inArray(workflow.id, workflowIds))
|
||||||
|
|
||||||
|
for (const workflowRecord of workflows) {
|
||||||
|
if (workflowRecord.workspaceId !== workspaceId) {
|
||||||
|
logger.warn(
|
||||||
|
`[${requestId}] Skipping workflow ${workflowRecord.id} - does not belong to workspace`
|
||||||
|
)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!workflowRecord.isDeployed) {
|
||||||
|
logger.warn(`[${requestId}] Skipping workflow ${workflowRecord.id} - not deployed`)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
const hasStartBlock = await hasValidStartBlock(workflowRecord.id)
|
||||||
|
if (!hasStartBlock) {
|
||||||
|
logger.warn(`[${requestId}] Skipping workflow ${workflowRecord.id} - no start block`)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
const toolName = sanitizeToolName(workflowRecord.name)
|
||||||
|
const toolDescription =
|
||||||
|
workflowRecord.description || `Execute ${workflowRecord.name} workflow`
|
||||||
|
|
||||||
|
const toolId = crypto.randomUUID()
|
||||||
|
await db.insert(workflowMcpTool).values({
|
||||||
|
id: toolId,
|
||||||
|
serverId,
|
||||||
|
workflowId: workflowRecord.id,
|
||||||
|
toolName,
|
||||||
|
toolDescription,
|
||||||
|
parameterSchema: {},
|
||||||
|
createdAt: new Date(),
|
||||||
|
updatedAt: new Date(),
|
||||||
|
})
|
||||||
|
|
||||||
|
addedTools.push({ workflowId: workflowRecord.id, toolName })
|
||||||
|
}
|
||||||
|
|
||||||
|
logger.info(
|
||||||
|
`[${requestId}] Added ${addedTools.length} tools to server ${serverId}:`,
|
||||||
|
addedTools.map((t) => t.toolName)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
logger.info(
|
logger.info(
|
||||||
`[${requestId}] Successfully created workflow MCP server: ${body.name} (ID: ${serverId})`
|
`[${requestId}] Successfully created workflow MCP server: ${body.name} (ID: ${serverId})`
|
||||||
)
|
)
|
||||||
|
|
||||||
return createMcpSuccessResponse({ server }, 201)
|
return createMcpSuccessResponse({ server, addedTools }, 201)
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.error(`[${requestId}] Error creating workflow MCP server:`, error)
|
logger.error(`[${requestId}] Error creating workflow MCP server:`, error)
|
||||||
return createMcpErrorResponse(
|
return createMcpErrorResponse(
|
||||||
|
|||||||
@@ -57,6 +57,7 @@ describe('Scheduled Workflow Execution API Route', () => {
|
|||||||
not: vi.fn((condition) => ({ type: 'not', condition })),
|
not: vi.fn((condition) => ({ type: 'not', condition })),
|
||||||
isNull: vi.fn((field) => ({ type: 'isNull', field })),
|
isNull: vi.fn((field) => ({ type: 'isNull', field })),
|
||||||
or: vi.fn((...conditions) => ({ type: 'or', conditions })),
|
or: vi.fn((...conditions) => ({ type: 'or', conditions })),
|
||||||
|
sql: vi.fn((strings, ...values) => ({ type: 'sql', strings, values })),
|
||||||
}))
|
}))
|
||||||
|
|
||||||
vi.doMock('@sim/db', () => {
|
vi.doMock('@sim/db', () => {
|
||||||
@@ -92,6 +93,17 @@ describe('Scheduled Workflow Execution API Route', () => {
|
|||||||
status: 'status',
|
status: 'status',
|
||||||
nextRunAt: 'nextRunAt',
|
nextRunAt: 'nextRunAt',
|
||||||
lastQueuedAt: 'lastQueuedAt',
|
lastQueuedAt: 'lastQueuedAt',
|
||||||
|
deploymentVersionId: 'deploymentVersionId',
|
||||||
|
},
|
||||||
|
workflowDeploymentVersion: {
|
||||||
|
id: 'id',
|
||||||
|
workflowId: 'workflowId',
|
||||||
|
isActive: 'isActive',
|
||||||
|
},
|
||||||
|
workflow: {
|
||||||
|
id: 'id',
|
||||||
|
userId: 'userId',
|
||||||
|
workspaceId: 'workspaceId',
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@@ -134,6 +146,7 @@ describe('Scheduled Workflow Execution API Route', () => {
|
|||||||
not: vi.fn((condition) => ({ type: 'not', condition })),
|
not: vi.fn((condition) => ({ type: 'not', condition })),
|
||||||
isNull: vi.fn((field) => ({ type: 'isNull', field })),
|
isNull: vi.fn((field) => ({ type: 'isNull', field })),
|
||||||
or: vi.fn((...conditions) => ({ type: 'or', conditions })),
|
or: vi.fn((...conditions) => ({ type: 'or', conditions })),
|
||||||
|
sql: vi.fn((strings, ...values) => ({ type: 'sql', strings, values })),
|
||||||
}))
|
}))
|
||||||
|
|
||||||
vi.doMock('@sim/db', () => {
|
vi.doMock('@sim/db', () => {
|
||||||
@@ -169,6 +182,17 @@ describe('Scheduled Workflow Execution API Route', () => {
|
|||||||
status: 'status',
|
status: 'status',
|
||||||
nextRunAt: 'nextRunAt',
|
nextRunAt: 'nextRunAt',
|
||||||
lastQueuedAt: 'lastQueuedAt',
|
lastQueuedAt: 'lastQueuedAt',
|
||||||
|
deploymentVersionId: 'deploymentVersionId',
|
||||||
|
},
|
||||||
|
workflowDeploymentVersion: {
|
||||||
|
id: 'id',
|
||||||
|
workflowId: 'workflowId',
|
||||||
|
isActive: 'isActive',
|
||||||
|
},
|
||||||
|
workflow: {
|
||||||
|
id: 'id',
|
||||||
|
userId: 'userId',
|
||||||
|
workspaceId: 'workspaceId',
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@@ -206,6 +230,7 @@ describe('Scheduled Workflow Execution API Route', () => {
|
|||||||
not: vi.fn((condition) => ({ type: 'not', condition })),
|
not: vi.fn((condition) => ({ type: 'not', condition })),
|
||||||
isNull: vi.fn((field) => ({ type: 'isNull', field })),
|
isNull: vi.fn((field) => ({ type: 'isNull', field })),
|
||||||
or: vi.fn((...conditions) => ({ type: 'or', conditions })),
|
or: vi.fn((...conditions) => ({ type: 'or', conditions })),
|
||||||
|
sql: vi.fn((strings, ...values) => ({ type: 'sql', strings, values })),
|
||||||
}))
|
}))
|
||||||
|
|
||||||
vi.doMock('@sim/db', () => {
|
vi.doMock('@sim/db', () => {
|
||||||
@@ -228,6 +253,17 @@ describe('Scheduled Workflow Execution API Route', () => {
|
|||||||
status: 'status',
|
status: 'status',
|
||||||
nextRunAt: 'nextRunAt',
|
nextRunAt: 'nextRunAt',
|
||||||
lastQueuedAt: 'lastQueuedAt',
|
lastQueuedAt: 'lastQueuedAt',
|
||||||
|
deploymentVersionId: 'deploymentVersionId',
|
||||||
|
},
|
||||||
|
workflowDeploymentVersion: {
|
||||||
|
id: 'id',
|
||||||
|
workflowId: 'workflowId',
|
||||||
|
isActive: 'isActive',
|
||||||
|
},
|
||||||
|
workflow: {
|
||||||
|
id: 'id',
|
||||||
|
userId: 'userId',
|
||||||
|
workspaceId: 'workspaceId',
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@@ -265,6 +301,7 @@ describe('Scheduled Workflow Execution API Route', () => {
|
|||||||
not: vi.fn((condition) => ({ type: 'not', condition })),
|
not: vi.fn((condition) => ({ type: 'not', condition })),
|
||||||
isNull: vi.fn((field) => ({ type: 'isNull', field })),
|
isNull: vi.fn((field) => ({ type: 'isNull', field })),
|
||||||
or: vi.fn((...conditions) => ({ type: 'or', conditions })),
|
or: vi.fn((...conditions) => ({ type: 'or', conditions })),
|
||||||
|
sql: vi.fn((strings, ...values) => ({ type: 'sql', strings, values })),
|
||||||
}))
|
}))
|
||||||
|
|
||||||
vi.doMock('@sim/db', () => {
|
vi.doMock('@sim/db', () => {
|
||||||
@@ -310,6 +347,17 @@ describe('Scheduled Workflow Execution API Route', () => {
|
|||||||
status: 'status',
|
status: 'status',
|
||||||
nextRunAt: 'nextRunAt',
|
nextRunAt: 'nextRunAt',
|
||||||
lastQueuedAt: 'lastQueuedAt',
|
lastQueuedAt: 'lastQueuedAt',
|
||||||
|
deploymentVersionId: 'deploymentVersionId',
|
||||||
|
},
|
||||||
|
workflowDeploymentVersion: {
|
||||||
|
id: 'id',
|
||||||
|
workflowId: 'workflowId',
|
||||||
|
isActive: 'isActive',
|
||||||
|
},
|
||||||
|
workflow: {
|
||||||
|
id: 'id',
|
||||||
|
userId: 'userId',
|
||||||
|
workspaceId: 'workspaceId',
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import { db, workflowSchedule } from '@sim/db'
|
import { db, workflowDeploymentVersion, workflowSchedule } from '@sim/db'
|
||||||
import { createLogger } from '@sim/logger'
|
import { createLogger } from '@sim/logger'
|
||||||
import { tasks } from '@trigger.dev/sdk'
|
import { tasks } from '@trigger.dev/sdk'
|
||||||
import { and, eq, isNull, lt, lte, not, or } from 'drizzle-orm'
|
import { and, eq, isNull, lt, lte, not, or, sql } from 'drizzle-orm'
|
||||||
import { type NextRequest, NextResponse } from 'next/server'
|
import { type NextRequest, NextResponse } from 'next/server'
|
||||||
import { verifyCronAuth } from '@/lib/auth/internal'
|
import { verifyCronAuth } from '@/lib/auth/internal'
|
||||||
import { isTriggerDevEnabled } from '@/lib/core/config/feature-flags'
|
import { isTriggerDevEnabled } from '@/lib/core/config/feature-flags'
|
||||||
@@ -37,7 +37,8 @@ export async function GET(request: NextRequest) {
|
|||||||
or(
|
or(
|
||||||
isNull(workflowSchedule.lastQueuedAt),
|
isNull(workflowSchedule.lastQueuedAt),
|
||||||
lt(workflowSchedule.lastQueuedAt, workflowSchedule.nextRunAt)
|
lt(workflowSchedule.lastQueuedAt, workflowSchedule.nextRunAt)
|
||||||
)
|
),
|
||||||
|
sql`${workflowSchedule.deploymentVersionId} = (select ${workflowDeploymentVersion.id} from ${workflowDeploymentVersion} where ${workflowDeploymentVersion.workflowId} = ${workflowSchedule.workflowId} and ${workflowDeploymentVersion.isActive} = true)`
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
.returning({
|
.returning({
|
||||||
|
|||||||
@@ -29,12 +29,23 @@ vi.mock('@sim/db', () => ({
|
|||||||
|
|
||||||
vi.mock('@sim/db/schema', () => ({
|
vi.mock('@sim/db/schema', () => ({
|
||||||
workflow: { id: 'id', userId: 'userId', workspaceId: 'workspaceId' },
|
workflow: { id: 'id', userId: 'userId', workspaceId: 'workspaceId' },
|
||||||
workflowSchedule: { workflowId: 'workflowId', blockId: 'blockId' },
|
workflowSchedule: {
|
||||||
|
workflowId: 'workflowId',
|
||||||
|
blockId: 'blockId',
|
||||||
|
deploymentVersionId: 'deploymentVersionId',
|
||||||
|
},
|
||||||
|
workflowDeploymentVersion: {
|
||||||
|
id: 'id',
|
||||||
|
workflowId: 'workflowId',
|
||||||
|
isActive: 'isActive',
|
||||||
|
},
|
||||||
}))
|
}))
|
||||||
|
|
||||||
vi.mock('drizzle-orm', () => ({
|
vi.mock('drizzle-orm', () => ({
|
||||||
eq: vi.fn(),
|
eq: vi.fn(),
|
||||||
and: vi.fn(),
|
and: vi.fn(),
|
||||||
|
or: vi.fn(),
|
||||||
|
isNull: vi.fn(),
|
||||||
}))
|
}))
|
||||||
|
|
||||||
vi.mock('@/lib/core/utils/request', () => ({
|
vi.mock('@/lib/core/utils/request', () => ({
|
||||||
@@ -56,6 +67,11 @@ function mockDbChain(results: any[]) {
|
|||||||
where: () => ({
|
where: () => ({
|
||||||
limit: () => results[callIndex++] || [],
|
limit: () => results[callIndex++] || [],
|
||||||
}),
|
}),
|
||||||
|
leftJoin: () => ({
|
||||||
|
where: () => ({
|
||||||
|
limit: () => results[callIndex++] || [],
|
||||||
|
}),
|
||||||
|
}),
|
||||||
}),
|
}),
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
@@ -74,7 +90,16 @@ describe('Schedule GET API', () => {
|
|||||||
it('returns schedule data for authorized user', async () => {
|
it('returns schedule data for authorized user', async () => {
|
||||||
mockDbChain([
|
mockDbChain([
|
||||||
[{ userId: 'user-1', workspaceId: null }],
|
[{ userId: 'user-1', workspaceId: null }],
|
||||||
[{ id: 'sched-1', cronExpression: '0 9 * * *', status: 'active', failedCount: 0 }],
|
[
|
||||||
|
{
|
||||||
|
schedule: {
|
||||||
|
id: 'sched-1',
|
||||||
|
cronExpression: '0 9 * * *',
|
||||||
|
status: 'active',
|
||||||
|
failedCount: 0,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
])
|
])
|
||||||
|
|
||||||
const res = await GET(createRequest('http://test/api/schedules?workflowId=wf-1'))
|
const res = await GET(createRequest('http://test/api/schedules?workflowId=wf-1'))
|
||||||
@@ -128,7 +153,7 @@ describe('Schedule GET API', () => {
|
|||||||
it('allows workspace members to view', async () => {
|
it('allows workspace members to view', async () => {
|
||||||
mockDbChain([
|
mockDbChain([
|
||||||
[{ userId: 'other-user', workspaceId: 'ws-1' }],
|
[{ userId: 'other-user', workspaceId: 'ws-1' }],
|
||||||
[{ id: 'sched-1', status: 'active', failedCount: 0 }],
|
[{ schedule: { id: 'sched-1', status: 'active', failedCount: 0 } }],
|
||||||
])
|
])
|
||||||
|
|
||||||
const res = await GET(createRequest('http://test/api/schedules?workflowId=wf-1'))
|
const res = await GET(createRequest('http://test/api/schedules?workflowId=wf-1'))
|
||||||
@@ -139,7 +164,7 @@ describe('Schedule GET API', () => {
|
|||||||
it('indicates disabled schedule with failures', async () => {
|
it('indicates disabled schedule with failures', async () => {
|
||||||
mockDbChain([
|
mockDbChain([
|
||||||
[{ userId: 'user-1', workspaceId: null }],
|
[{ userId: 'user-1', workspaceId: null }],
|
||||||
[{ id: 'sched-1', status: 'disabled', failedCount: 100 }],
|
[{ schedule: { id: 'sched-1', status: 'disabled', failedCount: 100 } }],
|
||||||
])
|
])
|
||||||
|
|
||||||
const res = await GET(createRequest('http://test/api/schedules?workflowId=wf-1'))
|
const res = await GET(createRequest('http://test/api/schedules?workflowId=wf-1'))
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import { db } from '@sim/db'
|
import { db } from '@sim/db'
|
||||||
import { workflow, workflowSchedule } from '@sim/db/schema'
|
import { workflow, workflowDeploymentVersion, workflowSchedule } from '@sim/db/schema'
|
||||||
import { createLogger } from '@sim/logger'
|
import { createLogger } from '@sim/logger'
|
||||||
import { and, eq } from 'drizzle-orm'
|
import { and, eq, isNull, or } from 'drizzle-orm'
|
||||||
import { type NextRequest, NextResponse } from 'next/server'
|
import { type NextRequest, NextResponse } from 'next/server'
|
||||||
import { getSession } from '@/lib/auth'
|
import { getSession } from '@/lib/auth'
|
||||||
import { generateRequestId } from '@/lib/core/utils/request'
|
import { generateRequestId } from '@/lib/core/utils/request'
|
||||||
@@ -62,9 +62,24 @@ export async function GET(req: NextRequest) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const schedule = await db
|
const schedule = await db
|
||||||
.select()
|
.select({ schedule: workflowSchedule })
|
||||||
.from(workflowSchedule)
|
.from(workflowSchedule)
|
||||||
.where(conditions.length > 1 ? and(...conditions) : conditions[0])
|
.leftJoin(
|
||||||
|
workflowDeploymentVersion,
|
||||||
|
and(
|
||||||
|
eq(workflowDeploymentVersion.workflowId, workflowSchedule.workflowId),
|
||||||
|
eq(workflowDeploymentVersion.isActive, true)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
.where(
|
||||||
|
and(
|
||||||
|
...conditions,
|
||||||
|
or(
|
||||||
|
eq(workflowSchedule.deploymentVersionId, workflowDeploymentVersion.id),
|
||||||
|
and(isNull(workflowDeploymentVersion.id), isNull(workflowSchedule.deploymentVersionId))
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
.limit(1)
|
.limit(1)
|
||||||
|
|
||||||
const headers = new Headers()
|
const headers = new Headers()
|
||||||
@@ -74,7 +89,7 @@ export async function GET(req: NextRequest) {
|
|||||||
return NextResponse.json({ schedule: null }, { headers })
|
return NextResponse.json({ schedule: null }, { headers })
|
||||||
}
|
}
|
||||||
|
|
||||||
const scheduleData = schedule[0]
|
const scheduleData = schedule[0].schedule
|
||||||
const isDisabled = scheduleData.status === 'disabled'
|
const isDisabled = scheduleData.status === 'disabled'
|
||||||
const hasFailures = scheduleData.failedCount > 0
|
const hasFailures = scheduleData.failedCount > 0
|
||||||
|
|
||||||
|
|||||||
193
apps/sim/app/api/superuser/import-workflow/route.ts
Normal file
193
apps/sim/app/api/superuser/import-workflow/route.ts
Normal file
@@ -0,0 +1,193 @@
|
|||||||
|
import { db } from '@sim/db'
|
||||||
|
import { copilotChats, workflow, workspace } from '@sim/db/schema'
|
||||||
|
import { createLogger } from '@sim/logger'
|
||||||
|
import { eq } from 'drizzle-orm'
|
||||||
|
import { type NextRequest, NextResponse } from 'next/server'
|
||||||
|
import { getSession } from '@/lib/auth'
|
||||||
|
import { verifyEffectiveSuperUser } from '@/lib/templates/permissions'
|
||||||
|
import { parseWorkflowJson } from '@/lib/workflows/operations/import-export'
|
||||||
|
import {
|
||||||
|
loadWorkflowFromNormalizedTables,
|
||||||
|
saveWorkflowToNormalizedTables,
|
||||||
|
} from '@/lib/workflows/persistence/utils'
|
||||||
|
import { sanitizeForExport } from '@/lib/workflows/sanitization/json-sanitizer'
|
||||||
|
|
||||||
|
const logger = createLogger('SuperUserImportWorkflow')
|
||||||
|
|
||||||
|
interface ImportWorkflowRequest {
|
||||||
|
workflowId: string
|
||||||
|
targetWorkspaceId: string
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* POST /api/superuser/import-workflow
|
||||||
|
*
|
||||||
|
* Superuser endpoint to import a workflow by ID along with its copilot chats.
|
||||||
|
* This creates a copy of the workflow in the target workspace with new IDs.
|
||||||
|
* Only the workflow structure and copilot chats are copied - no deployments,
|
||||||
|
* webhooks, triggers, or other sensitive data.
|
||||||
|
*
|
||||||
|
* Requires both isSuperUser flag AND superUserModeEnabled setting.
|
||||||
|
*/
|
||||||
|
export async function POST(request: NextRequest) {
|
||||||
|
try {
|
||||||
|
const session = await getSession()
|
||||||
|
if (!session?.user?.id) {
|
||||||
|
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 })
|
||||||
|
}
|
||||||
|
|
||||||
|
const { effectiveSuperUser, isSuperUser, superUserModeEnabled } =
|
||||||
|
await verifyEffectiveSuperUser(session.user.id)
|
||||||
|
|
||||||
|
if (!effectiveSuperUser) {
|
||||||
|
logger.warn('Non-effective-superuser attempted to access import-workflow endpoint', {
|
||||||
|
userId: session.user.id,
|
||||||
|
isSuperUser,
|
||||||
|
superUserModeEnabled,
|
||||||
|
})
|
||||||
|
return NextResponse.json({ error: 'Forbidden: Superuser access required' }, { status: 403 })
|
||||||
|
}
|
||||||
|
|
||||||
|
const body: ImportWorkflowRequest = await request.json()
|
||||||
|
const { workflowId, targetWorkspaceId } = body
|
||||||
|
|
||||||
|
if (!workflowId) {
|
||||||
|
return NextResponse.json({ error: 'workflowId is required' }, { status: 400 })
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!targetWorkspaceId) {
|
||||||
|
return NextResponse.json({ error: 'targetWorkspaceId is required' }, { status: 400 })
|
||||||
|
}
|
||||||
|
|
||||||
|
// Verify target workspace exists
|
||||||
|
const [targetWorkspace] = await db
|
||||||
|
.select({ id: workspace.id, ownerId: workspace.ownerId })
|
||||||
|
.from(workspace)
|
||||||
|
.where(eq(workspace.id, targetWorkspaceId))
|
||||||
|
.limit(1)
|
||||||
|
|
||||||
|
if (!targetWorkspace) {
|
||||||
|
return NextResponse.json({ error: 'Target workspace not found' }, { status: 404 })
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get the source workflow
|
||||||
|
const [sourceWorkflow] = await db
|
||||||
|
.select()
|
||||||
|
.from(workflow)
|
||||||
|
.where(eq(workflow.id, workflowId))
|
||||||
|
.limit(1)
|
||||||
|
|
||||||
|
if (!sourceWorkflow) {
|
||||||
|
return NextResponse.json({ error: 'Source workflow not found' }, { status: 404 })
|
||||||
|
}
|
||||||
|
|
||||||
|
// Load the workflow state from normalized tables
|
||||||
|
const normalizedData = await loadWorkflowFromNormalizedTables(workflowId)
|
||||||
|
|
||||||
|
if (!normalizedData) {
|
||||||
|
return NextResponse.json(
|
||||||
|
{ error: 'Workflow has no normalized data - cannot import' },
|
||||||
|
{ status: 400 }
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Use existing export logic to create export format
|
||||||
|
const workflowState = {
|
||||||
|
blocks: normalizedData.blocks,
|
||||||
|
edges: normalizedData.edges,
|
||||||
|
loops: normalizedData.loops,
|
||||||
|
parallels: normalizedData.parallels,
|
||||||
|
metadata: {
|
||||||
|
name: sourceWorkflow.name,
|
||||||
|
description: sourceWorkflow.description ?? undefined,
|
||||||
|
color: sourceWorkflow.color,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
const exportData = sanitizeForExport(workflowState)
|
||||||
|
|
||||||
|
// Use existing import logic (parseWorkflowJson regenerates IDs automatically)
|
||||||
|
const { data: importedData, errors } = parseWorkflowJson(JSON.stringify(exportData))
|
||||||
|
|
||||||
|
if (!importedData || errors.length > 0) {
|
||||||
|
return NextResponse.json(
|
||||||
|
{ error: `Failed to parse workflow: ${errors.join(', ')}` },
|
||||||
|
{ status: 400 }
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create new workflow record
|
||||||
|
const newWorkflowId = crypto.randomUUID()
|
||||||
|
const now = new Date()
|
||||||
|
|
||||||
|
await db.insert(workflow).values({
|
||||||
|
id: newWorkflowId,
|
||||||
|
userId: session.user.id,
|
||||||
|
workspaceId: targetWorkspaceId,
|
||||||
|
folderId: null, // Don't copy folder association
|
||||||
|
name: `[Debug Import] ${sourceWorkflow.name}`,
|
||||||
|
description: sourceWorkflow.description,
|
||||||
|
color: sourceWorkflow.color,
|
||||||
|
lastSynced: now,
|
||||||
|
createdAt: now,
|
||||||
|
updatedAt: now,
|
||||||
|
isDeployed: false, // Never copy deployment status
|
||||||
|
runCount: 0,
|
||||||
|
variables: sourceWorkflow.variables || {},
|
||||||
|
})
|
||||||
|
|
||||||
|
// Save using existing persistence logic
|
||||||
|
const saveResult = await saveWorkflowToNormalizedTables(newWorkflowId, importedData)
|
||||||
|
|
||||||
|
if (!saveResult.success) {
|
||||||
|
// Clean up the workflow record if save failed
|
||||||
|
await db.delete(workflow).where(eq(workflow.id, newWorkflowId))
|
||||||
|
return NextResponse.json(
|
||||||
|
{ error: `Failed to save workflow state: ${saveResult.error}` },
|
||||||
|
{ status: 500 }
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Copy copilot chats associated with the source workflow
|
||||||
|
const sourceCopilotChats = await db
|
||||||
|
.select()
|
||||||
|
.from(copilotChats)
|
||||||
|
.where(eq(copilotChats.workflowId, workflowId))
|
||||||
|
|
||||||
|
let copilotChatsImported = 0
|
||||||
|
|
||||||
|
for (const chat of sourceCopilotChats) {
|
||||||
|
await db.insert(copilotChats).values({
|
||||||
|
userId: session.user.id,
|
||||||
|
workflowId: newWorkflowId,
|
||||||
|
title: chat.title ? `[Import] ${chat.title}` : null,
|
||||||
|
messages: chat.messages,
|
||||||
|
model: chat.model,
|
||||||
|
conversationId: null, // Don't copy conversation ID
|
||||||
|
previewYaml: chat.previewYaml,
|
||||||
|
planArtifact: chat.planArtifact,
|
||||||
|
config: chat.config,
|
||||||
|
createdAt: new Date(),
|
||||||
|
updatedAt: new Date(),
|
||||||
|
})
|
||||||
|
copilotChatsImported++
|
||||||
|
}
|
||||||
|
|
||||||
|
logger.info('Superuser imported workflow', {
|
||||||
|
userId: session.user.id,
|
||||||
|
sourceWorkflowId: workflowId,
|
||||||
|
newWorkflowId,
|
||||||
|
targetWorkspaceId,
|
||||||
|
copilotChatsImported,
|
||||||
|
})
|
||||||
|
|
||||||
|
return NextResponse.json({
|
||||||
|
success: true,
|
||||||
|
newWorkflowId,
|
||||||
|
copilotChatsImported,
|
||||||
|
})
|
||||||
|
} catch (error) {
|
||||||
|
logger.error('Error importing workflow', error)
|
||||||
|
return NextResponse.json({ error: 'Internal server error' }, { status: 500 })
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -5,7 +5,7 @@ import { eq } from 'drizzle-orm'
|
|||||||
import { type NextRequest, NextResponse } from 'next/server'
|
import { type NextRequest, NextResponse } from 'next/server'
|
||||||
import { getSession } from '@/lib/auth'
|
import { getSession } from '@/lib/auth'
|
||||||
import { generateRequestId } from '@/lib/core/utils/request'
|
import { generateRequestId } from '@/lib/core/utils/request'
|
||||||
import { verifySuperUser } from '@/lib/templates/permissions'
|
import { verifyEffectiveSuperUser } from '@/lib/templates/permissions'
|
||||||
|
|
||||||
const logger = createLogger('TemplateApprovalAPI')
|
const logger = createLogger('TemplateApprovalAPI')
|
||||||
|
|
||||||
@@ -25,8 +25,8 @@ export async function POST(request: NextRequest, { params }: { params: Promise<{
|
|||||||
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 })
|
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 })
|
||||||
}
|
}
|
||||||
|
|
||||||
const { isSuperUser } = await verifySuperUser(session.user.id)
|
const { effectiveSuperUser } = await verifyEffectiveSuperUser(session.user.id)
|
||||||
if (!isSuperUser) {
|
if (!effectiveSuperUser) {
|
||||||
logger.warn(`[${requestId}] Non-super user attempted to approve template: ${id}`)
|
logger.warn(`[${requestId}] Non-super user attempted to approve template: ${id}`)
|
||||||
return NextResponse.json({ error: 'Only super users can approve templates' }, { status: 403 })
|
return NextResponse.json({ error: 'Only super users can approve templates' }, { status: 403 })
|
||||||
}
|
}
|
||||||
@@ -71,8 +71,8 @@ export async function DELETE(
|
|||||||
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 })
|
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 })
|
||||||
}
|
}
|
||||||
|
|
||||||
const { isSuperUser } = await verifySuperUser(session.user.id)
|
const { effectiveSuperUser } = await verifyEffectiveSuperUser(session.user.id)
|
||||||
if (!isSuperUser) {
|
if (!effectiveSuperUser) {
|
||||||
logger.warn(`[${requestId}] Non-super user attempted to reject template: ${id}`)
|
logger.warn(`[${requestId}] Non-super user attempted to reject template: ${id}`)
|
||||||
return NextResponse.json({ error: 'Only super users can reject templates' }, { status: 403 })
|
return NextResponse.json({ error: 'Only super users can reject templates' }, { status: 403 })
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import { eq } from 'drizzle-orm'
|
|||||||
import { type NextRequest, NextResponse } from 'next/server'
|
import { type NextRequest, NextResponse } from 'next/server'
|
||||||
import { getSession } from '@/lib/auth'
|
import { getSession } from '@/lib/auth'
|
||||||
import { generateRequestId } from '@/lib/core/utils/request'
|
import { generateRequestId } from '@/lib/core/utils/request'
|
||||||
import { verifySuperUser } from '@/lib/templates/permissions'
|
import { verifyEffectiveSuperUser } from '@/lib/templates/permissions'
|
||||||
|
|
||||||
const logger = createLogger('TemplateRejectionAPI')
|
const logger = createLogger('TemplateRejectionAPI')
|
||||||
|
|
||||||
@@ -25,8 +25,8 @@ export async function POST(request: NextRequest, { params }: { params: Promise<{
|
|||||||
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 })
|
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 })
|
||||||
}
|
}
|
||||||
|
|
||||||
const { isSuperUser } = await verifySuperUser(session.user.id)
|
const { effectiveSuperUser } = await verifyEffectiveSuperUser(session.user.id)
|
||||||
if (!isSuperUser) {
|
if (!effectiveSuperUser) {
|
||||||
logger.warn(`[${requestId}] Non-super user attempted to reject template: ${id}`)
|
logger.warn(`[${requestId}] Non-super user attempted to reject template: ${id}`)
|
||||||
return NextResponse.json({ error: 'Only super users can reject templates' }, { status: 403 })
|
return NextResponse.json({ error: 'Only super users can reject templates' }, { status: 403 })
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ import {
|
|||||||
templateCreators,
|
templateCreators,
|
||||||
templateStars,
|
templateStars,
|
||||||
templates,
|
templates,
|
||||||
user,
|
|
||||||
workflow,
|
workflow,
|
||||||
workflowDeploymentVersion,
|
workflowDeploymentVersion,
|
||||||
} from '@sim/db/schema'
|
} from '@sim/db/schema'
|
||||||
@@ -14,6 +13,7 @@ import { v4 as uuidv4 } from 'uuid'
|
|||||||
import { z } from 'zod'
|
import { z } from 'zod'
|
||||||
import { getSession } from '@/lib/auth'
|
import { getSession } from '@/lib/auth'
|
||||||
import { generateRequestId } from '@/lib/core/utils/request'
|
import { generateRequestId } from '@/lib/core/utils/request'
|
||||||
|
import { verifyEffectiveSuperUser } from '@/lib/templates/permissions'
|
||||||
import {
|
import {
|
||||||
extractRequiredCredentials,
|
extractRequiredCredentials,
|
||||||
sanitizeCredentials,
|
sanitizeCredentials,
|
||||||
@@ -70,8 +70,8 @@ export async function GET(request: NextRequest) {
|
|||||||
logger.debug(`[${requestId}] Fetching templates with params:`, params)
|
logger.debug(`[${requestId}] Fetching templates with params:`, params)
|
||||||
|
|
||||||
// Check if user is a super user
|
// Check if user is a super user
|
||||||
const currentUser = await db.select().from(user).where(eq(user.id, session.user.id)).limit(1)
|
const { effectiveSuperUser } = await verifyEffectiveSuperUser(session.user.id)
|
||||||
const isSuperUser = currentUser[0]?.isSuperUser || false
|
const isSuperUser = effectiveSuperUser
|
||||||
|
|
||||||
// Build query conditions
|
// Build query conditions
|
||||||
const conditions = []
|
const conditions = []
|
||||||
|
|||||||
@@ -60,7 +60,17 @@ export const POST = withAdminAuthParams<RouteParams>(async (request, context) =>
|
|||||||
return internalErrorResponse(deployResult.error || 'Failed to deploy workflow')
|
return internalErrorResponse(deployResult.error || 'Failed to deploy workflow')
|
||||||
}
|
}
|
||||||
|
|
||||||
const scheduleResult = await createSchedulesForDeploy(workflowId, normalizedData.blocks, db)
|
if (!deployResult.deploymentVersionId) {
|
||||||
|
await undeployWorkflow({ workflowId })
|
||||||
|
return internalErrorResponse('Failed to resolve deployment version')
|
||||||
|
}
|
||||||
|
|
||||||
|
const scheduleResult = await createSchedulesForDeploy(
|
||||||
|
workflowId,
|
||||||
|
normalizedData.blocks,
|
||||||
|
db,
|
||||||
|
deployResult.deploymentVersionId
|
||||||
|
)
|
||||||
if (!scheduleResult.success) {
|
if (!scheduleResult.success) {
|
||||||
logger.warn(`Schedule creation failed for workflow ${workflowId}: ${scheduleResult.error}`)
|
logger.warn(`Schedule creation failed for workflow ${workflowId}: ${scheduleResult.error}`)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import { db } from '@sim/db'
|
import { db } from '@sim/db'
|
||||||
import { webhook, workflow } from '@sim/db/schema'
|
import { webhook, workflow, workflowDeploymentVersion } from '@sim/db/schema'
|
||||||
import { createLogger } from '@sim/logger'
|
import { createLogger } from '@sim/logger'
|
||||||
import { and, desc, eq } from 'drizzle-orm'
|
import { and, desc, eq, isNull, or } from 'drizzle-orm'
|
||||||
import { nanoid } from 'nanoid'
|
import { nanoid } from 'nanoid'
|
||||||
import { type NextRequest, NextResponse } from 'next/server'
|
import { type NextRequest, NextResponse } from 'next/server'
|
||||||
import { getSession } from '@/lib/auth'
|
import { getSession } from '@/lib/auth'
|
||||||
@@ -71,7 +71,23 @@ export async function GET(request: NextRequest) {
|
|||||||
})
|
})
|
||||||
.from(webhook)
|
.from(webhook)
|
||||||
.innerJoin(workflow, eq(webhook.workflowId, workflow.id))
|
.innerJoin(workflow, eq(webhook.workflowId, workflow.id))
|
||||||
.where(and(eq(webhook.workflowId, workflowId), eq(webhook.blockId, blockId)))
|
.leftJoin(
|
||||||
|
workflowDeploymentVersion,
|
||||||
|
and(
|
||||||
|
eq(workflowDeploymentVersion.workflowId, workflow.id),
|
||||||
|
eq(workflowDeploymentVersion.isActive, true)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
.where(
|
||||||
|
and(
|
||||||
|
eq(webhook.workflowId, workflowId),
|
||||||
|
eq(webhook.blockId, blockId),
|
||||||
|
or(
|
||||||
|
eq(webhook.deploymentVersionId, workflowDeploymentVersion.id),
|
||||||
|
and(isNull(workflowDeploymentVersion.id), isNull(webhook.deploymentVersionId))
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
.orderBy(desc(webhook.updatedAt))
|
.orderBy(desc(webhook.updatedAt))
|
||||||
|
|
||||||
logger.info(
|
logger.info(
|
||||||
@@ -149,7 +165,23 @@ export async function POST(request: NextRequest) {
|
|||||||
const existingForBlock = await db
|
const existingForBlock = await db
|
||||||
.select({ id: webhook.id, path: webhook.path })
|
.select({ id: webhook.id, path: webhook.path })
|
||||||
.from(webhook)
|
.from(webhook)
|
||||||
.where(and(eq(webhook.workflowId, workflowId), eq(webhook.blockId, blockId)))
|
.leftJoin(
|
||||||
|
workflowDeploymentVersion,
|
||||||
|
and(
|
||||||
|
eq(workflowDeploymentVersion.workflowId, workflowId),
|
||||||
|
eq(workflowDeploymentVersion.isActive, true)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
.where(
|
||||||
|
and(
|
||||||
|
eq(webhook.workflowId, workflowId),
|
||||||
|
eq(webhook.blockId, blockId),
|
||||||
|
or(
|
||||||
|
eq(webhook.deploymentVersionId, workflowDeploymentVersion.id),
|
||||||
|
and(isNull(workflowDeploymentVersion.id), isNull(webhook.deploymentVersionId))
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
.limit(1)
|
.limit(1)
|
||||||
|
|
||||||
if (existingForBlock.length > 0) {
|
if (existingForBlock.length > 0) {
|
||||||
@@ -225,7 +257,23 @@ export async function POST(request: NextRequest) {
|
|||||||
const existingForBlock = await db
|
const existingForBlock = await db
|
||||||
.select({ id: webhook.id })
|
.select({ id: webhook.id })
|
||||||
.from(webhook)
|
.from(webhook)
|
||||||
.where(and(eq(webhook.workflowId, workflowId), eq(webhook.blockId, blockId)))
|
.leftJoin(
|
||||||
|
workflowDeploymentVersion,
|
||||||
|
and(
|
||||||
|
eq(workflowDeploymentVersion.workflowId, workflowId),
|
||||||
|
eq(workflowDeploymentVersion.isActive, true)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
.where(
|
||||||
|
and(
|
||||||
|
eq(webhook.workflowId, workflowId),
|
||||||
|
eq(webhook.blockId, blockId),
|
||||||
|
or(
|
||||||
|
eq(webhook.deploymentVersionId, workflowDeploymentVersion.id),
|
||||||
|
and(isNull(workflowDeploymentVersion.id), isNull(webhook.deploymentVersionId))
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
.limit(1)
|
.limit(1)
|
||||||
if (existingForBlock.length > 0) {
|
if (existingForBlock.length > 0) {
|
||||||
targetWebhookId = existingForBlock[0].id
|
targetWebhookId = existingForBlock[0].id
|
||||||
|
|||||||
@@ -152,7 +152,6 @@ export async function POST(
|
|||||||
const response = await queueWebhookExecution(foundWebhook, foundWorkflow, body, request, {
|
const response = await queueWebhookExecution(foundWebhook, foundWorkflow, body, request, {
|
||||||
requestId,
|
requestId,
|
||||||
path,
|
path,
|
||||||
executionTarget: 'deployed',
|
|
||||||
})
|
})
|
||||||
responses.push(response)
|
responses.push(response)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,6 +22,13 @@ export async function GET(_request: Request, { params }: { params: Promise<{ id:
|
|||||||
.select({
|
.select({
|
||||||
id: chat.id,
|
id: chat.id,
|
||||||
identifier: chat.identifier,
|
identifier: chat.identifier,
|
||||||
|
title: chat.title,
|
||||||
|
description: chat.description,
|
||||||
|
customizations: chat.customizations,
|
||||||
|
authType: chat.authType,
|
||||||
|
allowedEmails: chat.allowedEmails,
|
||||||
|
outputConfigs: chat.outputConfigs,
|
||||||
|
password: chat.password,
|
||||||
isActive: chat.isActive,
|
isActive: chat.isActive,
|
||||||
})
|
})
|
||||||
.from(chat)
|
.from(chat)
|
||||||
@@ -34,6 +41,13 @@ export async function GET(_request: Request, { params }: { params: Promise<{ id:
|
|||||||
? {
|
? {
|
||||||
id: deploymentResults[0].id,
|
id: deploymentResults[0].id,
|
||||||
identifier: deploymentResults[0].identifier,
|
identifier: deploymentResults[0].identifier,
|
||||||
|
title: deploymentResults[0].title,
|
||||||
|
description: deploymentResults[0].description,
|
||||||
|
customizations: deploymentResults[0].customizations,
|
||||||
|
authType: deploymentResults[0].authType,
|
||||||
|
allowedEmails: deploymentResults[0].allowedEmails,
|
||||||
|
outputConfigs: deploymentResults[0].outputConfigs,
|
||||||
|
hasPassword: Boolean(deploymentResults[0].password),
|
||||||
}
|
}
|
||||||
: null
|
: null
|
||||||
|
|
||||||
|
|||||||
@@ -10,7 +10,11 @@ import {
|
|||||||
loadWorkflowFromNormalizedTables,
|
loadWorkflowFromNormalizedTables,
|
||||||
undeployWorkflow,
|
undeployWorkflow,
|
||||||
} from '@/lib/workflows/persistence/utils'
|
} from '@/lib/workflows/persistence/utils'
|
||||||
import { createSchedulesForDeploy, validateWorkflowSchedules } from '@/lib/workflows/schedules'
|
import {
|
||||||
|
cleanupDeploymentVersion,
|
||||||
|
createSchedulesForDeploy,
|
||||||
|
validateWorkflowSchedules,
|
||||||
|
} from '@/lib/workflows/schedules'
|
||||||
import { validateWorkflowPermissions } from '@/lib/workflows/utils'
|
import { validateWorkflowPermissions } from '@/lib/workflows/utils'
|
||||||
import { createErrorResponse, createSuccessResponse } from '@/app/api/workflows/utils'
|
import { createErrorResponse, createSuccessResponse } from '@/app/api/workflows/utils'
|
||||||
|
|
||||||
@@ -131,22 +135,6 @@ export async function POST(request: NextRequest, { params }: { params: Promise<{
|
|||||||
return createErrorResponse(`Invalid schedule configuration: ${scheduleValidation.error}`, 400)
|
return createErrorResponse(`Invalid schedule configuration: ${scheduleValidation.error}`, 400)
|
||||||
}
|
}
|
||||||
|
|
||||||
const triggerSaveResult = await saveTriggerWebhooksForDeploy({
|
|
||||||
request,
|
|
||||||
workflowId: id,
|
|
||||||
workflow: workflowData,
|
|
||||||
userId: actorUserId,
|
|
||||||
blocks: normalizedData.blocks,
|
|
||||||
requestId,
|
|
||||||
})
|
|
||||||
|
|
||||||
if (!triggerSaveResult.success) {
|
|
||||||
return createErrorResponse(
|
|
||||||
triggerSaveResult.error?.message || 'Failed to save trigger configuration',
|
|
||||||
triggerSaveResult.error?.status || 500
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
const deployResult = await deployWorkflow({
|
const deployResult = await deployWorkflow({
|
||||||
workflowId: id,
|
workflowId: id,
|
||||||
deployedBy: actorUserId,
|
deployedBy: actorUserId,
|
||||||
@@ -158,14 +146,58 @@ export async function POST(request: NextRequest, { params }: { params: Promise<{
|
|||||||
}
|
}
|
||||||
|
|
||||||
const deployedAt = deployResult.deployedAt!
|
const deployedAt = deployResult.deployedAt!
|
||||||
|
const deploymentVersionId = deployResult.deploymentVersionId
|
||||||
|
|
||||||
|
if (!deploymentVersionId) {
|
||||||
|
await undeployWorkflow({ workflowId: id })
|
||||||
|
return createErrorResponse('Failed to resolve deployment version', 500)
|
||||||
|
}
|
||||||
|
|
||||||
|
const triggerSaveResult = await saveTriggerWebhooksForDeploy({
|
||||||
|
request,
|
||||||
|
workflowId: id,
|
||||||
|
workflow: workflowData,
|
||||||
|
userId: actorUserId,
|
||||||
|
blocks: normalizedData.blocks,
|
||||||
|
requestId,
|
||||||
|
deploymentVersionId,
|
||||||
|
})
|
||||||
|
|
||||||
|
if (!triggerSaveResult.success) {
|
||||||
|
await cleanupDeploymentVersion({
|
||||||
|
workflowId: id,
|
||||||
|
workflow: workflowData as Record<string, unknown>,
|
||||||
|
requestId,
|
||||||
|
deploymentVersionId,
|
||||||
|
})
|
||||||
|
await undeployWorkflow({ workflowId: id })
|
||||||
|
return createErrorResponse(
|
||||||
|
triggerSaveResult.error?.message || 'Failed to save trigger configuration',
|
||||||
|
triggerSaveResult.error?.status || 500
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
let scheduleInfo: { scheduleId?: string; cronExpression?: string; nextRunAt?: Date } = {}
|
let scheduleInfo: { scheduleId?: string; cronExpression?: string; nextRunAt?: Date } = {}
|
||||||
const scheduleResult = await createSchedulesForDeploy(id, normalizedData.blocks, db)
|
const scheduleResult = await createSchedulesForDeploy(
|
||||||
|
id,
|
||||||
|
normalizedData.blocks,
|
||||||
|
db,
|
||||||
|
deploymentVersionId
|
||||||
|
)
|
||||||
if (!scheduleResult.success) {
|
if (!scheduleResult.success) {
|
||||||
logger.error(
|
logger.error(
|
||||||
`[${requestId}] Failed to create schedule for workflow ${id}: ${scheduleResult.error}`
|
`[${requestId}] Failed to create schedule for workflow ${id}: ${scheduleResult.error}`
|
||||||
)
|
)
|
||||||
} else if (scheduleResult.scheduleId) {
|
await cleanupDeploymentVersion({
|
||||||
|
workflowId: id,
|
||||||
|
workflow: workflowData as Record<string, unknown>,
|
||||||
|
requestId,
|
||||||
|
deploymentVersionId,
|
||||||
|
})
|
||||||
|
await undeployWorkflow({ workflowId: id })
|
||||||
|
return createErrorResponse(scheduleResult.error || 'Failed to create schedule', 500)
|
||||||
|
}
|
||||||
|
if (scheduleResult.scheduleId) {
|
||||||
scheduleInfo = {
|
scheduleInfo = {
|
||||||
scheduleId: scheduleResult.scheduleId,
|
scheduleId: scheduleResult.scheduleId,
|
||||||
cronExpression: scheduleResult.cronExpression,
|
cronExpression: scheduleResult.cronExpression,
|
||||||
|
|||||||
@@ -1,10 +1,19 @@
|
|||||||
|
import { db, workflowDeploymentVersion } from '@sim/db'
|
||||||
import { createLogger } from '@sim/logger'
|
import { createLogger } from '@sim/logger'
|
||||||
|
import { and, eq } from 'drizzle-orm'
|
||||||
import type { NextRequest } from 'next/server'
|
import type { NextRequest } from 'next/server'
|
||||||
import { generateRequestId } from '@/lib/core/utils/request'
|
import { generateRequestId } from '@/lib/core/utils/request'
|
||||||
import { syncMcpToolsForWorkflow } from '@/lib/mcp/workflow-mcp-sync'
|
import { syncMcpToolsForWorkflow } from '@/lib/mcp/workflow-mcp-sync'
|
||||||
|
import { saveTriggerWebhooksForDeploy } from '@/lib/webhooks/deploy'
|
||||||
import { activateWorkflowVersion } from '@/lib/workflows/persistence/utils'
|
import { activateWorkflowVersion } from '@/lib/workflows/persistence/utils'
|
||||||
|
import {
|
||||||
|
cleanupDeploymentVersion,
|
||||||
|
createSchedulesForDeploy,
|
||||||
|
validateWorkflowSchedules,
|
||||||
|
} from '@/lib/workflows/schedules'
|
||||||
import { validateWorkflowPermissions } from '@/lib/workflows/utils'
|
import { validateWorkflowPermissions } from '@/lib/workflows/utils'
|
||||||
import { createErrorResponse, createSuccessResponse } from '@/app/api/workflows/utils'
|
import { createErrorResponse, createSuccessResponse } from '@/app/api/workflows/utils'
|
||||||
|
import type { BlockState } from '@/stores/workflows/workflow/types'
|
||||||
|
|
||||||
const logger = createLogger('WorkflowActivateDeploymentAPI')
|
const logger = createLogger('WorkflowActivateDeploymentAPI')
|
||||||
|
|
||||||
@@ -19,30 +28,135 @@ export async function POST(
|
|||||||
const { id, version } = await params
|
const { id, version } = await params
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const { error } = await validateWorkflowPermissions(id, requestId, 'admin')
|
const {
|
||||||
|
error,
|
||||||
|
session,
|
||||||
|
workflow: workflowData,
|
||||||
|
} = await validateWorkflowPermissions(id, requestId, 'admin')
|
||||||
if (error) {
|
if (error) {
|
||||||
return createErrorResponse(error.message, error.status)
|
return createErrorResponse(error.message, error.status)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const actorUserId = session?.user?.id
|
||||||
|
if (!actorUserId) {
|
||||||
|
logger.warn(`[${requestId}] Unable to resolve actor user for deployment activation: ${id}`)
|
||||||
|
return createErrorResponse('Unable to determine activating user', 400)
|
||||||
|
}
|
||||||
|
|
||||||
const versionNum = Number(version)
|
const versionNum = Number(version)
|
||||||
if (!Number.isFinite(versionNum)) {
|
if (!Number.isFinite(versionNum)) {
|
||||||
return createErrorResponse('Invalid version number', 400)
|
return createErrorResponse('Invalid version number', 400)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const [versionRow] = await db
|
||||||
|
.select({
|
||||||
|
id: workflowDeploymentVersion.id,
|
||||||
|
state: workflowDeploymentVersion.state,
|
||||||
|
})
|
||||||
|
.from(workflowDeploymentVersion)
|
||||||
|
.where(
|
||||||
|
and(
|
||||||
|
eq(workflowDeploymentVersion.workflowId, id),
|
||||||
|
eq(workflowDeploymentVersion.version, versionNum)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
.limit(1)
|
||||||
|
|
||||||
|
if (!versionRow?.state) {
|
||||||
|
return createErrorResponse('Deployment version not found', 404)
|
||||||
|
}
|
||||||
|
|
||||||
|
const [currentActiveVersion] = await db
|
||||||
|
.select({ id: workflowDeploymentVersion.id })
|
||||||
|
.from(workflowDeploymentVersion)
|
||||||
|
.where(
|
||||||
|
and(
|
||||||
|
eq(workflowDeploymentVersion.workflowId, id),
|
||||||
|
eq(workflowDeploymentVersion.isActive, true)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
.limit(1)
|
||||||
|
|
||||||
|
const previousVersionId = currentActiveVersion?.id
|
||||||
|
|
||||||
|
const deployedState = versionRow.state as { blocks?: Record<string, BlockState> }
|
||||||
|
const blocks = deployedState.blocks
|
||||||
|
if (!blocks || typeof blocks !== 'object') {
|
||||||
|
return createErrorResponse('Invalid deployed state structure', 500)
|
||||||
|
}
|
||||||
|
|
||||||
|
const triggerSaveResult = await saveTriggerWebhooksForDeploy({
|
||||||
|
request,
|
||||||
|
workflowId: id,
|
||||||
|
workflow: workflowData as Record<string, unknown>,
|
||||||
|
userId: actorUserId,
|
||||||
|
blocks,
|
||||||
|
requestId,
|
||||||
|
deploymentVersionId: versionRow.id,
|
||||||
|
})
|
||||||
|
|
||||||
|
if (!triggerSaveResult.success) {
|
||||||
|
return createErrorResponse(
|
||||||
|
triggerSaveResult.error?.message || 'Failed to sync trigger configuration',
|
||||||
|
triggerSaveResult.error?.status || 500
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
const scheduleValidation = validateWorkflowSchedules(blocks)
|
||||||
|
if (!scheduleValidation.isValid) {
|
||||||
|
return createErrorResponse(`Invalid schedule configuration: ${scheduleValidation.error}`, 400)
|
||||||
|
}
|
||||||
|
|
||||||
|
const scheduleResult = await createSchedulesForDeploy(id, blocks, db, versionRow.id)
|
||||||
|
|
||||||
|
if (!scheduleResult.success) {
|
||||||
|
await cleanupDeploymentVersion({
|
||||||
|
workflowId: id,
|
||||||
|
workflow: workflowData as Record<string, unknown>,
|
||||||
|
requestId,
|
||||||
|
deploymentVersionId: versionRow.id,
|
||||||
|
})
|
||||||
|
return createErrorResponse(scheduleResult.error || 'Failed to sync schedules', 500)
|
||||||
|
}
|
||||||
|
|
||||||
const result = await activateWorkflowVersion({ workflowId: id, version: versionNum })
|
const result = await activateWorkflowVersion({ workflowId: id, version: versionNum })
|
||||||
if (!result.success) {
|
if (!result.success) {
|
||||||
|
await cleanupDeploymentVersion({
|
||||||
|
workflowId: id,
|
||||||
|
workflow: workflowData as Record<string, unknown>,
|
||||||
|
requestId,
|
||||||
|
deploymentVersionId: versionRow.id,
|
||||||
|
})
|
||||||
return createErrorResponse(result.error || 'Failed to activate deployment', 400)
|
return createErrorResponse(result.error || 'Failed to activate deployment', 400)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (result.state) {
|
if (previousVersionId && previousVersionId !== versionRow.id) {
|
||||||
await syncMcpToolsForWorkflow({
|
try {
|
||||||
workflowId: id,
|
logger.info(
|
||||||
requestId,
|
`[${requestId}] Cleaning up previous version ${previousVersionId} webhooks/schedules`
|
||||||
state: result.state,
|
)
|
||||||
context: 'activate',
|
await cleanupDeploymentVersion({
|
||||||
})
|
workflowId: id,
|
||||||
|
workflow: workflowData as Record<string, unknown>,
|
||||||
|
requestId,
|
||||||
|
deploymentVersionId: previousVersionId,
|
||||||
|
})
|
||||||
|
logger.info(`[${requestId}] Previous version cleanup completed`)
|
||||||
|
} catch (cleanupError) {
|
||||||
|
logger.error(
|
||||||
|
`[${requestId}] Failed to clean up previous version ${previousVersionId}`,
|
||||||
|
cleanupError
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
await syncMcpToolsForWorkflow({
|
||||||
|
workflowId: id,
|
||||||
|
requestId,
|
||||||
|
state: versionRow.state,
|
||||||
|
context: 'activate',
|
||||||
|
})
|
||||||
|
|
||||||
return createSuccessResponse({ success: true, deployedAt: result.deployedAt })
|
return createSuccessResponse({ success: true, deployedAt: result.deployedAt })
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
logger.error(`[${requestId}] Error activating deployment for workflow: ${id}`, error)
|
logger.error(`[${requestId}] Error activating deployment for workflow: ${id}`, error)
|
||||||
|
|||||||
@@ -110,6 +110,7 @@ type AsyncExecutionParams = {
|
|||||||
userId: string
|
userId: string
|
||||||
input: any
|
input: any
|
||||||
triggerType: CoreTriggerType
|
triggerType: CoreTriggerType
|
||||||
|
preflighted?: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -132,6 +133,7 @@ async function handleAsyncExecution(params: AsyncExecutionParams): Promise<NextR
|
|||||||
userId,
|
userId,
|
||||||
input,
|
input,
|
||||||
triggerType,
|
triggerType,
|
||||||
|
preflighted: params.preflighted,
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@@ -264,6 +266,7 @@ export async function POST(req: NextRequest, { params }: { params: Promise<{ id:
|
|||||||
requestId
|
requestId
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const shouldPreflightEnvVars = isAsyncMode && isTriggerDevEnabled
|
||||||
const preprocessResult = await preprocessExecution({
|
const preprocessResult = await preprocessExecution({
|
||||||
workflowId,
|
workflowId,
|
||||||
userId,
|
userId,
|
||||||
@@ -272,6 +275,9 @@ export async function POST(req: NextRequest, { params }: { params: Promise<{ id:
|
|||||||
requestId,
|
requestId,
|
||||||
checkDeployment: !shouldUseDraftState,
|
checkDeployment: !shouldUseDraftState,
|
||||||
loggingSession,
|
loggingSession,
|
||||||
|
preflightEnvVars: shouldPreflightEnvVars,
|
||||||
|
useDraftState: shouldUseDraftState,
|
||||||
|
envUserId: isClientSession ? userId : undefined,
|
||||||
})
|
})
|
||||||
|
|
||||||
if (!preprocessResult.success) {
|
if (!preprocessResult.success) {
|
||||||
@@ -303,6 +309,7 @@ export async function POST(req: NextRequest, { params }: { params: Promise<{ id:
|
|||||||
userId: actorUserId,
|
userId: actorUserId,
|
||||||
input,
|
input,
|
||||||
triggerType: loggingTriggerType,
|
triggerType: loggingTriggerType,
|
||||||
|
preflighted: shouldPreflightEnvVars,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import React, { type HTMLAttributes, type ReactNode } from 'react'
|
import React, { type HTMLAttributes, memo, type ReactNode, useMemo } from 'react'
|
||||||
import ReactMarkdown from 'react-markdown'
|
import ReactMarkdown from 'react-markdown'
|
||||||
import remarkGfm from 'remark-gfm'
|
import remarkGfm from 'remark-gfm'
|
||||||
import { Tooltip } from '@/components/emcn'
|
import { Tooltip } from '@/components/emcn'
|
||||||
@@ -23,24 +23,16 @@ export function LinkWithPreview({ href, children }: { href: string; children: Re
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function MarkdownRenderer({
|
const REMARK_PLUGINS = [remarkGfm]
|
||||||
content,
|
|
||||||
customLinkComponent,
|
|
||||||
}: {
|
|
||||||
content: string
|
|
||||||
customLinkComponent?: typeof LinkWithPreview
|
|
||||||
}) {
|
|
||||||
const LinkComponent = customLinkComponent || LinkWithPreview
|
|
||||||
|
|
||||||
const customComponents = {
|
function createCustomComponents(LinkComponent: typeof LinkWithPreview) {
|
||||||
// Paragraph
|
return {
|
||||||
p: ({ children }: React.HTMLAttributes<HTMLParagraphElement>) => (
|
p: ({ children }: React.HTMLAttributes<HTMLParagraphElement>) => (
|
||||||
<p className='mb-1 font-sans text-base text-gray-800 leading-relaxed last:mb-0 dark:text-gray-200'>
|
<p className='mb-1 font-sans text-base text-gray-800 leading-relaxed last:mb-0 dark:text-gray-200'>
|
||||||
{children}
|
{children}
|
||||||
</p>
|
</p>
|
||||||
),
|
),
|
||||||
|
|
||||||
// Headings
|
|
||||||
h1: ({ children }: React.HTMLAttributes<HTMLHeadingElement>) => (
|
h1: ({ children }: React.HTMLAttributes<HTMLHeadingElement>) => (
|
||||||
<h1 className='mt-10 mb-5 font-sans font-semibold text-2xl text-gray-900 dark:text-gray-100'>
|
<h1 className='mt-10 mb-5 font-sans font-semibold text-2xl text-gray-900 dark:text-gray-100'>
|
||||||
{children}
|
{children}
|
||||||
@@ -62,7 +54,6 @@ export default function MarkdownRenderer({
|
|||||||
</h4>
|
</h4>
|
||||||
),
|
),
|
||||||
|
|
||||||
// Lists
|
|
||||||
ul: ({ children }: React.HTMLAttributes<HTMLUListElement>) => (
|
ul: ({ children }: React.HTMLAttributes<HTMLUListElement>) => (
|
||||||
<ul
|
<ul
|
||||||
className='mt-1 mb-1 space-y-1 pl-6 font-sans text-gray-800 dark:text-gray-200'
|
className='mt-1 mb-1 space-y-1 pl-6 font-sans text-gray-800 dark:text-gray-200'
|
||||||
@@ -89,7 +80,6 @@ export default function MarkdownRenderer({
|
|||||||
</li>
|
</li>
|
||||||
),
|
),
|
||||||
|
|
||||||
// Code blocks
|
|
||||||
pre: ({ children }: HTMLAttributes<HTMLPreElement>) => {
|
pre: ({ children }: HTMLAttributes<HTMLPreElement>) => {
|
||||||
let codeProps: HTMLAttributes<HTMLElement> = {}
|
let codeProps: HTMLAttributes<HTMLElement> = {}
|
||||||
let codeContent: ReactNode = children
|
let codeContent: ReactNode = children
|
||||||
@@ -120,7 +110,6 @@ export default function MarkdownRenderer({
|
|||||||
)
|
)
|
||||||
},
|
},
|
||||||
|
|
||||||
// Inline code
|
|
||||||
code: ({
|
code: ({
|
||||||
inline,
|
inline,
|
||||||
className,
|
className,
|
||||||
@@ -144,24 +133,20 @@ export default function MarkdownRenderer({
|
|||||||
)
|
)
|
||||||
},
|
},
|
||||||
|
|
||||||
// Blockquotes
|
|
||||||
blockquote: ({ children }: React.HTMLAttributes<HTMLQuoteElement>) => (
|
blockquote: ({ children }: React.HTMLAttributes<HTMLQuoteElement>) => (
|
||||||
<blockquote className='my-4 border-gray-300 border-l-4 py-1 pl-4 font-sans text-gray-700 italic dark:border-gray-600 dark:text-gray-300'>
|
<blockquote className='my-4 border-gray-300 border-l-4 py-1 pl-4 font-sans text-gray-700 italic dark:border-gray-600 dark:text-gray-300'>
|
||||||
{children}
|
{children}
|
||||||
</blockquote>
|
</blockquote>
|
||||||
),
|
),
|
||||||
|
|
||||||
// Horizontal rule
|
|
||||||
hr: () => <hr className='my-8 border-gray-500/[.07] border-t dark:border-gray-400/[.07]' />,
|
hr: () => <hr className='my-8 border-gray-500/[.07] border-t dark:border-gray-400/[.07]' />,
|
||||||
|
|
||||||
// Links
|
|
||||||
a: ({ href, children, ...props }: React.AnchorHTMLAttributes<HTMLAnchorElement>) => (
|
a: ({ href, children, ...props }: React.AnchorHTMLAttributes<HTMLAnchorElement>) => (
|
||||||
<LinkComponent href={href || '#'} {...props}>
|
<LinkComponent href={href || '#'} {...props}>
|
||||||
{children}
|
{children}
|
||||||
</LinkComponent>
|
</LinkComponent>
|
||||||
),
|
),
|
||||||
|
|
||||||
// Tables
|
|
||||||
table: ({ children }: React.TableHTMLAttributes<HTMLTableElement>) => (
|
table: ({ children }: React.TableHTMLAttributes<HTMLTableElement>) => (
|
||||||
<div className='my-4 w-full overflow-x-auto'>
|
<div className='my-4 w-full overflow-x-auto'>
|
||||||
<table className='min-w-full table-auto border border-gray-300 font-sans text-sm dark:border-gray-700'>
|
<table className='min-w-full table-auto border border-gray-300 font-sans text-sm dark:border-gray-700'>
|
||||||
@@ -193,7 +178,6 @@ export default function MarkdownRenderer({
|
|||||||
</td>
|
</td>
|
||||||
),
|
),
|
||||||
|
|
||||||
// Images
|
|
||||||
img: ({ src, alt, ...props }: React.ImgHTMLAttributes<HTMLImageElement>) => (
|
img: ({ src, alt, ...props }: React.ImgHTMLAttributes<HTMLImageElement>) => (
|
||||||
<img
|
<img
|
||||||
src={src}
|
src={src}
|
||||||
@@ -203,15 +187,33 @@ export default function MarkdownRenderer({
|
|||||||
/>
|
/>
|
||||||
),
|
),
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const DEFAULT_COMPONENTS = createCustomComponents(LinkWithPreview)
|
||||||
|
|
||||||
|
const MarkdownRenderer = memo(function MarkdownRenderer({
|
||||||
|
content,
|
||||||
|
customLinkComponent,
|
||||||
|
}: {
|
||||||
|
content: string
|
||||||
|
customLinkComponent?: typeof LinkWithPreview
|
||||||
|
}) {
|
||||||
|
const components = useMemo(() => {
|
||||||
|
if (!customLinkComponent) {
|
||||||
|
return DEFAULT_COMPONENTS
|
||||||
|
}
|
||||||
|
return createCustomComponents(customLinkComponent)
|
||||||
|
}, [customLinkComponent])
|
||||||
|
|
||||||
// Pre-process content to fix common issues
|
|
||||||
const processedContent = content.trim()
|
const processedContent = content.trim()
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className='space-y-4 break-words font-sans text-[#0D0D0D] text-base leading-relaxed dark:text-gray-100'>
|
<div className='space-y-4 break-words font-sans text-[#0D0D0D] text-base leading-relaxed dark:text-gray-100'>
|
||||||
<ReactMarkdown remarkPlugins={[remarkGfm]} components={customComponents}>
|
<ReactMarkdown remarkPlugins={REMARK_PLUGINS} components={components}>
|
||||||
{processedContent}
|
{processedContent}
|
||||||
</ReactMarkdown>
|
</ReactMarkdown>
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
}
|
})
|
||||||
|
|
||||||
|
export default MarkdownRenderer
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import { generateBrandedMetadata, generateStructuredData } from '@/lib/branding/
|
|||||||
import { PostHogProvider } from '@/app/_shell/providers/posthog-provider'
|
import { PostHogProvider } from '@/app/_shell/providers/posthog-provider'
|
||||||
import '@/app/_styles/globals.css'
|
import '@/app/_styles/globals.css'
|
||||||
import { OneDollarStats } from '@/components/analytics/onedollarstats'
|
import { OneDollarStats } from '@/components/analytics/onedollarstats'
|
||||||
import { isReactGrabEnabled } from '@/lib/core/config/feature-flags'
|
import { isReactGrabEnabled, isReactScanEnabled } from '@/lib/core/config/feature-flags'
|
||||||
import { HydrationErrorHandler } from '@/app/_shell/hydration-error-handler'
|
import { HydrationErrorHandler } from '@/app/_shell/hydration-error-handler'
|
||||||
import { QueryProvider } from '@/app/_shell/providers/query-provider'
|
import { QueryProvider } from '@/app/_shell/providers/query-provider'
|
||||||
import { SessionProvider } from '@/app/_shell/providers/session-provider'
|
import { SessionProvider } from '@/app/_shell/providers/session-provider'
|
||||||
@@ -35,6 +35,13 @@ export default function RootLayout({ children }: { children: React.ReactNode })
|
|||||||
return (
|
return (
|
||||||
<html lang='en' suppressHydrationWarning>
|
<html lang='en' suppressHydrationWarning>
|
||||||
<head>
|
<head>
|
||||||
|
{isReactScanEnabled && (
|
||||||
|
<Script
|
||||||
|
src='https://unpkg.com/react-scan/dist/auto.global.js'
|
||||||
|
crossOrigin='anonymous'
|
||||||
|
strategy='beforeInteractive'
|
||||||
|
/>
|
||||||
|
)}
|
||||||
{isReactGrabEnabled && (
|
{isReactGrabEnabled && (
|
||||||
<Script
|
<Script
|
||||||
src='https://unpkg.com/react-grab/dist/index.global.js'
|
src='https://unpkg.com/react-grab/dist/index.global.js'
|
||||||
|
|||||||
@@ -1,10 +1,13 @@
|
|||||||
'use client'
|
'use client'
|
||||||
|
|
||||||
import { Suspense, useEffect, useState } from 'react'
|
import { Suspense, useEffect, useState } from 'react'
|
||||||
import { CheckCircle, Heart, Info, Loader2, XCircle } from 'lucide-react'
|
import { Loader2 } from 'lucide-react'
|
||||||
import { useSearchParams } from 'next/navigation'
|
import { useSearchParams } from 'next/navigation'
|
||||||
import { Button, Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui'
|
import { inter } from '@/app/_styles/fonts/inter/inter'
|
||||||
import { useBrandConfig } from '@/lib/branding/branding'
|
import { soehne } from '@/app/_styles/fonts/soehne/soehne'
|
||||||
|
import { BrandedButton } from '@/app/(auth)/components/branded-button'
|
||||||
|
import { SupportFooter } from '@/app/(auth)/components/support-footer'
|
||||||
|
import { InviteLayout } from '@/app/invite/components'
|
||||||
|
|
||||||
interface UnsubscribeData {
|
interface UnsubscribeData {
|
||||||
success: boolean
|
success: boolean
|
||||||
@@ -27,7 +30,6 @@ function UnsubscribeContent() {
|
|||||||
const [error, setError] = useState<string | null>(null)
|
const [error, setError] = useState<string | null>(null)
|
||||||
const [processing, setProcessing] = useState(false)
|
const [processing, setProcessing] = useState(false)
|
||||||
const [unsubscribed, setUnsubscribed] = useState(false)
|
const [unsubscribed, setUnsubscribed] = useState(false)
|
||||||
const brand = useBrandConfig()
|
|
||||||
|
|
||||||
const email = searchParams.get('email')
|
const email = searchParams.get('email')
|
||||||
const token = searchParams.get('token')
|
const token = searchParams.get('token')
|
||||||
@@ -109,7 +111,7 @@ function UnsubscribeContent() {
|
|||||||
} else {
|
} else {
|
||||||
setError(result.error || 'Failed to unsubscribe')
|
setError(result.error || 'Failed to unsubscribe')
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch {
|
||||||
setError('Failed to process unsubscribe request')
|
setError('Failed to process unsubscribe request')
|
||||||
} finally {
|
} finally {
|
||||||
setProcessing(false)
|
setProcessing(false)
|
||||||
@@ -118,272 +120,171 @@ function UnsubscribeContent() {
|
|||||||
|
|
||||||
if (loading) {
|
if (loading) {
|
||||||
return (
|
return (
|
||||||
<div className='before:-z-50 relative flex min-h-screen items-center justify-center before:pointer-events-none before:fixed before:inset-0 before:bg-white'>
|
<InviteLayout>
|
||||||
<Card className='w-full max-w-md border shadow-sm'>
|
<div className='space-y-1 text-center'>
|
||||||
<CardContent className='flex items-center justify-center p-8'>
|
<h1 className={`${soehne.className} font-medium text-[32px] text-black tracking-tight`}>
|
||||||
<Loader2 className='h-8 w-8 animate-spin text-muted-foreground' />
|
Loading
|
||||||
</CardContent>
|
</h1>
|
||||||
</Card>
|
<p className={`${inter.className} font-[380] text-[16px] text-muted-foreground`}>
|
||||||
</div>
|
Validating your unsubscribe link...
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
<div className={`${inter.className} mt-8 flex w-full items-center justify-center py-8`}>
|
||||||
|
<Loader2 className='h-8 w-8 animate-spin text-muted-foreground' />
|
||||||
|
</div>
|
||||||
|
<SupportFooter position='absolute' />
|
||||||
|
</InviteLayout>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (error) {
|
if (error) {
|
||||||
return (
|
return (
|
||||||
<div className='before:-z-50 relative flex min-h-screen items-center justify-center p-4 before:pointer-events-none before:fixed before:inset-0 before:bg-white'>
|
<InviteLayout>
|
||||||
<Card className='w-full max-w-md border shadow-sm'>
|
<div className='space-y-1 text-center'>
|
||||||
<CardHeader className='text-center'>
|
<h1 className={`${soehne.className} font-medium text-[32px] text-black tracking-tight`}>
|
||||||
<XCircle className='mx-auto mb-2 h-12 w-12 text-red-500' />
|
Invalid Unsubscribe Link
|
||||||
<CardTitle className='text-foreground'>Invalid Unsubscribe Link</CardTitle>
|
</h1>
|
||||||
<CardDescription className='text-muted-foreground'>
|
<p className={`${inter.className} font-[380] text-[16px] text-muted-foreground`}>
|
||||||
This unsubscribe link is invalid or has expired
|
{error}
|
||||||
</CardDescription>
|
</p>
|
||||||
</CardHeader>
|
</div>
|
||||||
<CardContent className='space-y-4'>
|
|
||||||
<div className='rounded-lg border bg-red-50 p-4'>
|
|
||||||
<p className='text-red-800 text-sm'>
|
|
||||||
<strong>Error:</strong> {error}
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div className='space-y-3'>
|
<div className={`${inter.className} mt-8 w-full max-w-[410px] space-y-3`}>
|
||||||
<p className='text-muted-foreground text-sm'>This could happen if:</p>
|
<BrandedButton onClick={() => window.history.back()}>Go Back</BrandedButton>
|
||||||
<ul className='ml-4 list-inside list-disc space-y-1 text-muted-foreground text-sm'>
|
</div>
|
||||||
<li>The link is missing required parameters</li>
|
|
||||||
<li>The link has expired or been used already</li>
|
|
||||||
<li>The link was copied incorrectly</li>
|
|
||||||
</ul>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div className='mt-6 flex flex-col gap-3'>
|
<SupportFooter position='absolute' />
|
||||||
<Button
|
</InviteLayout>
|
||||||
onClick={() =>
|
|
||||||
window.open(
|
|
||||||
`mailto:${brand.supportEmail}?subject=Unsubscribe%20Help&body=Hi%2C%20I%20need%20help%20unsubscribing%20from%20emails.%20My%20unsubscribe%20link%20is%20not%20working.`,
|
|
||||||
'_blank'
|
|
||||||
)
|
|
||||||
}
|
|
||||||
className='w-full bg-[var(--brand-primary-hex)] font-medium text-white shadow-sm transition-colors duration-200 hover:bg-[var(--brand-primary-hover-hex)]'
|
|
||||||
>
|
|
||||||
Contact Support
|
|
||||||
</Button>
|
|
||||||
<Button onClick={() => window.history.back()} variant='outline' className='w-full'>
|
|
||||||
Go Back
|
|
||||||
</Button>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div className='mt-4 text-center'>
|
|
||||||
<p className='text-muted-foreground text-xs'>
|
|
||||||
Need immediate help? Email us at{' '}
|
|
||||||
<a
|
|
||||||
href={`mailto:${brand.supportEmail}`}
|
|
||||||
className='text-muted-foreground hover:underline'
|
|
||||||
>
|
|
||||||
{brand.supportEmail}
|
|
||||||
</a>
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
</CardContent>
|
|
||||||
</Card>
|
|
||||||
</div>
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (data?.isTransactional) {
|
if (data?.isTransactional) {
|
||||||
return (
|
return (
|
||||||
<div className='before:-z-50 relative flex min-h-screen items-center justify-center p-4 before:pointer-events-none before:fixed before:inset-0 before:bg-white'>
|
<InviteLayout>
|
||||||
<Card className='w-full max-w-md border shadow-sm'>
|
<div className='space-y-1 text-center'>
|
||||||
<CardHeader className='text-center'>
|
<h1 className={`${soehne.className} font-medium text-[32px] text-black tracking-tight`}>
|
||||||
<Info className='mx-auto mb-2 h-12 w-12 text-blue-500' />
|
Important Account Emails
|
||||||
<CardTitle className='text-foreground'>Important Account Emails</CardTitle>
|
</h1>
|
||||||
<CardDescription className='text-muted-foreground'>
|
<p className={`${inter.className} font-[380] text-[16px] text-muted-foreground`}>
|
||||||
This email contains important information about your account
|
Transactional emails like password resets, account confirmations, and security alerts
|
||||||
</CardDescription>
|
cannot be unsubscribed from as they contain essential information for your account.
|
||||||
</CardHeader>
|
</p>
|
||||||
<CardContent className='space-y-4'>
|
</div>
|
||||||
<div className='rounded-lg border bg-blue-50 p-4'>
|
|
||||||
<p className='text-blue-800 text-sm'>
|
|
||||||
<strong>Transactional emails</strong> like password resets, account confirmations,
|
|
||||||
and security alerts cannot be unsubscribed from as they contain essential
|
|
||||||
information for your account security and functionality.
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div className='space-y-3'>
|
<div className={`${inter.className} mt-8 w-full max-w-[410px] space-y-3`}>
|
||||||
<p className='text-foreground text-sm'>
|
<BrandedButton onClick={() => window.close()}>Close</BrandedButton>
|
||||||
If you no longer wish to receive these emails, you can:
|
</div>
|
||||||
</p>
|
|
||||||
<ul className='ml-4 list-inside list-disc space-y-1 text-muted-foreground text-sm'>
|
|
||||||
<li>Close your account entirely</li>
|
|
||||||
<li>Contact our support team for assistance</li>
|
|
||||||
</ul>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div className='mt-6 flex flex-col gap-3'>
|
<SupportFooter position='absolute' />
|
||||||
<Button
|
</InviteLayout>
|
||||||
onClick={() =>
|
|
||||||
window.open(
|
|
||||||
`mailto:${brand.supportEmail}?subject=Account%20Help&body=Hi%2C%20I%20need%20help%20with%20my%20account%20emails.`,
|
|
||||||
'_blank'
|
|
||||||
)
|
|
||||||
}
|
|
||||||
className='w-full bg-blue-600 text-white hover:bg-blue-700'
|
|
||||||
>
|
|
||||||
Contact Support
|
|
||||||
</Button>
|
|
||||||
<Button onClick={() => window.close()} variant='outline' className='w-full'>
|
|
||||||
Close
|
|
||||||
</Button>
|
|
||||||
</div>
|
|
||||||
</CardContent>
|
|
||||||
</Card>
|
|
||||||
</div>
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (unsubscribed) {
|
if (unsubscribed) {
|
||||||
return (
|
return (
|
||||||
<div className='before:-z-50 relative flex min-h-screen items-center justify-center before:pointer-events-none before:fixed before:inset-0 before:bg-white'>
|
<InviteLayout>
|
||||||
<Card className='w-full max-w-md border shadow-sm'>
|
<div className='space-y-1 text-center'>
|
||||||
<CardHeader className='text-center'>
|
<h1 className={`${soehne.className} font-medium text-[32px] text-black tracking-tight`}>
|
||||||
<CheckCircle className='mx-auto mb-2 h-12 w-12 text-green-500' />
|
Successfully Unsubscribed
|
||||||
<CardTitle className='text-foreground'>Successfully Unsubscribed</CardTitle>
|
</h1>
|
||||||
<CardDescription className='text-muted-foreground'>
|
<p className={`${inter.className} font-[380] text-[16px] text-muted-foreground`}>
|
||||||
You have been unsubscribed from our emails. You will stop receiving emails within 48
|
You have been unsubscribed from our emails. You will stop receiving emails within 48
|
||||||
hours.
|
hours.
|
||||||
</CardDescription>
|
</p>
|
||||||
</CardHeader>
|
</div>
|
||||||
<CardContent className='text-center'>
|
|
||||||
<p className='text-muted-foreground text-sm'>
|
<div className={`${inter.className} mt-8 w-full max-w-[410px] space-y-3`}>
|
||||||
If you change your mind, you can always update your email preferences in your account
|
<BrandedButton onClick={() => window.close()}>Close</BrandedButton>
|
||||||
settings or contact us at{' '}
|
</div>
|
||||||
<a
|
|
||||||
href={`mailto:${brand.supportEmail}`}
|
<SupportFooter position='absolute' />
|
||||||
className='text-muted-foreground hover:underline'
|
</InviteLayout>
|
||||||
>
|
|
||||||
{brand.supportEmail}
|
|
||||||
</a>
|
|
||||||
</p>
|
|
||||||
</CardContent>
|
|
||||||
</Card>
|
|
||||||
</div>
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const isAlreadyUnsubscribedFromAll = data?.currentPreferences.unsubscribeAll
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className='before:-z-50 relative flex min-h-screen items-center justify-center p-4 before:pointer-events-none before:fixed before:inset-0 before:bg-white'>
|
<InviteLayout>
|
||||||
<Card className='w-full max-w-md border shadow-sm'>
|
<div className='space-y-1 text-center'>
|
||||||
<CardHeader className='text-center'>
|
<h1 className={`${soehne.className} font-medium text-[32px] text-black tracking-tight`}>
|
||||||
<Heart className='mx-auto mb-2 h-12 w-12 text-red-500' />
|
Email Preferences
|
||||||
<CardTitle className='text-foreground'>We're sorry to see you go!</CardTitle>
|
</h1>
|
||||||
<CardDescription className='text-muted-foreground'>
|
<p className={`${inter.className} font-[380] text-[16px] text-muted-foreground`}>
|
||||||
We understand email preferences are personal. Choose which emails you'd like to
|
Choose which emails you'd like to stop receiving.
|
||||||
stop receiving from Sim.
|
</p>
|
||||||
</CardDescription>
|
<p className={`${inter.className} mt-2 font-[380] text-[14px] text-muted-foreground`}>
|
||||||
<div className='mt-2 rounded-lg border bg-muted/50 p-3'>
|
{data?.email}
|
||||||
<p className='text-muted-foreground text-xs'>
|
</p>
|
||||||
Email: <span className='font-medium text-foreground'>{data?.email}</span>
|
</div>
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
</CardHeader>
|
|
||||||
<CardContent className='space-y-4'>
|
|
||||||
<div className='space-y-3'>
|
|
||||||
<Button
|
|
||||||
onClick={() => handleUnsubscribe('all')}
|
|
||||||
disabled={processing || data?.currentPreferences.unsubscribeAll}
|
|
||||||
variant='destructive'
|
|
||||||
className='w-full'
|
|
||||||
>
|
|
||||||
{data?.currentPreferences.unsubscribeAll ? (
|
|
||||||
<CheckCircle className='mr-2 h-4 w-4' />
|
|
||||||
) : null}
|
|
||||||
{processing
|
|
||||||
? 'Unsubscribing...'
|
|
||||||
: data?.currentPreferences.unsubscribeAll
|
|
||||||
? 'Unsubscribed from All Emails'
|
|
||||||
: 'Unsubscribe from All Marketing Emails'}
|
|
||||||
</Button>
|
|
||||||
|
|
||||||
<div className='text-center text-muted-foreground text-sm'>
|
<div className={`${inter.className} mt-8 w-full max-w-[410px] space-y-3`}>
|
||||||
or choose specific types:
|
<BrandedButton
|
||||||
</div>
|
onClick={() => handleUnsubscribe('all')}
|
||||||
|
disabled={processing || isAlreadyUnsubscribedFromAll}
|
||||||
|
loading={processing}
|
||||||
|
loadingText='Unsubscribing'
|
||||||
|
>
|
||||||
|
{isAlreadyUnsubscribedFromAll
|
||||||
|
? 'Unsubscribed from All Emails'
|
||||||
|
: 'Unsubscribe from All Marketing Emails'}
|
||||||
|
</BrandedButton>
|
||||||
|
|
||||||
<Button
|
<div className='py-2 text-center'>
|
||||||
onClick={() => handleUnsubscribe('marketing')}
|
<span className={`${inter.className} font-[380] text-[14px] text-muted-foreground`}>
|
||||||
disabled={
|
or choose specific types
|
||||||
processing ||
|
</span>
|
||||||
data?.currentPreferences.unsubscribeAll ||
|
</div>
|
||||||
data?.currentPreferences.unsubscribeMarketing
|
|
||||||
}
|
|
||||||
variant='outline'
|
|
||||||
className='w-full'
|
|
||||||
>
|
|
||||||
{data?.currentPreferences.unsubscribeMarketing ? (
|
|
||||||
<CheckCircle className='mr-2 h-4 w-4' />
|
|
||||||
) : null}
|
|
||||||
{data?.currentPreferences.unsubscribeMarketing
|
|
||||||
? 'Unsubscribed from Marketing'
|
|
||||||
: 'Unsubscribe from Marketing Emails'}
|
|
||||||
</Button>
|
|
||||||
|
|
||||||
<Button
|
<BrandedButton
|
||||||
onClick={() => handleUnsubscribe('updates')}
|
onClick={() => handleUnsubscribe('marketing')}
|
||||||
disabled={
|
disabled={
|
||||||
processing ||
|
processing ||
|
||||||
data?.currentPreferences.unsubscribeAll ||
|
isAlreadyUnsubscribedFromAll ||
|
||||||
data?.currentPreferences.unsubscribeUpdates
|
data?.currentPreferences.unsubscribeMarketing
|
||||||
}
|
}
|
||||||
variant='outline'
|
>
|
||||||
className='w-full'
|
{data?.currentPreferences.unsubscribeMarketing
|
||||||
>
|
? 'Unsubscribed from Marketing'
|
||||||
{data?.currentPreferences.unsubscribeUpdates ? (
|
: 'Unsubscribe from Marketing Emails'}
|
||||||
<CheckCircle className='mr-2 h-4 w-4' />
|
</BrandedButton>
|
||||||
) : null}
|
|
||||||
{data?.currentPreferences.unsubscribeUpdates
|
|
||||||
? 'Unsubscribed from Updates'
|
|
||||||
: 'Unsubscribe from Product Updates'}
|
|
||||||
</Button>
|
|
||||||
|
|
||||||
<Button
|
<BrandedButton
|
||||||
onClick={() => handleUnsubscribe('notifications')}
|
onClick={() => handleUnsubscribe('updates')}
|
||||||
disabled={
|
disabled={
|
||||||
processing ||
|
processing ||
|
||||||
data?.currentPreferences.unsubscribeAll ||
|
isAlreadyUnsubscribedFromAll ||
|
||||||
data?.currentPreferences.unsubscribeNotifications
|
data?.currentPreferences.unsubscribeUpdates
|
||||||
}
|
}
|
||||||
variant='outline'
|
>
|
||||||
className='w-full'
|
{data?.currentPreferences.unsubscribeUpdates
|
||||||
>
|
? 'Unsubscribed from Updates'
|
||||||
{data?.currentPreferences.unsubscribeNotifications ? (
|
: 'Unsubscribe from Product Updates'}
|
||||||
<CheckCircle className='mr-2 h-4 w-4' />
|
</BrandedButton>
|
||||||
) : null}
|
|
||||||
{data?.currentPreferences.unsubscribeNotifications
|
|
||||||
? 'Unsubscribed from Notifications'
|
|
||||||
: 'Unsubscribe from Notifications'}
|
|
||||||
</Button>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div className='mt-6 space-y-3'>
|
<BrandedButton
|
||||||
<div className='rounded-lg border bg-muted/50 p-3'>
|
onClick={() => handleUnsubscribe('notifications')}
|
||||||
<p className='text-center text-muted-foreground text-xs'>
|
disabled={
|
||||||
<strong>Note:</strong> You'll continue receiving important account emails like
|
processing ||
|
||||||
password resets and security alerts.
|
isAlreadyUnsubscribedFromAll ||
|
||||||
</p>
|
data?.currentPreferences.unsubscribeNotifications
|
||||||
</div>
|
}
|
||||||
|
>
|
||||||
|
{data?.currentPreferences.unsubscribeNotifications
|
||||||
|
? 'Unsubscribed from Notifications'
|
||||||
|
: 'Unsubscribe from Notifications'}
|
||||||
|
</BrandedButton>
|
||||||
|
</div>
|
||||||
|
|
||||||
<p className='text-center text-muted-foreground text-xs'>
|
<div className={`${inter.className} mt-6 max-w-[410px] text-center`}>
|
||||||
Questions? Contact us at{' '}
|
<p className='font-[380] text-[13px] text-muted-foreground'>
|
||||||
<a
|
You'll continue receiving important account emails like password resets and security
|
||||||
href={`mailto:${brand.supportEmail}`}
|
alerts.
|
||||||
className='text-muted-foreground hover:underline'
|
</p>
|
||||||
>
|
</div>
|
||||||
{brand.supportEmail}
|
|
||||||
</a>
|
<SupportFooter position='absolute' />
|
||||||
</p>
|
</InviteLayout>
|
||||||
</div>
|
|
||||||
</CardContent>
|
|
||||||
</Card>
|
|
||||||
</div>
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -391,13 +292,20 @@ export default function Unsubscribe() {
|
|||||||
return (
|
return (
|
||||||
<Suspense
|
<Suspense
|
||||||
fallback={
|
fallback={
|
||||||
<div className='before:-z-50 relative flex min-h-screen items-center justify-center before:pointer-events-none before:fixed before:inset-0 before:bg-white'>
|
<InviteLayout>
|
||||||
<Card className='w-full max-w-md border shadow-sm'>
|
<div className='space-y-1 text-center'>
|
||||||
<CardContent className='flex items-center justify-center p-8'>
|
<h1 className={`${soehne.className} font-medium text-[32px] text-black tracking-tight`}>
|
||||||
<Loader2 className='h-8 w-8 animate-spin text-muted-foreground' />
|
Loading
|
||||||
</CardContent>
|
</h1>
|
||||||
</Card>
|
<p className={`${inter.className} font-[380] text-[16px] text-muted-foreground`}>
|
||||||
</div>
|
Validating your unsubscribe link...
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
<div className={`${inter.className} mt-8 flex w-full items-center justify-center py-8`}>
|
||||||
|
<Loader2 className='h-8 w-8 animate-spin text-muted-foreground' />
|
||||||
|
</div>
|
||||||
|
<SupportFooter position='absolute' />
|
||||||
|
</InviteLayout>
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
<UnsubscribeContent />
|
<UnsubscribeContent />
|
||||||
|
|||||||
@@ -77,7 +77,7 @@ export function DeleteChunkModal({
|
|||||||
</p>
|
</p>
|
||||||
</ModalBody>
|
</ModalBody>
|
||||||
<ModalFooter>
|
<ModalFooter>
|
||||||
<Button variant='active' disabled={isDeleting} onClick={onClose}>
|
<Button variant='default' disabled={isDeleting} onClick={onClose}>
|
||||||
Cancel
|
Cancel
|
||||||
</Button>
|
</Button>
|
||||||
<Button variant='destructive' onClick={handleDeleteChunk} disabled={isDeleting}>
|
<Button variant='destructive' onClick={handleDeleteChunk} disabled={isDeleting}>
|
||||||
|
|||||||
@@ -392,7 +392,7 @@ export function DocumentTagsModal({
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<Modal open={open} onOpenChange={handleClose}>
|
<Modal open={open} onOpenChange={handleClose}>
|
||||||
<ModalContent>
|
<ModalContent size='sm'>
|
||||||
<ModalHeader>
|
<ModalHeader>
|
||||||
<div className='flex items-center justify-between'>
|
<div className='flex items-center justify-between'>
|
||||||
<span>Document Tags</span>
|
<span>Document Tags</span>
|
||||||
@@ -486,7 +486,7 @@ export function DocumentTagsModal({
|
|||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
{tagNameConflict && (
|
{tagNameConflict && (
|
||||||
<span className='text-[11px] text-[var(--text-error)]'>
|
<span className='text-[12px] text-[var(--text-error)]'>
|
||||||
A tag with this name already exists
|
A tag with this name already exists
|
||||||
</span>
|
</span>
|
||||||
)}
|
)}
|
||||||
@@ -639,7 +639,7 @@ export function DocumentTagsModal({
|
|||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
{tagNameConflict && (
|
{tagNameConflict && (
|
||||||
<span className='text-[11px] text-[var(--text-error)]'>
|
<span className='text-[12px] text-[var(--text-error)]'>
|
||||||
A tag with this name already exists
|
A tag with this name already exists
|
||||||
</span>
|
</span>
|
||||||
)}
|
)}
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ import { ActionBar } from '@/app/workspace/[workspaceId]/knowledge/[id]/componen
|
|||||||
import { useUserPermissionsContext } from '@/app/workspace/[workspaceId]/providers/workspace-permissions-provider'
|
import { useUserPermissionsContext } from '@/app/workspace/[workspaceId]/providers/workspace-permissions-provider'
|
||||||
import { useContextMenu } from '@/app/workspace/[workspaceId]/w/components/sidebar/hooks'
|
import { useContextMenu } from '@/app/workspace/[workspaceId]/w/components/sidebar/hooks'
|
||||||
import { useDocument, useDocumentChunks, useKnowledgeBase } from '@/hooks/kb/use-knowledge'
|
import { useDocument, useDocumentChunks, useKnowledgeBase } from '@/hooks/kb/use-knowledge'
|
||||||
import { knowledgeKeys } from '@/hooks/queries/knowledge'
|
import { knowledgeKeys, useDocumentChunkSearchQuery } from '@/hooks/queries/knowledge'
|
||||||
|
|
||||||
const logger = createLogger('Document')
|
const logger = createLogger('Document')
|
||||||
|
|
||||||
@@ -313,69 +313,22 @@ export function Document({
|
|||||||
isFetching: isFetchingChunks,
|
isFetching: isFetchingChunks,
|
||||||
} = useDocumentChunks(knowledgeBaseId, documentId, currentPageFromURL)
|
} = useDocumentChunks(knowledgeBaseId, documentId, currentPageFromURL)
|
||||||
|
|
||||||
const [searchResults, setSearchResults] = useState<ChunkData[]>([])
|
const {
|
||||||
const [isLoadingSearch, setIsLoadingSearch] = useState(false)
|
data: searchResults = [],
|
||||||
const [searchError, setSearchError] = useState<string | null>(null)
|
isLoading: isLoadingSearch,
|
||||||
|
error: searchQueryError,
|
||||||
useEffect(() => {
|
} = useDocumentChunkSearchQuery(
|
||||||
if (!debouncedSearchQuery.trim()) {
|
{
|
||||||
setSearchResults([])
|
knowledgeBaseId,
|
||||||
setSearchError(null)
|
documentId,
|
||||||
return
|
search: debouncedSearchQuery,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
enabled: Boolean(debouncedSearchQuery.trim()),
|
||||||
}
|
}
|
||||||
|
)
|
||||||
|
|
||||||
let isMounted = true
|
const searchError = searchQueryError instanceof Error ? searchQueryError.message : null
|
||||||
|
|
||||||
const searchAllChunks = async () => {
|
|
||||||
try {
|
|
||||||
setIsLoadingSearch(true)
|
|
||||||
setSearchError(null)
|
|
||||||
|
|
||||||
const allResults: ChunkData[] = []
|
|
||||||
let hasMore = true
|
|
||||||
let offset = 0
|
|
||||||
const limit = 100
|
|
||||||
|
|
||||||
while (hasMore && isMounted) {
|
|
||||||
const response = await fetch(
|
|
||||||
`/api/knowledge/${knowledgeBaseId}/documents/${documentId}/chunks?search=${encodeURIComponent(debouncedSearchQuery)}&limit=${limit}&offset=${offset}`
|
|
||||||
)
|
|
||||||
|
|
||||||
if (!response.ok) {
|
|
||||||
throw new Error('Search failed')
|
|
||||||
}
|
|
||||||
|
|
||||||
const result = await response.json()
|
|
||||||
|
|
||||||
if (result.success && result.data) {
|
|
||||||
allResults.push(...result.data)
|
|
||||||
hasMore = result.pagination?.hasMore || false
|
|
||||||
offset += limit
|
|
||||||
} else {
|
|
||||||
hasMore = false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isMounted) {
|
|
||||||
setSearchResults(allResults)
|
|
||||||
}
|
|
||||||
} catch (err) {
|
|
||||||
if (isMounted) {
|
|
||||||
setSearchError(err instanceof Error ? err.message : 'Search failed')
|
|
||||||
}
|
|
||||||
} finally {
|
|
||||||
if (isMounted) {
|
|
||||||
setIsLoadingSearch(false)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
searchAllChunks()
|
|
||||||
|
|
||||||
return () => {
|
|
||||||
isMounted = false
|
|
||||||
}
|
|
||||||
}, [debouncedSearchQuery, knowledgeBaseId, documentId])
|
|
||||||
|
|
||||||
const [selectedChunks, setSelectedChunks] = useState<Set<string>>(new Set())
|
const [selectedChunks, setSelectedChunks] = useState<Set<string>>(new Set())
|
||||||
const [selectedChunk, setSelectedChunk] = useState<ChunkData | null>(null)
|
const [selectedChunk, setSelectedChunk] = useState<ChunkData | null>(null)
|
||||||
@@ -1208,15 +1161,19 @@ export function Document({
|
|||||||
<ModalHeader>Delete Document</ModalHeader>
|
<ModalHeader>Delete Document</ModalHeader>
|
||||||
<ModalBody>
|
<ModalBody>
|
||||||
<p className='text-[12px] text-[var(--text-secondary)]'>
|
<p className='text-[12px] text-[var(--text-secondary)]'>
|
||||||
Are you sure you want to delete "{effectiveDocumentName}"? This will permanently
|
Are you sure you want to delete{' '}
|
||||||
delete the document and all {documentData?.chunkCount ?? 0} chunk
|
<span className='font-medium text-[var(--text-primary)]'>
|
||||||
|
{effectiveDocumentName}
|
||||||
|
</span>
|
||||||
|
? This will permanently delete the document and all {documentData?.chunkCount ?? 0}{' '}
|
||||||
|
chunk
|
||||||
{documentData?.chunkCount === 1 ? '' : 's'} within it.{' '}
|
{documentData?.chunkCount === 1 ? '' : 's'} within it.{' '}
|
||||||
<span className='text-[var(--text-error)]'>This action cannot be undone.</span>
|
<span className='text-[var(--text-error)]'>This action cannot be undone.</span>
|
||||||
</p>
|
</p>
|
||||||
</ModalBody>
|
</ModalBody>
|
||||||
<ModalFooter>
|
<ModalFooter>
|
||||||
<Button
|
<Button
|
||||||
variant='active'
|
variant='default'
|
||||||
onClick={() => setShowDeleteDocumentDialog(false)}
|
onClick={() => setShowDeleteDocumentDialog(false)}
|
||||||
disabled={isDeletingDocument}
|
disabled={isDeletingDocument}
|
||||||
>
|
>
|
||||||
|
|||||||
@@ -1523,15 +1523,16 @@ export function KnowledgeBase({
|
|||||||
<ModalHeader>Delete Knowledge Base</ModalHeader>
|
<ModalHeader>Delete Knowledge Base</ModalHeader>
|
||||||
<ModalBody>
|
<ModalBody>
|
||||||
<p className='text-[12px] text-[var(--text-secondary)]'>
|
<p className='text-[12px] text-[var(--text-secondary)]'>
|
||||||
Are you sure you want to delete "{knowledgeBaseName}"? This will permanently delete
|
Are you sure you want to delete{' '}
|
||||||
the knowledge base and all {pagination.total} document
|
<span className='font-medium text-[var(--text-primary)]'>{knowledgeBaseName}</span>?
|
||||||
|
This will permanently delete the knowledge base and all {pagination.total} document
|
||||||
{pagination.total === 1 ? '' : 's'} within it.{' '}
|
{pagination.total === 1 ? '' : 's'} within it.{' '}
|
||||||
<span className='text-[var(--text-error)]'>This action cannot be undone.</span>
|
<span className='text-[var(--text-error)]'>This action cannot be undone.</span>
|
||||||
</p>
|
</p>
|
||||||
</ModalBody>
|
</ModalBody>
|
||||||
<ModalFooter>
|
<ModalFooter>
|
||||||
<Button
|
<Button
|
||||||
variant='active'
|
variant='default'
|
||||||
onClick={() => setShowDeleteDialog(false)}
|
onClick={() => setShowDeleteDialog(false)}
|
||||||
disabled={isDeleting}
|
disabled={isDeleting}
|
||||||
>
|
>
|
||||||
@@ -1549,14 +1550,16 @@ export function KnowledgeBase({
|
|||||||
<ModalHeader>Delete Document</ModalHeader>
|
<ModalHeader>Delete Document</ModalHeader>
|
||||||
<ModalBody>
|
<ModalBody>
|
||||||
<p className='text-[12px] text-[var(--text-secondary)]'>
|
<p className='text-[12px] text-[var(--text-secondary)]'>
|
||||||
Are you sure you want to delete "
|
Are you sure you want to delete{' '}
|
||||||
{documents.find((doc) => doc.id === documentToDelete)?.filename ?? 'this document'}"?{' '}
|
<span className='font-medium text-[var(--text-primary)]'>
|
||||||
<span className='text-[var(--text-error)]'>This action cannot be undone.</span>
|
{documents.find((doc) => doc.id === documentToDelete)?.filename ?? 'this document'}
|
||||||
|
</span>
|
||||||
|
? <span className='text-[var(--text-error)]'>This action cannot be undone.</span>
|
||||||
</p>
|
</p>
|
||||||
</ModalBody>
|
</ModalBody>
|
||||||
<ModalFooter>
|
<ModalFooter>
|
||||||
<Button
|
<Button
|
||||||
variant='active'
|
variant='default'
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
setShowDeleteDocumentModal(false)
|
setShowDeleteDocumentModal(false)
|
||||||
setDocumentToDelete(null)
|
setDocumentToDelete(null)
|
||||||
@@ -1582,7 +1585,7 @@ export function KnowledgeBase({
|
|||||||
</p>
|
</p>
|
||||||
</ModalBody>
|
</ModalBody>
|
||||||
<ModalFooter>
|
<ModalFooter>
|
||||||
<Button variant='active' onClick={() => setShowBulkDeleteModal(false)}>
|
<Button variant='default' onClick={() => setShowBulkDeleteModal(false)}>
|
||||||
Cancel
|
Cancel
|
||||||
</Button>
|
</Button>
|
||||||
<Button variant='destructive' onClick={confirmBulkDelete} disabled={isBulkOperating}>
|
<Button variant='destructive' onClick={confirmBulkDelete} disabled={isBulkOperating}>
|
||||||
|
|||||||
@@ -221,14 +221,14 @@ export function AddDocumentsModal({
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<Modal open={open} onOpenChange={handleClose}>
|
<Modal open={open} onOpenChange={handleClose}>
|
||||||
<ModalContent>
|
<ModalContent size='md'>
|
||||||
<ModalHeader>Add Documents</ModalHeader>
|
<ModalHeader>Add Documents</ModalHeader>
|
||||||
|
|
||||||
<ModalBody>
|
<ModalBody>
|
||||||
<div className='min-h-0 flex-1 overflow-y-auto'>
|
<div className='min-h-0 flex-1 overflow-y-auto'>
|
||||||
<div className='space-y-[12px]'>
|
<div className='space-y-[12px]'>
|
||||||
{fileError && (
|
{fileError && (
|
||||||
<p className='text-[11px] text-[var(--text-error)] leading-tight'>{fileError}</p>
|
<p className='text-[12px] text-[var(--text-error)] leading-tight'>{fileError}</p>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
<div className='flex flex-col gap-[8px]'>
|
<div className='flex flex-col gap-[8px]'>
|
||||||
@@ -336,7 +336,7 @@ export function AddDocumentsModal({
|
|||||||
<ModalFooter>
|
<ModalFooter>
|
||||||
<div className='flex w-full items-center justify-between gap-[12px]'>
|
<div className='flex w-full items-center justify-between gap-[12px]'>
|
||||||
{uploadError ? (
|
{uploadError ? (
|
||||||
<p className='min-w-0 flex-1 truncate text-[11px] text-[var(--text-error)] leading-tight'>
|
<p className='min-w-0 flex-1 truncate text-[12px] text-[var(--text-error)] leading-tight'>
|
||||||
{uploadError.message}
|
{uploadError.message}
|
||||||
</p>
|
</p>
|
||||||
) : (
|
) : (
|
||||||
|
|||||||
@@ -306,7 +306,7 @@ export function BaseTagsModal({ open, onOpenChange, knowledgeBaseId }: BaseTagsM
|
|||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<Modal open={open} onOpenChange={handleClose}>
|
<Modal open={open} onOpenChange={handleClose}>
|
||||||
<ModalContent>
|
<ModalContent size='sm'>
|
||||||
<ModalHeader>
|
<ModalHeader>
|
||||||
<div className='flex items-center justify-between'>
|
<div className='flex items-center justify-between'>
|
||||||
<span>Tags</span>
|
<span>Tags</span>
|
||||||
@@ -400,7 +400,7 @@ export function BaseTagsModal({ open, onOpenChange, knowledgeBaseId }: BaseTagsM
|
|||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
{tagNameConflict && (
|
{tagNameConflict && (
|
||||||
<span className='text-[11px] text-[var(--text-error)]'>
|
<span className='text-[12px] text-[var(--text-error)]'>
|
||||||
A tag with this name already exists
|
A tag with this name already exists
|
||||||
</span>
|
</span>
|
||||||
)}
|
)}
|
||||||
@@ -417,7 +417,7 @@ export function BaseTagsModal({ open, onOpenChange, knowledgeBaseId }: BaseTagsM
|
|||||||
placeholder='Select type'
|
placeholder='Select type'
|
||||||
/>
|
/>
|
||||||
{!hasAvailableSlots(createTagForm.fieldType) && (
|
{!hasAvailableSlots(createTagForm.fieldType) && (
|
||||||
<span className='text-[11px] text-[var(--text-error)]'>
|
<span className='text-[12px] text-[var(--text-error)]'>
|
||||||
No available slots for this type. Choose a different type.
|
No available slots for this type. Choose a different type.
|
||||||
</span>
|
</span>
|
||||||
)}
|
)}
|
||||||
|
|||||||
@@ -77,7 +77,7 @@ export function RenameDocumentModal({
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<Modal open={open} onOpenChange={onOpenChange}>
|
<Modal open={open} onOpenChange={onOpenChange}>
|
||||||
<ModalContent>
|
<ModalContent size='sm'>
|
||||||
<ModalHeader>Rename Document</ModalHeader>
|
<ModalHeader>Rename Document</ModalHeader>
|
||||||
<form onSubmit={handleSubmit} className='flex min-h-0 flex-1 flex-col'>
|
<form onSubmit={handleSubmit} className='flex min-h-0 flex-1 flex-col'>
|
||||||
<ModalBody className='!pb-[16px]'>
|
<ModalBody className='!pb-[16px]'>
|
||||||
@@ -108,7 +108,7 @@ export function RenameDocumentModal({
|
|||||||
<ModalFooter>
|
<ModalFooter>
|
||||||
<div className='flex w-full items-center justify-between gap-[12px]'>
|
<div className='flex w-full items-center justify-between gap-[12px]'>
|
||||||
{error ? (
|
{error ? (
|
||||||
<p className='min-w-0 flex-1 truncate text-[11px] text-[var(--text-error)] leading-tight'>
|
<p className='min-w-0 flex-1 truncate text-[12px] text-[var(--text-error)] leading-tight'>
|
||||||
{error}
|
{error}
|
||||||
</p>
|
</p>
|
||||||
) : (
|
) : (
|
||||||
|
|||||||
@@ -332,7 +332,7 @@ export function CreateBaseModal({ open, onOpenChange }: CreateBaseModalProps) {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<Modal open={open} onOpenChange={handleClose}>
|
<Modal open={open} onOpenChange={handleClose}>
|
||||||
<ModalContent>
|
<ModalContent size='lg'>
|
||||||
<ModalHeader>Create Knowledge Base</ModalHeader>
|
<ModalHeader>Create Knowledge Base</ModalHeader>
|
||||||
|
|
||||||
<form onSubmit={handleSubmit(onSubmit)} className='flex min-h-0 flex-1 flex-col'>
|
<form onSubmit={handleSubmit(onSubmit)} className='flex min-h-0 flex-1 flex-col'>
|
||||||
@@ -528,7 +528,7 @@ export function CreateBaseModal({ open, onOpenChange }: CreateBaseModalProps) {
|
|||||||
)}
|
)}
|
||||||
|
|
||||||
{fileError && (
|
{fileError && (
|
||||||
<p className='text-[11px] text-[var(--text-error)] leading-tight'>{fileError}</p>
|
<p className='text-[12px] text-[var(--text-error)] leading-tight'>{fileError}</p>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -537,7 +537,7 @@ export function CreateBaseModal({ open, onOpenChange }: CreateBaseModalProps) {
|
|||||||
<ModalFooter>
|
<ModalFooter>
|
||||||
<div className='flex w-full items-center justify-between gap-[12px]'>
|
<div className='flex w-full items-center justify-between gap-[12px]'>
|
||||||
{submitStatus?.type === 'error' || uploadError ? (
|
{submitStatus?.type === 'error' || uploadError ? (
|
||||||
<p className='min-w-0 flex-1 truncate text-[11px] text-[var(--text-error)] leading-tight'>
|
<p className='min-w-0 flex-1 truncate text-[12px] text-[var(--text-error)] leading-tight'>
|
||||||
{uploadError?.message || submitStatus?.message}
|
{uploadError?.message || submitStatus?.message}
|
||||||
</p>
|
</p>
|
||||||
) : (
|
) : (
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ export function DeleteKnowledgeBaseModal({
|
|||||||
}: DeleteKnowledgeBaseModalProps) {
|
}: DeleteKnowledgeBaseModalProps) {
|
||||||
return (
|
return (
|
||||||
<Modal open={isOpen} onOpenChange={onClose}>
|
<Modal open={isOpen} onOpenChange={onClose}>
|
||||||
<ModalContent className='w-[400px]'>
|
<ModalContent size='sm'>
|
||||||
<ModalHeader>Delete Knowledge Base</ModalHeader>
|
<ModalHeader>Delete Knowledge Base</ModalHeader>
|
||||||
<ModalBody>
|
<ModalBody>
|
||||||
<p className='text-[12px] text-[var(--text-secondary)]'>
|
<p className='text-[12px] text-[var(--text-secondary)]'>
|
||||||
@@ -55,7 +55,7 @@ export function DeleteKnowledgeBaseModal({
|
|||||||
</p>
|
</p>
|
||||||
</ModalBody>
|
</ModalBody>
|
||||||
<ModalFooter>
|
<ModalFooter>
|
||||||
<Button variant='active' onClick={onClose} disabled={isDeleting}>
|
<Button variant='default' onClick={onClose} disabled={isDeleting}>
|
||||||
Cancel
|
Cancel
|
||||||
</Button>
|
</Button>
|
||||||
<Button variant='destructive' onClick={onConfirm} disabled={isDeleting}>
|
<Button variant='destructive' onClick={onConfirm} disabled={isDeleting}>
|
||||||
|
|||||||
@@ -98,7 +98,7 @@ export function EditKnowledgeBaseModal({
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<Modal open={open} onOpenChange={onOpenChange}>
|
<Modal open={open} onOpenChange={onOpenChange}>
|
||||||
<ModalContent>
|
<ModalContent size='sm'>
|
||||||
<ModalHeader>Edit Knowledge Base</ModalHeader>
|
<ModalHeader>Edit Knowledge Base</ModalHeader>
|
||||||
|
|
||||||
<form onSubmit={handleSubmit(onSubmit)} className='flex min-h-0 flex-1 flex-col'>
|
<form onSubmit={handleSubmit(onSubmit)} className='flex min-h-0 flex-1 flex-col'>
|
||||||
@@ -118,7 +118,7 @@ export function EditKnowledgeBaseModal({
|
|||||||
data-form-type='other'
|
data-form-type='other'
|
||||||
/>
|
/>
|
||||||
{errors.name && (
|
{errors.name && (
|
||||||
<p className='text-[11px] text-[var(--text-error)]'>{errors.name.message}</p>
|
<p className='text-[12px] text-[var(--text-error)]'>{errors.name.message}</p>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -132,7 +132,7 @@ export function EditKnowledgeBaseModal({
|
|||||||
className={cn(errors.description && 'border-[var(--text-error)]')}
|
className={cn(errors.description && 'border-[var(--text-error)]')}
|
||||||
/>
|
/>
|
||||||
{errors.description && (
|
{errors.description && (
|
||||||
<p className='text-[11px] text-[var(--text-error)]'>
|
<p className='text-[12px] text-[var(--text-error)]'>
|
||||||
{errors.description.message}
|
{errors.description.message}
|
||||||
</p>
|
</p>
|
||||||
)}
|
)}
|
||||||
@@ -143,7 +143,7 @@ export function EditKnowledgeBaseModal({
|
|||||||
<ModalFooter>
|
<ModalFooter>
|
||||||
<div className='flex w-full items-center justify-between gap-[12px]'>
|
<div className='flex w-full items-center justify-between gap-[12px]'>
|
||||||
{error ? (
|
{error ? (
|
||||||
<p className='min-w-0 flex-1 truncate text-[11px] text-[var(--text-error)] leading-tight'>
|
<p className='min-w-0 flex-1 truncate text-[12px] text-[var(--text-error)] leading-tight'>
|
||||||
{error}
|
{error}
|
||||||
</p>
|
</p>
|
||||||
) : (
|
) : (
|
||||||
|
|||||||
@@ -112,7 +112,7 @@ export function SlackChannelSelector({
|
|||||||
{selectedChannel.isPrivate ? 'Private' : 'Public'} channel: #{selectedChannel.name}
|
{selectedChannel.isPrivate ? 'Private' : 'Public'} channel: #{selectedChannel.name}
|
||||||
</p>
|
</p>
|
||||||
)}
|
)}
|
||||||
{error && <p className='text-[11px] text-[var(--text-error)]'>{error}</p>}
|
{error && <p className='text-[12px] text-[var(--text-error)]'>{error}</p>}
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +1,10 @@
|
|||||||
'use client'
|
'use client'
|
||||||
|
|
||||||
import { useEffect, useMemo, useState } from 'react'
|
import { useMemo } from 'react'
|
||||||
import { X } from 'lucide-react'
|
import { X } from 'lucide-react'
|
||||||
import { Badge, Combobox, type ComboboxOption } from '@/components/emcn'
|
import { Badge, Combobox, type ComboboxOption } from '@/components/emcn'
|
||||||
import { Skeleton } from '@/components/ui'
|
import { Skeleton } from '@/components/ui'
|
||||||
|
import { useWorkflows } from '@/hooks/queries/workflows'
|
||||||
|
|
||||||
interface WorkflowSelectorProps {
|
interface WorkflowSelectorProps {
|
||||||
workspaceId: string
|
workspaceId: string
|
||||||
@@ -25,26 +26,9 @@ export function WorkflowSelector({
|
|||||||
onChange,
|
onChange,
|
||||||
error,
|
error,
|
||||||
}: WorkflowSelectorProps) {
|
}: WorkflowSelectorProps) {
|
||||||
const [workflows, setWorkflows] = useState<Array<{ id: string; name: string }>>([])
|
const { data: workflows = [], isPending: isLoading } = useWorkflows(workspaceId, {
|
||||||
const [isLoading, setIsLoading] = useState(true)
|
syncRegistry: false,
|
||||||
|
})
|
||||||
useEffect(() => {
|
|
||||||
const load = async () => {
|
|
||||||
try {
|
|
||||||
setIsLoading(true)
|
|
||||||
const response = await fetch(`/api/workflows?workspaceId=${workspaceId}`)
|
|
||||||
if (response.ok) {
|
|
||||||
const data = await response.json()
|
|
||||||
setWorkflows(data.data || [])
|
|
||||||
}
|
|
||||||
} catch {
|
|
||||||
setWorkflows([])
|
|
||||||
} finally {
|
|
||||||
setIsLoading(false)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
load()
|
|
||||||
}, [workspaceId])
|
|
||||||
|
|
||||||
const options: ComboboxOption[] = useMemo(() => {
|
const options: ComboboxOption[] = useMemo(() => {
|
||||||
return workflows.map((w) => ({
|
return workflows.map((w) => ({
|
||||||
|
|||||||
@@ -634,7 +634,7 @@ export function NotificationSettings({
|
|||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
{formErrors.webhookUrl && (
|
{formErrors.webhookUrl && (
|
||||||
<p className='text-[11px] text-[var(--text-error)]'>{formErrors.webhookUrl}</p>
|
<p className='text-[12px] text-[var(--text-error)]'>{formErrors.webhookUrl}</p>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
<div className='flex flex-col gap-[8px]'>
|
<div className='flex flex-col gap-[8px]'>
|
||||||
@@ -660,7 +660,7 @@ export function NotificationSettings({
|
|||||||
placeholderWithTags='Add email'
|
placeholderWithTags='Add email'
|
||||||
/>
|
/>
|
||||||
{formErrors.emailRecipients && (
|
{formErrors.emailRecipients && (
|
||||||
<p className='text-[11px] text-[var(--text-error)]'>{formErrors.emailRecipients}</p>
|
<p className='text-[12px] text-[var(--text-error)]'>{formErrors.emailRecipients}</p>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
@@ -707,7 +707,7 @@ export function NotificationSettings({
|
|||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
{formErrors.slackAccountId && (
|
{formErrors.slackAccountId && (
|
||||||
<p className='text-[11px] text-[var(--text-error)]'>
|
<p className='text-[12px] text-[var(--text-error)]'>
|
||||||
{formErrors.slackAccountId}
|
{formErrors.slackAccountId}
|
||||||
</p>
|
</p>
|
||||||
)}
|
)}
|
||||||
@@ -776,7 +776,7 @@ export function NotificationSettings({
|
|||||||
allOptionLabel='All levels'
|
allOptionLabel='All levels'
|
||||||
/>
|
/>
|
||||||
{formErrors.levelFilter && (
|
{formErrors.levelFilter && (
|
||||||
<p className='text-[11px] text-[var(--text-error)]'>{formErrors.levelFilter}</p>
|
<p className='text-[12px] text-[var(--text-error)]'>{formErrors.levelFilter}</p>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -822,7 +822,7 @@ export function NotificationSettings({
|
|||||||
allOptionLabel='All triggers'
|
allOptionLabel='All triggers'
|
||||||
/>
|
/>
|
||||||
{formErrors.triggerFilter && (
|
{formErrors.triggerFilter && (
|
||||||
<p className='text-[11px] text-[var(--text-error)]'>{formErrors.triggerFilter}</p>
|
<p className='text-[12px] text-[var(--text-error)]'>{formErrors.triggerFilter}</p>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -938,7 +938,7 @@ export function NotificationSettings({
|
|||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
{formErrors.consecutiveFailures && (
|
{formErrors.consecutiveFailures && (
|
||||||
<p className='text-[11px] text-[var(--text-error)]'>
|
<p className='text-[12px] text-[var(--text-error)]'>
|
||||||
{formErrors.consecutiveFailures}
|
{formErrors.consecutiveFailures}
|
||||||
</p>
|
</p>
|
||||||
)}
|
)}
|
||||||
@@ -962,7 +962,7 @@ export function NotificationSettings({
|
|||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
{formErrors.failureRatePercent && (
|
{formErrors.failureRatePercent && (
|
||||||
<p className='text-[11px] text-[var(--text-error)]'>
|
<p className='text-[12px] text-[var(--text-error)]'>
|
||||||
{formErrors.failureRatePercent}
|
{formErrors.failureRatePercent}
|
||||||
</p>
|
</p>
|
||||||
)}
|
)}
|
||||||
@@ -982,7 +982,7 @@ export function NotificationSettings({
|
|||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
{formErrors.windowHours && (
|
{formErrors.windowHours && (
|
||||||
<p className='text-[11px] text-[var(--text-error)]'>{formErrors.windowHours}</p>
|
<p className='text-[12px] text-[var(--text-error)]'>{formErrors.windowHours}</p>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -1004,7 +1004,7 @@ export function NotificationSettings({
|
|||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
{formErrors.durationThresholdMs && (
|
{formErrors.durationThresholdMs && (
|
||||||
<p className='text-[11px] text-[var(--text-error)]'>
|
<p className='text-[12px] text-[var(--text-error)]'>
|
||||||
{formErrors.durationThresholdMs}
|
{formErrors.durationThresholdMs}
|
||||||
</p>
|
</p>
|
||||||
)}
|
)}
|
||||||
@@ -1028,7 +1028,7 @@ export function NotificationSettings({
|
|||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
{formErrors.latencySpikePercent && (
|
{formErrors.latencySpikePercent && (
|
||||||
<p className='text-[11px] text-[var(--text-error)]'>
|
<p className='text-[12px] text-[var(--text-error)]'>
|
||||||
{formErrors.latencySpikePercent}
|
{formErrors.latencySpikePercent}
|
||||||
</p>
|
</p>
|
||||||
)}
|
)}
|
||||||
@@ -1048,7 +1048,7 @@ export function NotificationSettings({
|
|||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
{formErrors.windowHours && (
|
{formErrors.windowHours && (
|
||||||
<p className='text-[11px] text-[var(--text-error)]'>{formErrors.windowHours}</p>
|
<p className='text-[12px] text-[var(--text-error)]'>{formErrors.windowHours}</p>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -1071,7 +1071,7 @@ export function NotificationSettings({
|
|||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
{formErrors.costThresholdDollars && (
|
{formErrors.costThresholdDollars && (
|
||||||
<p className='text-[11px] text-[var(--text-error)]'>
|
<p className='text-[12px] text-[var(--text-error)]'>
|
||||||
{formErrors.costThresholdDollars}
|
{formErrors.costThresholdDollars}
|
||||||
</p>
|
</p>
|
||||||
)}
|
)}
|
||||||
@@ -1094,7 +1094,7 @@ export function NotificationSettings({
|
|||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
{formErrors.inactivityHours && (
|
{formErrors.inactivityHours && (
|
||||||
<p className='text-[11px] text-[var(--text-error)]'>{formErrors.inactivityHours}</p>
|
<p className='text-[12px] text-[var(--text-error)]'>{formErrors.inactivityHours}</p>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
@@ -1116,7 +1116,7 @@ export function NotificationSettings({
|
|||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
{formErrors.errorCountThreshold && (
|
{formErrors.errorCountThreshold && (
|
||||||
<p className='text-[11px] text-[var(--text-error)]'>
|
<p className='text-[12px] text-[var(--text-error)]'>
|
||||||
{formErrors.errorCountThreshold}
|
{formErrors.errorCountThreshold}
|
||||||
</p>
|
</p>
|
||||||
)}
|
)}
|
||||||
@@ -1136,7 +1136,7 @@ export function NotificationSettings({
|
|||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
{formErrors.windowHours && (
|
{formErrors.windowHours && (
|
||||||
<p className='text-[11px] text-[var(--text-error)]'>{formErrors.windowHours}</p>
|
<p className='text-[12px] text-[var(--text-error)]'>{formErrors.windowHours}</p>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -1261,7 +1261,7 @@ export function NotificationSettings({
|
|||||||
</Modal>
|
</Modal>
|
||||||
|
|
||||||
<Modal open={showDeleteDialog} onOpenChange={setShowDeleteDialog}>
|
<Modal open={showDeleteDialog} onOpenChange={setShowDeleteDialog}>
|
||||||
<ModalContent className='w-[400px]'>
|
<ModalContent size='sm'>
|
||||||
<ModalHeader>Delete Notification</ModalHeader>
|
<ModalHeader>Delete Notification</ModalHeader>
|
||||||
<ModalBody>
|
<ModalBody>
|
||||||
<p className='text-[12px] text-[var(--text-secondary)]'>
|
<p className='text-[12px] text-[var(--text-secondary)]'>
|
||||||
|
|||||||
@@ -4,13 +4,13 @@ import type React from 'react'
|
|||||||
import { createContext, useContext, useEffect, useMemo, useState } from 'react'
|
import { createContext, useContext, useEffect, useMemo, useState } from 'react'
|
||||||
import { createLogger } from '@sim/logger'
|
import { createLogger } from '@sim/logger'
|
||||||
import { useParams } from 'next/navigation'
|
import { useParams } from 'next/navigation'
|
||||||
import { useCollaborativeWorkflow } from '@/hooks/use-collaborative-workflow'
|
|
||||||
import { useUserPermissions, type WorkspaceUserPermissions } from '@/hooks/use-user-permissions'
|
import { useUserPermissions, type WorkspaceUserPermissions } from '@/hooks/use-user-permissions'
|
||||||
import {
|
import {
|
||||||
useWorkspacePermissions,
|
useWorkspacePermissions,
|
||||||
type WorkspacePermissions,
|
type WorkspacePermissions,
|
||||||
} from '@/hooks/use-workspace-permissions'
|
} from '@/hooks/use-workspace-permissions'
|
||||||
import { useNotificationStore } from '@/stores/notifications'
|
import { useNotificationStore } from '@/stores/notifications'
|
||||||
|
import { useOperationQueueStore } from '@/stores/operation-queue/store'
|
||||||
|
|
||||||
const logger = createLogger('WorkspacePermissionsProvider')
|
const logger = createLogger('WorkspacePermissionsProvider')
|
||||||
|
|
||||||
@@ -64,8 +64,8 @@ export function WorkspacePermissionsProvider({ children }: WorkspacePermissionsP
|
|||||||
// Track whether we've already surfaced an offline notification to avoid duplicates
|
// Track whether we've already surfaced an offline notification to avoid duplicates
|
||||||
const [hasShownOfflineNotification, setHasShownOfflineNotification] = useState(false)
|
const [hasShownOfflineNotification, setHasShownOfflineNotification] = useState(false)
|
||||||
|
|
||||||
// Get operation error state from collaborative workflow
|
// Get operation error state directly from the store (avoid full useCollaborativeWorkflow subscription)
|
||||||
const { hasOperationError } = useCollaborativeWorkflow()
|
const hasOperationError = useOperationQueueStore((state) => state.hasOperationError)
|
||||||
|
|
||||||
const addNotification = useNotificationStore((state) => state.addNotification)
|
const addNotification = useNotificationStore((state) => state.addNotification)
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import { memo, useCallback } from 'react'
|
|||||||
import { ArrowLeftRight, ArrowUpDown, Circle, CircleOff, LogOut } from 'lucide-react'
|
import { ArrowLeftRight, ArrowUpDown, Circle, CircleOff, LogOut } from 'lucide-react'
|
||||||
import { Button, Copy, Tooltip, Trash2 } from '@/components/emcn'
|
import { Button, Copy, Tooltip, Trash2 } from '@/components/emcn'
|
||||||
import { cn } from '@/lib/core/utils/cn'
|
import { cn } from '@/lib/core/utils/cn'
|
||||||
|
import { isValidStartBlockType } from '@/lib/workflows/triggers/start-block-types'
|
||||||
import { useUserPermissionsContext } from '@/app/workspace/[workspaceId]/providers/workspace-permissions-provider'
|
import { useUserPermissionsContext } from '@/app/workspace/[workspaceId]/providers/workspace-permissions-provider'
|
||||||
import { useCollaborativeWorkflow } from '@/hooks/use-collaborative-workflow'
|
import { useCollaborativeWorkflow } from '@/hooks/use-collaborative-workflow'
|
||||||
import { useWorkflowRegistry } from '@/stores/workflows/registry/store'
|
import { useWorkflowRegistry } from '@/stores/workflows/registry/store'
|
||||||
@@ -47,17 +48,17 @@ export const ActionBar = memo(
|
|||||||
collaborativeBatchToggleBlockEnabled,
|
collaborativeBatchToggleBlockEnabled,
|
||||||
collaborativeBatchToggleBlockHandles,
|
collaborativeBatchToggleBlockHandles,
|
||||||
} = useCollaborativeWorkflow()
|
} = useCollaborativeWorkflow()
|
||||||
const { activeWorkflowId } = useWorkflowRegistry()
|
const { activeWorkflowId, setPendingSelection } = useWorkflowRegistry()
|
||||||
const blocks = useWorkflowStore((state) => state.blocks)
|
|
||||||
const subBlockStore = useSubBlockStore()
|
|
||||||
|
|
||||||
const handleDuplicateBlock = useCallback(() => {
|
const handleDuplicateBlock = useCallback(() => {
|
||||||
|
const blocks = useWorkflowStore.getState().blocks
|
||||||
const sourceBlock = blocks[blockId]
|
const sourceBlock = blocks[blockId]
|
||||||
if (!sourceBlock) return
|
if (!sourceBlock) return
|
||||||
|
|
||||||
const newId = crypto.randomUUID()
|
const newId = crypto.randomUUID()
|
||||||
const newName = getUniqueBlockName(sourceBlock.name, blocks)
|
const newName = getUniqueBlockName(sourceBlock.name, blocks)
|
||||||
const subBlockValues = subBlockStore.workflowValues[activeWorkflowId || '']?.[blockId] || {}
|
const subBlockValues =
|
||||||
|
useSubBlockStore.getState().workflowValues[activeWorkflowId || '']?.[blockId] || {}
|
||||||
|
|
||||||
const { block, subBlockValues: filteredValues } = prepareDuplicateBlockState({
|
const { block, subBlockValues: filteredValues } = prepareDuplicateBlockState({
|
||||||
sourceBlock,
|
sourceBlock,
|
||||||
@@ -67,18 +68,10 @@ export const ActionBar = memo(
|
|||||||
subBlockValues,
|
subBlockValues,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
setPendingSelection([newId])
|
||||||
collaborativeBatchAddBlocks([block], [], {}, {}, { [newId]: filteredValues })
|
collaborativeBatchAddBlocks([block], [], {}, {}, { [newId]: filteredValues })
|
||||||
}, [
|
}, [blockId, activeWorkflowId, collaborativeBatchAddBlocks, setPendingSelection])
|
||||||
blockId,
|
|
||||||
blocks,
|
|
||||||
activeWorkflowId,
|
|
||||||
subBlockStore.workflowValues,
|
|
||||||
collaborativeBatchAddBlocks,
|
|
||||||
])
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Optimized single store subscription for all block data
|
|
||||||
*/
|
|
||||||
const { isEnabled, horizontalHandles, parentId, parentType } = useWorkflowStore(
|
const { isEnabled, horizontalHandles, parentId, parentType } = useWorkflowStore(
|
||||||
useCallback(
|
useCallback(
|
||||||
(state) => {
|
(state) => {
|
||||||
@@ -97,7 +90,7 @@ export const ActionBar = memo(
|
|||||||
|
|
||||||
const userPermissions = useUserPermissionsContext()
|
const userPermissions = useUserPermissionsContext()
|
||||||
|
|
||||||
const isStartBlock = blockType === 'starter' || blockType === 'start_trigger'
|
const isStartBlock = isValidStartBlockType(blockType)
|
||||||
const isResponseBlock = blockType === 'response'
|
const isResponseBlock = blockType === 'response'
|
||||||
const isNoteBlock = blockType === 'note'
|
const isNoteBlock = blockType === 'note'
|
||||||
const isSubflowBlock = blockType === 'loop' || blockType === 'parallel'
|
const isSubflowBlock = blockType === 'loop' || blockType === 'parallel'
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import {
|
|||||||
PopoverDivider,
|
PopoverDivider,
|
||||||
PopoverItem,
|
PopoverItem,
|
||||||
} from '@/components/emcn'
|
} from '@/components/emcn'
|
||||||
|
import { isValidStartBlockType } from '@/lib/workflows/triggers/start-block-types'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Block information for context menu actions
|
* Block information for context menu actions
|
||||||
@@ -73,9 +74,7 @@ export function BlockMenu({
|
|||||||
const allEnabled = selectedBlocks.every((b) => b.enabled)
|
const allEnabled = selectedBlocks.every((b) => b.enabled)
|
||||||
const allDisabled = selectedBlocks.every((b) => !b.enabled)
|
const allDisabled = selectedBlocks.every((b) => !b.enabled)
|
||||||
|
|
||||||
const hasStarterBlock = selectedBlocks.some(
|
const hasStarterBlock = selectedBlocks.some((b) => isValidStartBlockType(b.type))
|
||||||
(b) => b.type === 'starter' || b.type === 'start_trigger'
|
|
||||||
)
|
|
||||||
const allNoteBlocks = selectedBlocks.every((b) => b.type === 'note')
|
const allNoteBlocks = selectedBlocks.every((b) => b.type === 'note')
|
||||||
const isSubflow =
|
const isSubflow =
|
||||||
isSingleBlock && (selectedBlocks[0]?.type === 'loop' || selectedBlocks[0]?.type === 'parallel')
|
isSingleBlock && (selectedBlocks[0]?.type === 'loop' || selectedBlocks[0]?.type === 'parallel')
|
||||||
|
|||||||
@@ -995,7 +995,7 @@ export function Chat() {
|
|||||||
<div className='flex items-start gap-2'>
|
<div className='flex items-start gap-2'>
|
||||||
<AlertCircle className='mt-0.5 h-3 w-3 shrink-0 text-[var(--text-error)]' />
|
<AlertCircle className='mt-0.5 h-3 w-3 shrink-0 text-[var(--text-error)]' />
|
||||||
<div className='flex-1'>
|
<div className='flex-1'>
|
||||||
<div className='mb-1 font-medium text-[11px] text-[var(--text-error)]'>
|
<div className='mb-1 font-medium text-[12px] text-[var(--text-error)]'>
|
||||||
File upload error
|
File upload error
|
||||||
</div>
|
</div>
|
||||||
<div className='space-y-1'>
|
<div className='space-y-1'>
|
||||||
|
|||||||
@@ -9,8 +9,6 @@ import { useCopilotStore, usePanelStore } from '@/stores/panel'
|
|||||||
import { useTerminalStore } from '@/stores/terminal'
|
import { useTerminalStore } from '@/stores/terminal'
|
||||||
import { useWorkflowDiffStore } from '@/stores/workflow-diff'
|
import { useWorkflowDiffStore } from '@/stores/workflow-diff'
|
||||||
import { useWorkflowRegistry } from '@/stores/workflows/registry/store'
|
import { useWorkflowRegistry } from '@/stores/workflows/registry/store'
|
||||||
import { mergeSubblockState } from '@/stores/workflows/utils'
|
|
||||||
import { useWorkflowStore } from '@/stores/workflows/workflow/store'
|
|
||||||
|
|
||||||
const logger = createLogger('DiffControls')
|
const logger = createLogger('DiffControls')
|
||||||
const NOTIFICATION_WIDTH = 240
|
const NOTIFICATION_WIDTH = 240
|
||||||
@@ -19,26 +17,22 @@ const NOTIFICATION_GAP = 16
|
|||||||
export const DiffControls = memo(function DiffControls() {
|
export const DiffControls = memo(function DiffControls() {
|
||||||
const isTerminalResizing = useTerminalStore((state) => state.isResizing)
|
const isTerminalResizing = useTerminalStore((state) => state.isResizing)
|
||||||
const isPanelResizing = usePanelStore((state) => state.isResizing)
|
const isPanelResizing = usePanelStore((state) => state.isResizing)
|
||||||
const { isDiffReady, hasActiveDiff, acceptChanges, rejectChanges, baselineWorkflow } =
|
const { isDiffReady, hasActiveDiff, acceptChanges, rejectChanges } = useWorkflowDiffStore(
|
||||||
useWorkflowDiffStore(
|
useCallback(
|
||||||
useCallback(
|
(state) => ({
|
||||||
(state) => ({
|
isDiffReady: state.isDiffReady,
|
||||||
isDiffReady: state.isDiffReady,
|
hasActiveDiff: state.hasActiveDiff,
|
||||||
hasActiveDiff: state.hasActiveDiff,
|
acceptChanges: state.acceptChanges,
|
||||||
acceptChanges: state.acceptChanges,
|
rejectChanges: state.rejectChanges,
|
||||||
rejectChanges: state.rejectChanges,
|
}),
|
||||||
baselineWorkflow: state.baselineWorkflow,
|
[]
|
||||||
}),
|
|
||||||
[]
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
|
)
|
||||||
|
|
||||||
const { updatePreviewToolCallState, currentChat, messages } = useCopilotStore(
|
const { updatePreviewToolCallState } = useCopilotStore(
|
||||||
useCallback(
|
useCallback(
|
||||||
(state) => ({
|
(state) => ({
|
||||||
updatePreviewToolCallState: state.updatePreviewToolCallState,
|
updatePreviewToolCallState: state.updatePreviewToolCallState,
|
||||||
currentChat: state.currentChat,
|
|
||||||
messages: state.messages,
|
|
||||||
}),
|
}),
|
||||||
[]
|
[]
|
||||||
)
|
)
|
||||||
@@ -54,154 +48,6 @@ export const DiffControls = memo(function DiffControls() {
|
|||||||
return allNotifications.some((n) => !n.workflowId || n.workflowId === activeWorkflowId)
|
return allNotifications.some((n) => !n.workflowId || n.workflowId === activeWorkflowId)
|
||||||
}, [allNotifications, activeWorkflowId])
|
}, [allNotifications, activeWorkflowId])
|
||||||
|
|
||||||
const createCheckpoint = useCallback(async () => {
|
|
||||||
if (!activeWorkflowId || !currentChat?.id) {
|
|
||||||
logger.warn('Cannot create checkpoint: missing workflowId or chatId', {
|
|
||||||
workflowId: activeWorkflowId,
|
|
||||||
chatId: currentChat?.id,
|
|
||||||
})
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
logger.info('Creating checkpoint before accepting changes')
|
|
||||||
|
|
||||||
// Use the baseline workflow (state before diff) instead of current state
|
|
||||||
// This ensures reverting to the checkpoint restores the pre-diff state
|
|
||||||
const rawState = baselineWorkflow || useWorkflowStore.getState().getWorkflowState()
|
|
||||||
|
|
||||||
// The baseline already has merged subblock values, but we'll merge again to be safe
|
|
||||||
// This ensures all user inputs and subblock data are captured
|
|
||||||
const blocksWithSubblockValues = mergeSubblockState(rawState.blocks, activeWorkflowId)
|
|
||||||
|
|
||||||
// Filter and complete blocks to ensure all required fields are present
|
|
||||||
// This matches the validation logic from /api/workflows/[id]/state
|
|
||||||
const filteredBlocks = Object.entries(blocksWithSubblockValues).reduce(
|
|
||||||
(acc, [blockId, block]) => {
|
|
||||||
if (block.type && block.name) {
|
|
||||||
// Ensure all required fields are present
|
|
||||||
acc[blockId] = {
|
|
||||||
...block,
|
|
||||||
id: block.id || blockId, // Ensure id field is set
|
|
||||||
enabled: block.enabled !== undefined ? block.enabled : true,
|
|
||||||
horizontalHandles:
|
|
||||||
block.horizontalHandles !== undefined ? block.horizontalHandles : true,
|
|
||||||
height: block.height !== undefined ? block.height : 90,
|
|
||||||
subBlocks: block.subBlocks || {},
|
|
||||||
outputs: block.outputs || {},
|
|
||||||
data: block.data || {},
|
|
||||||
position: block.position || { x: 0, y: 0 }, // Ensure position exists
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return acc
|
|
||||||
},
|
|
||||||
{} as typeof rawState.blocks
|
|
||||||
)
|
|
||||||
|
|
||||||
// Clean the workflow state - only include valid fields, exclude null/undefined values
|
|
||||||
const workflowState = {
|
|
||||||
blocks: filteredBlocks,
|
|
||||||
edges: rawState.edges || [],
|
|
||||||
loops: rawState.loops || {},
|
|
||||||
parallels: rawState.parallels || {},
|
|
||||||
lastSaved: rawState.lastSaved || Date.now(),
|
|
||||||
deploymentStatuses: rawState.deploymentStatuses || {},
|
|
||||||
}
|
|
||||||
|
|
||||||
logger.info('Prepared complete workflow state for checkpoint', {
|
|
||||||
blocksCount: Object.keys(workflowState.blocks).length,
|
|
||||||
edgesCount: workflowState.edges.length,
|
|
||||||
loopsCount: Object.keys(workflowState.loops).length,
|
|
||||||
parallelsCount: Object.keys(workflowState.parallels).length,
|
|
||||||
hasRequiredFields: Object.values(workflowState.blocks).every(
|
|
||||||
(block) => block.id && block.type && block.name && block.position
|
|
||||||
),
|
|
||||||
hasSubblockValues: Object.values(workflowState.blocks).some((block) =>
|
|
||||||
Object.values(block.subBlocks || {}).some(
|
|
||||||
(subblock) => subblock.value !== null && subblock.value !== undefined
|
|
||||||
)
|
|
||||||
),
|
|
||||||
sampleBlock: Object.values(workflowState.blocks)[0],
|
|
||||||
})
|
|
||||||
|
|
||||||
// Find the most recent user message ID from the current chat
|
|
||||||
const userMessages = messages.filter((msg) => msg.role === 'user')
|
|
||||||
const lastUserMessage = userMessages[userMessages.length - 1]
|
|
||||||
const messageId = lastUserMessage?.id
|
|
||||||
|
|
||||||
logger.info('Creating checkpoint with message association', {
|
|
||||||
totalMessages: messages.length,
|
|
||||||
userMessageCount: userMessages.length,
|
|
||||||
lastUserMessageId: messageId,
|
|
||||||
chatId: currentChat.id,
|
|
||||||
entireMessageArray: messages,
|
|
||||||
allMessageIds: messages.map((m) => ({
|
|
||||||
id: m.id,
|
|
||||||
role: m.role,
|
|
||||||
content: m.content.substring(0, 50),
|
|
||||||
})),
|
|
||||||
selectedUserMessages: userMessages.map((m) => ({
|
|
||||||
id: m.id,
|
|
||||||
content: m.content.substring(0, 100),
|
|
||||||
})),
|
|
||||||
allRawMessageIds: messages.map((m) => m.id),
|
|
||||||
userMessageIds: userMessages.map((m) => m.id),
|
|
||||||
checkpointData: {
|
|
||||||
workflowId: activeWorkflowId,
|
|
||||||
chatId: currentChat.id,
|
|
||||||
messageId: messageId,
|
|
||||||
messageFound: !!lastUserMessage,
|
|
||||||
},
|
|
||||||
})
|
|
||||||
|
|
||||||
const response = await fetch('/api/copilot/checkpoints', {
|
|
||||||
method: 'POST',
|
|
||||||
headers: { 'Content-Type': 'application/json' },
|
|
||||||
body: JSON.stringify({
|
|
||||||
workflowId: activeWorkflowId,
|
|
||||||
chatId: currentChat.id,
|
|
||||||
messageId,
|
|
||||||
workflowState: JSON.stringify(workflowState),
|
|
||||||
}),
|
|
||||||
})
|
|
||||||
|
|
||||||
if (!response.ok) {
|
|
||||||
throw new Error(`Failed to create checkpoint: ${response.statusText}`)
|
|
||||||
}
|
|
||||||
|
|
||||||
const result = await response.json()
|
|
||||||
const newCheckpoint = result.checkpoint
|
|
||||||
|
|
||||||
logger.info('Checkpoint created successfully', {
|
|
||||||
messageId,
|
|
||||||
chatId: currentChat.id,
|
|
||||||
checkpointId: newCheckpoint?.id,
|
|
||||||
})
|
|
||||||
|
|
||||||
// Update the copilot store immediately to show the checkpoint icon
|
|
||||||
if (newCheckpoint && messageId) {
|
|
||||||
const { messageCheckpoints: currentCheckpoints } = useCopilotStore.getState()
|
|
||||||
const existingCheckpoints = currentCheckpoints[messageId] || []
|
|
||||||
|
|
||||||
const updatedCheckpoints = {
|
|
||||||
...currentCheckpoints,
|
|
||||||
[messageId]: [newCheckpoint, ...existingCheckpoints],
|
|
||||||
}
|
|
||||||
|
|
||||||
useCopilotStore.setState({ messageCheckpoints: updatedCheckpoints })
|
|
||||||
logger.info('Updated copilot store with new checkpoint', {
|
|
||||||
messageId,
|
|
||||||
checkpointId: newCheckpoint.id,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
return true
|
|
||||||
} catch (error) {
|
|
||||||
logger.error('Failed to create checkpoint:', error)
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
}, [activeWorkflowId, currentChat, messages, baselineWorkflow])
|
|
||||||
|
|
||||||
const handleAccept = useCallback(() => {
|
const handleAccept = useCallback(() => {
|
||||||
logger.info('Accepting proposed changes with backup protection')
|
logger.info('Accepting proposed changes with backup protection')
|
||||||
|
|
||||||
@@ -238,12 +84,8 @@ export const DiffControls = memo(function DiffControls() {
|
|||||||
})
|
})
|
||||||
|
|
||||||
// Create checkpoint in the background (fire-and-forget) so it doesn't block UI
|
// Create checkpoint in the background (fire-and-forget) so it doesn't block UI
|
||||||
createCheckpoint().catch((error) => {
|
|
||||||
logger.warn('Failed to create checkpoint after accept:', error)
|
|
||||||
})
|
|
||||||
|
|
||||||
logger.info('Accept triggered; UI will update optimistically')
|
logger.info('Accept triggered; UI will update optimistically')
|
||||||
}, [createCheckpoint, updatePreviewToolCallState, acceptChanges])
|
}, [updatePreviewToolCallState, acceptChanges])
|
||||||
|
|
||||||
const handleReject = useCallback(() => {
|
const handleReject = useCallback(() => {
|
||||||
logger.info('Rejecting proposed changes (optimistic)')
|
logger.info('Rejecting proposed changes (optimistic)')
|
||||||
|
|||||||
@@ -3,13 +3,11 @@ import ReactMarkdown from 'react-markdown'
|
|||||||
import type { NodeProps } from 'reactflow'
|
import type { NodeProps } from 'reactflow'
|
||||||
import remarkGfm from 'remark-gfm'
|
import remarkGfm from 'remark-gfm'
|
||||||
import { cn } from '@/lib/core/utils/cn'
|
import { cn } from '@/lib/core/utils/cn'
|
||||||
|
import { BLOCK_DIMENSIONS } from '@/lib/workflows/blocks/block-dimensions'
|
||||||
import { useUserPermissionsContext } from '@/app/workspace/[workspaceId]/providers/workspace-permissions-provider'
|
import { useUserPermissionsContext } from '@/app/workspace/[workspaceId]/providers/workspace-permissions-provider'
|
||||||
import { ActionBar } from '@/app/workspace/[workspaceId]/w/[workflowId]/components/action-bar/action-bar'
|
import { ActionBar } from '@/app/workspace/[workspaceId]/w/[workflowId]/components/action-bar/action-bar'
|
||||||
import { useBlockVisual } from '@/app/workspace/[workspaceId]/w/[workflowId]/hooks'
|
import { useBlockVisual } from '@/app/workspace/[workspaceId]/w/[workflowId]/hooks'
|
||||||
import {
|
import { useBlockDimensions } from '@/app/workspace/[workspaceId]/w/[workflowId]/hooks/use-block-dimensions'
|
||||||
BLOCK_DIMENSIONS,
|
|
||||||
useBlockDimensions,
|
|
||||||
} from '@/app/workspace/[workspaceId]/w/[workflowId]/hooks/use-block-dimensions'
|
|
||||||
import { useSubBlockStore } from '@/stores/workflows/subblock/store'
|
import { useSubBlockStore } from '@/stores/workflows/subblock/store'
|
||||||
import type { WorkflowBlockProps } from '../workflow-block/types'
|
import type { WorkflowBlockProps } from '../workflow-block/types'
|
||||||
|
|
||||||
@@ -168,12 +166,17 @@ const NoteMarkdown = memo(function NoteMarkdown({ content }: { content: string }
|
|||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
export const NoteBlock = memo(function NoteBlock({ id, data }: NodeProps<NoteBlockNodeData>) {
|
export const NoteBlock = memo(function NoteBlock({
|
||||||
|
id,
|
||||||
|
data,
|
||||||
|
selected,
|
||||||
|
}: NodeProps<NoteBlockNodeData>) {
|
||||||
const { type, config, name } = data
|
const { type, config, name } = data
|
||||||
|
|
||||||
const { activeWorkflowId, isEnabled, handleClick, hasRing, ringStyles } = useBlockVisual({
|
const { activeWorkflowId, isEnabled, handleClick, hasRing, ringStyles } = useBlockVisual({
|
||||||
blockId: id,
|
blockId: id,
|
||||||
data,
|
data,
|
||||||
|
isSelected: selected,
|
||||||
})
|
})
|
||||||
const storedValues = useSubBlockStore(
|
const storedValues = useSubBlockStore(
|
||||||
useCallback(
|
useCallback(
|
||||||
|
|||||||
@@ -6,6 +6,8 @@ import ReactMarkdown from 'react-markdown'
|
|||||||
import remarkGfm from 'remark-gfm'
|
import remarkGfm from 'remark-gfm'
|
||||||
import { Code, Tooltip } from '@/components/emcn'
|
import { Code, Tooltip } from '@/components/emcn'
|
||||||
|
|
||||||
|
const REMARK_PLUGINS = [remarkGfm]
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Recursively extracts text content from React elements
|
* Recursively extracts text content from React elements
|
||||||
* @param element - React node to extract text from
|
* @param element - React node to extract text from
|
||||||
@@ -149,14 +151,12 @@ interface CopilotMarkdownRendererProps {
|
|||||||
* Tighter spacing compared to traditional prose for better chat UX
|
* Tighter spacing compared to traditional prose for better chat UX
|
||||||
*/
|
*/
|
||||||
const markdownComponents = {
|
const markdownComponents = {
|
||||||
// Paragraphs - tight spacing, no margin on last
|
|
||||||
p: ({ children }: React.HTMLAttributes<HTMLParagraphElement>) => (
|
p: ({ children }: React.HTMLAttributes<HTMLParagraphElement>) => (
|
||||||
<p className='mb-1.5 font-base font-season text-[var(--text-primary)] text-sm leading-[1.4] last:mb-0 dark:font-[470]'>
|
<p className='mb-1.5 font-base font-season text-[var(--text-primary)] text-sm leading-[1.4] last:mb-0 dark:font-[470]'>
|
||||||
{children}
|
{children}
|
||||||
</p>
|
</p>
|
||||||
),
|
),
|
||||||
|
|
||||||
// Headings - minimal margins for chat context
|
|
||||||
h1: ({ children }: React.HTMLAttributes<HTMLHeadingElement>) => (
|
h1: ({ children }: React.HTMLAttributes<HTMLHeadingElement>) => (
|
||||||
<h1 className='mt-2 mb-1 font-season font-semibold text-[var(--text-primary)] text-base first:mt-0'>
|
<h1 className='mt-2 mb-1 font-season font-semibold text-[var(--text-primary)] text-base first:mt-0'>
|
||||||
{children}
|
{children}
|
||||||
@@ -178,7 +178,6 @@ const markdownComponents = {
|
|||||||
</h4>
|
</h4>
|
||||||
),
|
),
|
||||||
|
|
||||||
// Lists - compact spacing
|
|
||||||
ul: ({ children }: React.HTMLAttributes<HTMLUListElement>) => (
|
ul: ({ children }: React.HTMLAttributes<HTMLUListElement>) => (
|
||||||
<ul
|
<ul
|
||||||
className='my-1 space-y-0.5 pl-5 font-base font-season text-[var(--text-primary)] dark:font-[470]'
|
className='my-1 space-y-0.5 pl-5 font-base font-season text-[var(--text-primary)] dark:font-[470]'
|
||||||
@@ -204,7 +203,6 @@ const markdownComponents = {
|
|||||||
</li>
|
</li>
|
||||||
),
|
),
|
||||||
|
|
||||||
// Code blocks - handled by CodeBlock component
|
|
||||||
pre: ({ children }: React.HTMLAttributes<HTMLPreElement>) => {
|
pre: ({ children }: React.HTMLAttributes<HTMLPreElement>) => {
|
||||||
let codeContent: React.ReactNode = children
|
let codeContent: React.ReactNode = children
|
||||||
let language = 'code'
|
let language = 'code'
|
||||||
@@ -243,7 +241,6 @@ const markdownComponents = {
|
|||||||
return <CodeBlock code={actualCodeText} language={language} />
|
return <CodeBlock code={actualCodeText} language={language} />
|
||||||
},
|
},
|
||||||
|
|
||||||
// Inline code
|
|
||||||
code: ({
|
code: ({
|
||||||
className,
|
className,
|
||||||
children,
|
children,
|
||||||
@@ -257,7 +254,6 @@ const markdownComponents = {
|
|||||||
</code>
|
</code>
|
||||||
),
|
),
|
||||||
|
|
||||||
// Text formatting
|
|
||||||
strong: ({ children }: React.HTMLAttributes<HTMLElement>) => (
|
strong: ({ children }: React.HTMLAttributes<HTMLElement>) => (
|
||||||
<strong className='font-semibold text-[var(--text-primary)]'>{children}</strong>
|
<strong className='font-semibold text-[var(--text-primary)]'>{children}</strong>
|
||||||
),
|
),
|
||||||
@@ -271,22 +267,18 @@ const markdownComponents = {
|
|||||||
<i className='text-[var(--text-primary)] italic'>{children}</i>
|
<i className='text-[var(--text-primary)] italic'>{children}</i>
|
||||||
),
|
),
|
||||||
|
|
||||||
// Blockquote - compact
|
|
||||||
blockquote: ({ children }: React.HTMLAttributes<HTMLQuoteElement>) => (
|
blockquote: ({ children }: React.HTMLAttributes<HTMLQuoteElement>) => (
|
||||||
<blockquote className='my-1.5 border-[var(--border-1)] border-l-2 py-0.5 pl-3 font-season text-[var(--text-secondary)] text-sm italic'>
|
<blockquote className='my-1.5 border-[var(--border-1)] border-l-2 py-0.5 pl-3 font-season text-[var(--text-secondary)] text-sm italic'>
|
||||||
{children}
|
{children}
|
||||||
</blockquote>
|
</blockquote>
|
||||||
),
|
),
|
||||||
|
|
||||||
// Horizontal rule
|
|
||||||
hr: () => <hr className='my-3 border-[var(--divider)] border-t' />,
|
hr: () => <hr className='my-3 border-[var(--divider)] border-t' />,
|
||||||
|
|
||||||
// Links
|
|
||||||
a: ({ href, children }: React.AnchorHTMLAttributes<HTMLAnchorElement>) => (
|
a: ({ href, children }: React.AnchorHTMLAttributes<HTMLAnchorElement>) => (
|
||||||
<LinkWithPreview href={href || '#'}>{children}</LinkWithPreview>
|
<LinkWithPreview href={href || '#'}>{children}</LinkWithPreview>
|
||||||
),
|
),
|
||||||
|
|
||||||
// Tables - compact
|
|
||||||
table: ({ children }: React.TableHTMLAttributes<HTMLTableElement>) => (
|
table: ({ children }: React.TableHTMLAttributes<HTMLTableElement>) => (
|
||||||
<div className='my-2 max-w-full overflow-x-auto'>
|
<div className='my-2 max-w-full overflow-x-auto'>
|
||||||
<table className='min-w-full table-auto border border-[var(--border-1)] font-season text-xs'>
|
<table className='min-w-full table-auto border border-[var(--border-1)] font-season text-xs'>
|
||||||
@@ -314,7 +306,6 @@ const markdownComponents = {
|
|||||||
</td>
|
</td>
|
||||||
),
|
),
|
||||||
|
|
||||||
// Images
|
|
||||||
img: ({ src, alt, ...props }: React.ImgHTMLAttributes<HTMLImageElement>) => (
|
img: ({ src, alt, ...props }: React.ImgHTMLAttributes<HTMLImageElement>) => (
|
||||||
<img src={src} alt={alt || 'Image'} className='my-2 h-auto max-w-full rounded-md' {...props} />
|
<img src={src} alt={alt || 'Image'} className='my-2 h-auto max-w-full rounded-md' {...props} />
|
||||||
),
|
),
|
||||||
@@ -330,7 +321,7 @@ const markdownComponents = {
|
|||||||
function CopilotMarkdownRenderer({ content }: CopilotMarkdownRendererProps) {
|
function CopilotMarkdownRenderer({ content }: CopilotMarkdownRendererProps) {
|
||||||
return (
|
return (
|
||||||
<div className='max-w-full break-words font-base font-season text-[var(--text-primary)] text-sm leading-[1.4] dark:font-[470] [&_*]:max-w-full [&_a]:break-all [&_code:not(pre_code)]:break-words [&_li]:break-words [&_p]:break-words'>
|
<div className='max-w-full break-words font-base font-season text-[var(--text-primary)] text-sm leading-[1.4] dark:font-[470] [&_*]:max-w-full [&_a]:break-all [&_code:not(pre_code)]:break-words [&_li]:break-words [&_p]:break-words'>
|
||||||
<ReactMarkdown remarkPlugins={[remarkGfm]} components={markdownComponents}>
|
<ReactMarkdown remarkPlugins={REMARK_PLUGINS} components={markdownComponents}>
|
||||||
{content}
|
{content}
|
||||||
</ReactMarkdown>
|
</ReactMarkdown>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import { memo, useEffect, useRef, useState } from 'react'
|
import { memo, useEffect, useRef, useState } from 'react'
|
||||||
|
import { cn } from '@/lib/core/utils/cn'
|
||||||
import CopilotMarkdownRenderer from '@/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/copilot/components/copilot-message/components/markdown-renderer'
|
import CopilotMarkdownRenderer from '@/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/copilot/components/copilot-message/components/markdown-renderer'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -6,14 +7,23 @@ import CopilotMarkdownRenderer from '@/app/workspace/[workspaceId]/w/[workflowId
|
|||||||
*/
|
*/
|
||||||
const CHARACTER_DELAY = 3
|
const CHARACTER_DELAY = 3
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Props for the StreamingIndicator component
|
||||||
|
*/
|
||||||
|
interface StreamingIndicatorProps {
|
||||||
|
/** Optional class name for layout adjustments */
|
||||||
|
className?: string
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* StreamingIndicator shows animated dots during message streaming
|
* StreamingIndicator shows animated dots during message streaming
|
||||||
* Used as a standalone indicator when no content has arrived yet
|
* Used as a standalone indicator when no content has arrived yet
|
||||||
*
|
*
|
||||||
|
* @param props - Component props
|
||||||
* @returns Animated loading indicator
|
* @returns Animated loading indicator
|
||||||
*/
|
*/
|
||||||
export const StreamingIndicator = memo(() => (
|
export const StreamingIndicator = memo(({ className }: StreamingIndicatorProps) => (
|
||||||
<div className='flex h-[1.25rem] items-center text-muted-foreground'>
|
<div className={cn('flex h-[1.25rem] items-center text-muted-foreground', className)}>
|
||||||
<div className='flex space-x-0.5'>
|
<div className='flex space-x-0.5'>
|
||||||
<div className='h-1 w-1 animate-bounce rounded-full bg-muted-foreground [animation-delay:0ms] [animation-duration:1.2s]' />
|
<div className='h-1 w-1 animate-bounce rounded-full bg-muted-foreground [animation-delay:0ms] [animation-duration:1.2s]' />
|
||||||
<div className='h-1 w-1 animate-bounce rounded-full bg-muted-foreground [animation-delay:150ms] [animation-duration:1.2s]' />
|
<div className='h-1 w-1 animate-bounce rounded-full bg-muted-foreground [animation-delay:150ms] [animation-duration:1.2s]' />
|
||||||
|
|||||||
@@ -1,10 +1,20 @@
|
|||||||
'use client'
|
'use client'
|
||||||
|
|
||||||
import { memo, useEffect, useRef, useState } from 'react'
|
import { memo, useEffect, useMemo, useRef, useState } from 'react'
|
||||||
import clsx from 'clsx'
|
import clsx from 'clsx'
|
||||||
import { ChevronUp } from 'lucide-react'
|
import { ChevronUp } from 'lucide-react'
|
||||||
import CopilotMarkdownRenderer from './markdown-renderer'
|
import CopilotMarkdownRenderer from './markdown-renderer'
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Removes thinking tags (raw or escaped) from streamed content.
|
||||||
|
*/
|
||||||
|
function stripThinkingTags(text: string): string {
|
||||||
|
return text
|
||||||
|
.replace(/<\/?thinking[^>]*>/gi, '')
|
||||||
|
.replace(/<\/?thinking[^&]*>/gi, '')
|
||||||
|
.trim()
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Max height for thinking content before internal scrolling kicks in
|
* Max height for thinking content before internal scrolling kicks in
|
||||||
*/
|
*/
|
||||||
@@ -187,6 +197,9 @@ export function ThinkingBlock({
|
|||||||
label = 'Thought',
|
label = 'Thought',
|
||||||
hasSpecialTags = false,
|
hasSpecialTags = false,
|
||||||
}: ThinkingBlockProps) {
|
}: ThinkingBlockProps) {
|
||||||
|
// Strip thinking tags from content on render to handle persisted messages
|
||||||
|
const cleanContent = useMemo(() => stripThinkingTags(content || ''), [content])
|
||||||
|
|
||||||
const [isExpanded, setIsExpanded] = useState(false)
|
const [isExpanded, setIsExpanded] = useState(false)
|
||||||
const [duration, setDuration] = useState(0)
|
const [duration, setDuration] = useState(0)
|
||||||
const [userHasScrolledAway, setUserHasScrolledAway] = useState(false)
|
const [userHasScrolledAway, setUserHasScrolledAway] = useState(false)
|
||||||
@@ -209,10 +222,10 @@ export function ThinkingBlock({
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!userCollapsedRef.current && content && content.trim().length > 0) {
|
if (!userCollapsedRef.current && cleanContent && cleanContent.length > 0) {
|
||||||
setIsExpanded(true)
|
setIsExpanded(true)
|
||||||
}
|
}
|
||||||
}, [isStreaming, content, hasFollowingContent, hasSpecialTags])
|
}, [isStreaming, cleanContent, hasFollowingContent, hasSpecialTags])
|
||||||
|
|
||||||
// Reset start time when streaming begins
|
// Reset start time when streaming begins
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@@ -298,7 +311,7 @@ export function ThinkingBlock({
|
|||||||
return `${seconds}s`
|
return `${seconds}s`
|
||||||
}
|
}
|
||||||
|
|
||||||
const hasContent = content && content.trim().length > 0
|
const hasContent = cleanContent.length > 0
|
||||||
// Thinking is "done" when streaming ends OR when there's following content (like a tool call) OR when special tags appear
|
// Thinking is "done" when streaming ends OR when there's following content (like a tool call) OR when special tags appear
|
||||||
const isThinkingDone = !isStreaming || hasFollowingContent || hasSpecialTags
|
const isThinkingDone = !isStreaming || hasFollowingContent || hasSpecialTags
|
||||||
const durationText = `${label} for ${formatDuration(duration)}`
|
const durationText = `${label} for ${formatDuration(duration)}`
|
||||||
@@ -374,7 +387,10 @@ export function ThinkingBlock({
|
|||||||
isExpanded ? 'mt-1.5 max-h-[150px] opacity-100' : 'max-h-0 opacity-0'
|
isExpanded ? 'mt-1.5 max-h-[150px] opacity-100' : 'max-h-0 opacity-0'
|
||||||
)}
|
)}
|
||||||
>
|
>
|
||||||
<SmoothThinkingText content={content} isStreaming={isStreaming && !hasFollowingContent} />
|
<SmoothThinkingText
|
||||||
|
content={cleanContent}
|
||||||
|
isStreaming={isStreaming && !hasFollowingContent}
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
@@ -412,7 +428,7 @@ export function ThinkingBlock({
|
|||||||
>
|
>
|
||||||
{/* Completed thinking text - dimmed with markdown */}
|
{/* Completed thinking text - dimmed with markdown */}
|
||||||
<div className='[&_*]:!text-[var(--text-muted)] [&_*]:!text-[12px] [&_*]:!leading-[1.4] [&_p]:!m-0 [&_p]:!mb-1 [&_h1]:!text-[12px] [&_h1]:!font-semibold [&_h1]:!m-0 [&_h1]:!mb-1 [&_h2]:!text-[12px] [&_h2]:!font-semibold [&_h2]:!m-0 [&_h2]:!mb-1 [&_h3]:!text-[12px] [&_h3]:!font-semibold [&_h3]:!m-0 [&_h3]:!mb-1 [&_code]:!text-[11px] [&_ul]:!pl-5 [&_ul]:!my-1 [&_ol]:!pl-6 [&_ol]:!my-1 [&_li]:!my-0.5 [&_li]:!py-0 font-season text-[12px] text-[var(--text-muted)]'>
|
<div className='[&_*]:!text-[var(--text-muted)] [&_*]:!text-[12px] [&_*]:!leading-[1.4] [&_p]:!m-0 [&_p]:!mb-1 [&_h1]:!text-[12px] [&_h1]:!font-semibold [&_h1]:!m-0 [&_h1]:!mb-1 [&_h2]:!text-[12px] [&_h2]:!font-semibold [&_h2]:!m-0 [&_h2]:!mb-1 [&_h3]:!text-[12px] [&_h3]:!font-semibold [&_h3]:!m-0 [&_h3]:!mb-1 [&_code]:!text-[11px] [&_ul]:!pl-5 [&_ul]:!my-1 [&_ol]:!pl-6 [&_ol]:!my-1 [&_li]:!my-0.5 [&_li]:!py-0 font-season text-[12px] text-[var(--text-muted)]'>
|
||||||
<CopilotMarkdownRenderer content={content} />
|
<CopilotMarkdownRenderer content={cleanContent} />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
'use client'
|
'use client'
|
||||||
|
|
||||||
import { type FC, memo, useCallback, useMemo, useState } from 'react'
|
import { type FC, memo, useCallback, useMemo, useRef, useState } from 'react'
|
||||||
import { RotateCcw } from 'lucide-react'
|
import { RotateCcw } from 'lucide-react'
|
||||||
import { Button } from '@/components/emcn'
|
import { Button } from '@/components/emcn'
|
||||||
import {
|
import {
|
||||||
@@ -93,6 +93,8 @@ const CopilotMessage: FC<CopilotMessageProps> = memo(
|
|||||||
// UI state
|
// UI state
|
||||||
const [isHoveringMessage, setIsHoveringMessage] = useState(false)
|
const [isHoveringMessage, setIsHoveringMessage] = useState(false)
|
||||||
|
|
||||||
|
const cancelEditRef = useRef<(() => void) | null>(null)
|
||||||
|
|
||||||
// Checkpoint management hook
|
// Checkpoint management hook
|
||||||
const {
|
const {
|
||||||
showRestoreConfirmation,
|
showRestoreConfirmation,
|
||||||
@@ -112,7 +114,8 @@ const CopilotMessage: FC<CopilotMessageProps> = memo(
|
|||||||
messages,
|
messages,
|
||||||
messageCheckpoints,
|
messageCheckpoints,
|
||||||
onRevertModeChange,
|
onRevertModeChange,
|
||||||
onEditModeChange
|
onEditModeChange,
|
||||||
|
() => cancelEditRef.current?.()
|
||||||
)
|
)
|
||||||
|
|
||||||
// Message editing hook
|
// Message editing hook
|
||||||
@@ -142,6 +145,8 @@ const CopilotMessage: FC<CopilotMessageProps> = memo(
|
|||||||
pendingEditRef,
|
pendingEditRef,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
cancelEditRef.current = handleCancelEdit
|
||||||
|
|
||||||
// Get clean text content with double newline parsing
|
// Get clean text content with double newline parsing
|
||||||
const cleanTextContent = useMemo(() => {
|
const cleanTextContent = useMemo(() => {
|
||||||
if (!message.content) return ''
|
if (!message.content) return ''
|
||||||
@@ -488,8 +493,9 @@ const CopilotMessage: FC<CopilotMessageProps> = memo(
|
|||||||
{/* Content blocks in chronological order */}
|
{/* Content blocks in chronological order */}
|
||||||
{memoizedContentBlocks}
|
{memoizedContentBlocks}
|
||||||
|
|
||||||
{/* Streaming indicator always at bottom during streaming */}
|
{isStreaming && (
|
||||||
{isStreaming && <StreamingIndicator />}
|
<StreamingIndicator className={!hasVisibleContent ? 'mt-1' : undefined} />
|
||||||
|
)}
|
||||||
|
|
||||||
{message.errorType === 'usage_limit' && (
|
{message.errorType === 'usage_limit' && (
|
||||||
<div className='flex gap-1.5'>
|
<div className='flex gap-1.5'>
|
||||||
|
|||||||
@@ -1,4 +1,2 @@
|
|||||||
export { useCheckpointManagement } from './use-checkpoint-management'
|
export { useCheckpointManagement } from './use-checkpoint-management'
|
||||||
export { useMessageEditing } from './use-message-editing'
|
export { useMessageEditing } from './use-message-editing'
|
||||||
export { useMessageFeedback } from './use-message-feedback'
|
|
||||||
export { useSuccessTimers } from './use-success-timers'
|
|
||||||
|
|||||||
@@ -22,7 +22,8 @@ export function useCheckpointManagement(
|
|||||||
messages: CopilotMessage[],
|
messages: CopilotMessage[],
|
||||||
messageCheckpoints: any[],
|
messageCheckpoints: any[],
|
||||||
onRevertModeChange?: (isReverting: boolean) => void,
|
onRevertModeChange?: (isReverting: boolean) => void,
|
||||||
onEditModeChange?: (isEditing: boolean) => void
|
onEditModeChange?: (isEditing: boolean) => void,
|
||||||
|
onCancelEdit?: () => void
|
||||||
) {
|
) {
|
||||||
const [showRestoreConfirmation, setShowRestoreConfirmation] = useState(false)
|
const [showRestoreConfirmation, setShowRestoreConfirmation] = useState(false)
|
||||||
const [showCheckpointDiscardModal, setShowCheckpointDiscardModal] = useState(false)
|
const [showCheckpointDiscardModal, setShowCheckpointDiscardModal] = useState(false)
|
||||||
@@ -57,7 +58,7 @@ export function useCheckpointManagement(
|
|||||||
const { messageCheckpoints: currentCheckpoints } = useCopilotStore.getState()
|
const { messageCheckpoints: currentCheckpoints } = useCopilotStore.getState()
|
||||||
const updatedCheckpoints = {
|
const updatedCheckpoints = {
|
||||||
...currentCheckpoints,
|
...currentCheckpoints,
|
||||||
[message.id]: messageCheckpoints.slice(1),
|
[message.id]: [],
|
||||||
}
|
}
|
||||||
useCopilotStore.setState({ messageCheckpoints: updatedCheckpoints })
|
useCopilotStore.setState({ messageCheckpoints: updatedCheckpoints })
|
||||||
|
|
||||||
@@ -93,7 +94,6 @@ export function useCheckpointManagement(
|
|||||||
|
|
||||||
setShowRestoreConfirmation(false)
|
setShowRestoreConfirmation(false)
|
||||||
onRevertModeChange?.(false)
|
onRevertModeChange?.(false)
|
||||||
onEditModeChange?.(true)
|
|
||||||
|
|
||||||
logger.info('Checkpoint reverted and removed from message', {
|
logger.info('Checkpoint reverted and removed from message', {
|
||||||
messageId: message.id,
|
messageId: message.id,
|
||||||
@@ -114,7 +114,6 @@ export function useCheckpointManagement(
|
|||||||
messages,
|
messages,
|
||||||
currentChat,
|
currentChat,
|
||||||
onRevertModeChange,
|
onRevertModeChange,
|
||||||
onEditModeChange,
|
|
||||||
])
|
])
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -140,7 +139,7 @@ export function useCheckpointManagement(
|
|||||||
const { messageCheckpoints: currentCheckpoints } = useCopilotStore.getState()
|
const { messageCheckpoints: currentCheckpoints } = useCopilotStore.getState()
|
||||||
const updatedCheckpoints = {
|
const updatedCheckpoints = {
|
||||||
...currentCheckpoints,
|
...currentCheckpoints,
|
||||||
[message.id]: messageCheckpoints.slice(1),
|
[message.id]: [],
|
||||||
}
|
}
|
||||||
useCopilotStore.setState({ messageCheckpoints: updatedCheckpoints })
|
useCopilotStore.setState({ messageCheckpoints: updatedCheckpoints })
|
||||||
|
|
||||||
@@ -154,6 +153,8 @@ export function useCheckpointManagement(
|
|||||||
}
|
}
|
||||||
|
|
||||||
setShowCheckpointDiscardModal(false)
|
setShowCheckpointDiscardModal(false)
|
||||||
|
onEditModeChange?.(false)
|
||||||
|
onCancelEdit?.()
|
||||||
|
|
||||||
const { sendMessage } = useCopilotStore.getState()
|
const { sendMessage } = useCopilotStore.getState()
|
||||||
if (pendingEditRef.current) {
|
if (pendingEditRef.current) {
|
||||||
@@ -173,6 +174,7 @@ export function useCheckpointManagement(
|
|||||||
fileAttachments: fileAttachments || message.fileAttachments,
|
fileAttachments: fileAttachments || message.fileAttachments,
|
||||||
contexts: contexts || (message as any).contexts,
|
contexts: contexts || (message as any).contexts,
|
||||||
messageId: message.id,
|
messageId: message.id,
|
||||||
|
queueIfBusy: false,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
pendingEditRef.current = null
|
pendingEditRef.current = null
|
||||||
@@ -180,15 +182,17 @@ export function useCheckpointManagement(
|
|||||||
} finally {
|
} finally {
|
||||||
setIsProcessingDiscard(false)
|
setIsProcessingDiscard(false)
|
||||||
}
|
}
|
||||||
}, [messageCheckpoints, revertToCheckpoint, message, messages])
|
}, [messageCheckpoints, revertToCheckpoint, message, messages, onEditModeChange, onCancelEdit])
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Cancels checkpoint discard and clears pending edit
|
* Cancels checkpoint discard and clears pending edit
|
||||||
*/
|
*/
|
||||||
const handleCancelCheckpointDiscard = useCallback(() => {
|
const handleCancelCheckpointDiscard = useCallback(() => {
|
||||||
setShowCheckpointDiscardModal(false)
|
setShowCheckpointDiscardModal(false)
|
||||||
|
onEditModeChange?.(false)
|
||||||
|
onCancelEdit?.()
|
||||||
pendingEditRef.current = null
|
pendingEditRef.current = null
|
||||||
}, [])
|
}, [onEditModeChange, onCancelEdit])
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Continues with edit WITHOUT reverting checkpoint
|
* Continues with edit WITHOUT reverting checkpoint
|
||||||
@@ -214,11 +218,12 @@ export function useCheckpointManagement(
|
|||||||
fileAttachments: fileAttachments || message.fileAttachments,
|
fileAttachments: fileAttachments || message.fileAttachments,
|
||||||
contexts: contexts || (message as any).contexts,
|
contexts: contexts || (message as any).contexts,
|
||||||
messageId: message.id,
|
messageId: message.id,
|
||||||
|
queueIfBusy: false,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
pendingEditRef.current = null
|
pendingEditRef.current = null
|
||||||
}
|
}
|
||||||
}, [message, messages])
|
}, [message, messages, onEditModeChange, onCancelEdit])
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handles keyboard events for restore confirmation (Escape/Enter)
|
* Handles keyboard events for restore confirmation (Escape/Enter)
|
||||||
|
|||||||
@@ -166,6 +166,7 @@ export function useMessageEditing(props: UseMessageEditingProps) {
|
|||||||
fileAttachments: fileAttachments || message.fileAttachments,
|
fileAttachments: fileAttachments || message.fileAttachments,
|
||||||
contexts: contexts || (message as any).contexts,
|
contexts: contexts || (message as any).contexts,
|
||||||
messageId: message.id,
|
messageId: message.id,
|
||||||
|
queueIfBusy: false,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -1,138 +0,0 @@
|
|||||||
'use client'
|
|
||||||
|
|
||||||
import { useCallback } from 'react'
|
|
||||||
import { createLogger } from '@sim/logger'
|
|
||||||
import type { CopilotMessage } from '@/stores/panel'
|
|
||||||
import { useCopilotStore } from '@/stores/panel'
|
|
||||||
|
|
||||||
const logger = createLogger('useMessageFeedback')
|
|
||||||
|
|
||||||
const WORKFLOW_TOOL_NAMES = ['edit_workflow']
|
|
||||||
|
|
||||||
interface UseMessageFeedbackProps {
|
|
||||||
setShowUpvoteSuccess: (show: boolean) => void
|
|
||||||
setShowDownvoteSuccess: (show: boolean) => void
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Custom hook to handle message feedback (upvote/downvote)
|
|
||||||
*
|
|
||||||
* @param message - The copilot message
|
|
||||||
* @param messages - Array of all messages in the chat
|
|
||||||
* @param props - Success state setters from useSuccessTimers
|
|
||||||
* @returns Feedback management utilities
|
|
||||||
*/
|
|
||||||
export function useMessageFeedback(
|
|
||||||
message: CopilotMessage,
|
|
||||||
messages: CopilotMessage[],
|
|
||||||
props: UseMessageFeedbackProps
|
|
||||||
) {
|
|
||||||
const { setShowUpvoteSuccess, setShowDownvoteSuccess } = props
|
|
||||||
const { currentChat } = useCopilotStore()
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the full assistant response content from message
|
|
||||||
*/
|
|
||||||
const getFullAssistantContent = useCallback((message: CopilotMessage) => {
|
|
||||||
if (message.content?.trim()) {
|
|
||||||
return message.content
|
|
||||||
}
|
|
||||||
|
|
||||||
if (message.contentBlocks && message.contentBlocks.length > 0) {
|
|
||||||
return message.contentBlocks
|
|
||||||
.filter((block) => block.type === 'text')
|
|
||||||
.map((block) => block.content)
|
|
||||||
.join('')
|
|
||||||
}
|
|
||||||
|
|
||||||
return message.content || ''
|
|
||||||
}, [])
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Finds the last user query before this assistant message
|
|
||||||
*/
|
|
||||||
const getLastUserQuery = useCallback(() => {
|
|
||||||
const messageIndex = messages.findIndex((msg) => msg.id === message.id)
|
|
||||||
if (messageIndex === -1) return null
|
|
||||||
|
|
||||||
for (let i = messageIndex - 1; i >= 0; i--) {
|
|
||||||
if (messages[i].role === 'user') {
|
|
||||||
return messages[i].content
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null
|
|
||||||
}, [messages, message.id])
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Submits feedback to the API
|
|
||||||
*/
|
|
||||||
const submitFeedback = useCallback(
|
|
||||||
async (isPositive: boolean) => {
|
|
||||||
if (!currentChat?.id) {
|
|
||||||
logger.error('No current chat ID available for feedback submission')
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
const userQuery = getLastUserQuery()
|
|
||||||
if (!userQuery) {
|
|
||||||
logger.error('No user query found for feedback submission')
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
const agentResponse = getFullAssistantContent(message)
|
|
||||||
if (!agentResponse.trim()) {
|
|
||||||
logger.error('No agent response content available for feedback submission')
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
const requestBody = {
|
|
||||||
chatId: currentChat.id,
|
|
||||||
userQuery,
|
|
||||||
agentResponse,
|
|
||||||
isPositiveFeedback: isPositive,
|
|
||||||
}
|
|
||||||
|
|
||||||
const response = await fetch('/api/copilot/feedback', {
|
|
||||||
method: 'POST',
|
|
||||||
headers: {
|
|
||||||
'Content-Type': 'application/json',
|
|
||||||
},
|
|
||||||
body: JSON.stringify(requestBody),
|
|
||||||
})
|
|
||||||
|
|
||||||
if (!response.ok) {
|
|
||||||
throw new Error(`Failed to submit feedback: ${response.statusText}`)
|
|
||||||
}
|
|
||||||
|
|
||||||
await response.json()
|
|
||||||
} catch (error) {
|
|
||||||
logger.error('Error submitting feedback:', error)
|
|
||||||
}
|
|
||||||
},
|
|
||||||
[currentChat, getLastUserQuery, getFullAssistantContent, message]
|
|
||||||
)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Handles upvote action
|
|
||||||
*/
|
|
||||||
const handleUpvote = useCallback(async () => {
|
|
||||||
setShowDownvoteSuccess(false)
|
|
||||||
setShowUpvoteSuccess(true)
|
|
||||||
await submitFeedback(true)
|
|
||||||
}, [submitFeedback])
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Handles downvote action
|
|
||||||
*/
|
|
||||||
const handleDownvote = useCallback(async () => {
|
|
||||||
setShowUpvoteSuccess(false)
|
|
||||||
setShowDownvoteSuccess(true)
|
|
||||||
await submitFeedback(false)
|
|
||||||
}, [submitFeedback])
|
|
||||||
|
|
||||||
return {
|
|
||||||
handleUpvote,
|
|
||||||
handleDownvote,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,77 +0,0 @@
|
|||||||
'use client'
|
|
||||||
|
|
||||||
import { useCallback, useEffect, useState } from 'react'
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Duration to show success indicators (in milliseconds)
|
|
||||||
*/
|
|
||||||
const SUCCESS_DISPLAY_DURATION = 2000
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Custom hook to manage auto-hiding success states
|
|
||||||
* Automatically hides success indicators after a set duration
|
|
||||||
*
|
|
||||||
* @returns Success state management utilities
|
|
||||||
*/
|
|
||||||
export function useSuccessTimers() {
|
|
||||||
const [showCopySuccess, setShowCopySuccess] = useState(false)
|
|
||||||
const [showUpvoteSuccess, setShowUpvoteSuccess] = useState(false)
|
|
||||||
const [showDownvoteSuccess, setShowDownvoteSuccess] = useState(false)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Auto-hide copy success indicator after duration
|
|
||||||
*/
|
|
||||||
useEffect(() => {
|
|
||||||
if (showCopySuccess) {
|
|
||||||
const timer = setTimeout(() => {
|
|
||||||
setShowCopySuccess(false)
|
|
||||||
}, SUCCESS_DISPLAY_DURATION)
|
|
||||||
return () => clearTimeout(timer)
|
|
||||||
}
|
|
||||||
}, [showCopySuccess])
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Auto-hide upvote success indicator after duration
|
|
||||||
*/
|
|
||||||
useEffect(() => {
|
|
||||||
if (showUpvoteSuccess) {
|
|
||||||
const timer = setTimeout(() => {
|
|
||||||
setShowUpvoteSuccess(false)
|
|
||||||
}, SUCCESS_DISPLAY_DURATION)
|
|
||||||
return () => clearTimeout(timer)
|
|
||||||
}
|
|
||||||
}, [showUpvoteSuccess])
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Auto-hide downvote success indicator after duration
|
|
||||||
*/
|
|
||||||
useEffect(() => {
|
|
||||||
if (showDownvoteSuccess) {
|
|
||||||
const timer = setTimeout(() => {
|
|
||||||
setShowDownvoteSuccess(false)
|
|
||||||
}, SUCCESS_DISPLAY_DURATION)
|
|
||||||
return () => clearTimeout(timer)
|
|
||||||
}
|
|
||||||
}, [showDownvoteSuccess])
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Handles copy to clipboard action
|
|
||||||
* @param content - Content to copy to clipboard
|
|
||||||
*/
|
|
||||||
const handleCopy = useCallback((content: string) => {
|
|
||||||
navigator.clipboard.writeText(content)
|
|
||||||
setShowCopySuccess(true)
|
|
||||||
}, [])
|
|
||||||
|
|
||||||
return {
|
|
||||||
// State
|
|
||||||
showCopySuccess,
|
|
||||||
showUpvoteSuccess,
|
|
||||||
showDownvoteSuccess,
|
|
||||||
|
|
||||||
// Operations
|
|
||||||
handleCopy,
|
|
||||||
setShowUpvoteSuccess,
|
|
||||||
setShowDownvoteSuccess,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
File diff suppressed because it is too large
Load Diff
@@ -22,6 +22,9 @@ interface UseContextManagementProps {
|
|||||||
export function useContextManagement({ message, initialContexts }: UseContextManagementProps) {
|
export function useContextManagement({ message, initialContexts }: UseContextManagementProps) {
|
||||||
const [selectedContexts, setSelectedContexts] = useState<ChatContext[]>(initialContexts ?? [])
|
const [selectedContexts, setSelectedContexts] = useState<ChatContext[]>(initialContexts ?? [])
|
||||||
const initializedRef = useRef(false)
|
const initializedRef = useRef(false)
|
||||||
|
const escapeRegex = useCallback((value: string) => {
|
||||||
|
return value.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')
|
||||||
|
}, [])
|
||||||
|
|
||||||
// Initialize with initial contexts when they're first provided (for edit mode)
|
// Initialize with initial contexts when they're first provided (for edit mode)
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@@ -78,10 +81,10 @@ export function useContextManagement({ message, initialContexts }: UseContextMan
|
|||||||
// Check for slash command tokens or mention tokens based on kind
|
// Check for slash command tokens or mention tokens based on kind
|
||||||
const isSlashCommand = c.kind === 'slash_command'
|
const isSlashCommand = c.kind === 'slash_command'
|
||||||
const prefix = isSlashCommand ? '/' : '@'
|
const prefix = isSlashCommand ? '/' : '@'
|
||||||
const tokenWithSpaces = ` ${prefix}${c.label} `
|
const tokenPattern = new RegExp(
|
||||||
const tokenAtStart = `${prefix}${c.label} `
|
`(^|\\s)${escapeRegex(prefix)}${escapeRegex(c.label)}(\\s|$)`
|
||||||
// Token can appear with leading space OR at the start of the message
|
)
|
||||||
return message.includes(tokenWithSpaces) || message.startsWith(tokenAtStart)
|
return tokenPattern.test(message)
|
||||||
})
|
})
|
||||||
return filtered.length === prev.length ? prev : filtered
|
return filtered.length === prev.length ? prev : filtered
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -151,7 +151,7 @@ export function useMentionData(props: UseMentionDataProps): MentionDataReturn {
|
|||||||
useShallow(useCallback((state) => Object.keys(state.blocks), []))
|
useShallow(useCallback((state) => Object.keys(state.blocks), []))
|
||||||
)
|
)
|
||||||
|
|
||||||
const registryWorkflows = useWorkflowRegistry((state) => state.workflows)
|
const registryWorkflows = useWorkflowRegistry(useShallow((state) => state.workflows))
|
||||||
const hydrationPhase = useWorkflowRegistry((state) => state.hydration.phase)
|
const hydrationPhase = useWorkflowRegistry((state) => state.hydration.phase)
|
||||||
const isLoadingWorkflows =
|
const isLoadingWorkflows =
|
||||||
hydrationPhase === 'idle' ||
|
hydrationPhase === 'idle' ||
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { useCallback } from 'react'
|
import { useCallback, useMemo } from 'react'
|
||||||
import type { useMentionMenu } from '@/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/copilot/components/user-input/hooks/use-mention-menu'
|
import type { useMentionMenu } from '@/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/copilot/components/user-input/hooks/use-mention-menu'
|
||||||
import type { ChatContext } from '@/stores/panel'
|
import type { ChatContext } from '@/stores/panel'
|
||||||
|
|
||||||
@@ -39,11 +39,11 @@ export function useMentionTokens({
|
|||||||
setSelectedContexts,
|
setSelectedContexts,
|
||||||
}: UseMentionTokensProps) {
|
}: UseMentionTokensProps) {
|
||||||
/**
|
/**
|
||||||
* Computes all mention ranges in the message (both @mentions and /commands)
|
* Memoized mention ranges - computed once when message or selectedContexts change.
|
||||||
*
|
* This prevents expensive O(n×m) string searches from running on every keystroke
|
||||||
* @returns Array of mention ranges sorted by start position
|
* when other callbacks access the ranges.
|
||||||
*/
|
*/
|
||||||
const computeMentionRanges = useCallback((): MentionRange[] => {
|
const memoizedMentionRanges = useMemo((): MentionRange[] => {
|
||||||
const ranges: MentionRange[] = []
|
const ranges: MentionRange[] = []
|
||||||
if (!message || selectedContexts.length === 0) return ranges
|
if (!message || selectedContexts.length === 0) return ranges
|
||||||
|
|
||||||
@@ -76,6 +76,15 @@ export function useMentionTokens({
|
|||||||
ranges.push({ start: idx, end: idx + token.length, label })
|
ranges.push({ start: idx, end: idx + token.length, label })
|
||||||
fromIndex = idx + token.length
|
fromIndex = idx + token.length
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Token at end of message without trailing space: "@label" or " /label"
|
||||||
|
const tokenAtEnd = `${prefix}${label}`
|
||||||
|
if (message.endsWith(tokenAtEnd)) {
|
||||||
|
const idx = message.lastIndexOf(tokenAtEnd)
|
||||||
|
const hasLeadingSpace = idx > 0 && message[idx - 1] === ' '
|
||||||
|
const start = hasLeadingSpace ? idx - 1 : idx
|
||||||
|
ranges.push({ start, end: message.length, label })
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ranges.sort((a, b) => a.start - b.start)
|
ranges.sort((a, b) => a.start - b.start)
|
||||||
@@ -84,35 +93,45 @@ export function useMentionTokens({
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Finds a mention range containing the given position
|
* Finds a mention range containing the given position
|
||||||
|
*/
|
||||||
|
const computeMentionRanges = useCallback(
|
||||||
|
(): MentionRange[] => memoizedMentionRanges,
|
||||||
|
[memoizedMentionRanges]
|
||||||
|
)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Finds a mention range containing the given position.
|
||||||
|
* Uses memoized ranges directly for better performance.
|
||||||
*
|
*
|
||||||
* @param pos - Position to check
|
* @param pos - Position to check
|
||||||
* @returns Mention range if found, undefined otherwise
|
* @returns Mention range if found, undefined otherwise
|
||||||
*/
|
*/
|
||||||
const findRangeContaining = useCallback(
|
const findRangeContaining = useCallback(
|
||||||
(pos: number): MentionRange | undefined => {
|
(pos: number): MentionRange | undefined => {
|
||||||
const ranges = computeMentionRanges()
|
return memoizedMentionRanges.find((r) => pos > r.start && pos < r.end)
|
||||||
return ranges.find((r) => pos > r.start && pos < r.end)
|
|
||||||
},
|
},
|
||||||
[computeMentionRanges]
|
[memoizedMentionRanges]
|
||||||
)
|
)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Removes contexts for mention tokens that overlap with a text selection
|
* Removes contexts for mention tokens that overlap with a text selection.
|
||||||
|
* Uses memoized ranges directly for better performance.
|
||||||
*
|
*
|
||||||
* @param selStart - Selection start position
|
* @param selStart - Selection start position
|
||||||
* @param selEnd - Selection end position
|
* @param selEnd - Selection end position
|
||||||
*/
|
*/
|
||||||
const removeContextsInSelection = useCallback(
|
const removeContextsInSelection = useCallback(
|
||||||
(selStart: number, selEnd: number) => {
|
(selStart: number, selEnd: number) => {
|
||||||
const ranges = computeMentionRanges()
|
const overlappingRanges = memoizedMentionRanges.filter(
|
||||||
const overlappingRanges = ranges.filter((r) => !(selEnd <= r.start || selStart >= r.end))
|
(r) => !(selEnd <= r.start || selStart >= r.end)
|
||||||
|
)
|
||||||
|
|
||||||
if (overlappingRanges.length > 0) {
|
if (overlappingRanges.length > 0) {
|
||||||
const labelsToRemove = new Set(overlappingRanges.map((r) => r.label))
|
const labelsToRemove = new Set(overlappingRanges.map((r) => r.label))
|
||||||
setSelectedContexts((prev) => prev.filter((c) => !c.label || !labelsToRemove.has(c.label)))
|
setSelectedContexts((prev) => prev.filter((c) => !c.label || !labelsToRemove.has(c.label)))
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
[computeMentionRanges, setSelectedContexts]
|
[memoizedMentionRanges, setSelectedContexts]
|
||||||
)
|
)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -613,7 +613,7 @@ const UserInput = forwardRef<UserInputRef, UserInputProps>(
|
|||||||
|
|
||||||
const insertTriggerAndOpenMenu = useCallback(
|
const insertTriggerAndOpenMenu = useCallback(
|
||||||
(trigger: '@' | '/') => {
|
(trigger: '@' | '/') => {
|
||||||
if (disabled || isLoading) return
|
if (disabled) return
|
||||||
const textarea = mentionMenu.textareaRef.current
|
const textarea = mentionMenu.textareaRef.current
|
||||||
if (!textarea) return
|
if (!textarea) return
|
||||||
|
|
||||||
@@ -642,7 +642,7 @@ const UserInput = forwardRef<UserInputRef, UserInputProps>(
|
|||||||
}
|
}
|
||||||
mentionMenu.setSubmenuActiveIndex(0)
|
mentionMenu.setSubmenuActiveIndex(0)
|
||||||
},
|
},
|
||||||
[disabled, isLoading, mentionMenu, message, setMessage]
|
[disabled, mentionMenu, message, setMessage]
|
||||||
)
|
)
|
||||||
|
|
||||||
const handleOpenMentionMenuWithAt = useCallback(
|
const handleOpenMentionMenuWithAt = useCallback(
|
||||||
@@ -655,6 +655,13 @@ const UserInput = forwardRef<UserInputRef, UserInputProps>(
|
|||||||
[insertTriggerAndOpenMenu]
|
[insertTriggerAndOpenMenu]
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const handleModelSelect = useCallback(
|
||||||
|
(model: string) => {
|
||||||
|
setSelectedModel(model as any)
|
||||||
|
},
|
||||||
|
[setSelectedModel]
|
||||||
|
)
|
||||||
|
|
||||||
const canSubmit = message.trim().length > 0 && !disabled && !isLoading
|
const canSubmit = message.trim().length > 0 && !disabled && !isLoading
|
||||||
const showAbortButton = isLoading && onAbort
|
const showAbortButton = isLoading && onAbort
|
||||||
|
|
||||||
@@ -737,7 +744,7 @@ const UserInput = forwardRef<UserInputRef, UserInputProps>(
|
|||||||
title='Insert @'
|
title='Insert @'
|
||||||
className={cn(
|
className={cn(
|
||||||
'cursor-pointer rounded-[6px] p-[4.5px]',
|
'cursor-pointer rounded-[6px] p-[4.5px]',
|
||||||
(disabled || isLoading) && 'cursor-not-allowed'
|
disabled && 'cursor-not-allowed'
|
||||||
)}
|
)}
|
||||||
>
|
>
|
||||||
<AtSign className='h-3 w-3' strokeWidth={1.75} />
|
<AtSign className='h-3 w-3' strokeWidth={1.75} />
|
||||||
@@ -749,7 +756,7 @@ const UserInput = forwardRef<UserInputRef, UserInputProps>(
|
|||||||
title='Insert /'
|
title='Insert /'
|
||||||
className={cn(
|
className={cn(
|
||||||
'cursor-pointer rounded-[6px] p-[4.5px]',
|
'cursor-pointer rounded-[6px] p-[4.5px]',
|
||||||
(disabled || isLoading) && 'cursor-not-allowed'
|
disabled && 'cursor-not-allowed'
|
||||||
)}
|
)}
|
||||||
>
|
>
|
||||||
<span className='flex h-3 w-3 items-center justify-center font-medium text-[11px] leading-none'>
|
<span className='flex h-3 w-3 items-center justify-center font-medium text-[11px] leading-none'>
|
||||||
@@ -816,7 +823,7 @@ const UserInput = forwardRef<UserInputRef, UserInputProps>(
|
|||||||
placeholder={fileAttachments.isDragging ? 'Drop files here...' : effectivePlaceholder}
|
placeholder={fileAttachments.isDragging ? 'Drop files here...' : effectivePlaceholder}
|
||||||
disabled={disabled}
|
disabled={disabled}
|
||||||
rows={2}
|
rows={2}
|
||||||
className='relative z-[2] m-0 box-border h-auto min-h-[48px] w-full resize-none overflow-y-auto overflow-x-hidden break-words border-0 bg-transparent px-[2px] py-1 font-medium font-sans text-sm text-transparent leading-[1.25rem] caret-foreground outline-none [-ms-overflow-style:none] [scrollbar-width:none] [text-rendering:auto] placeholder:text-[var(--text-muted)] focus-visible:ring-0 focus-visible:ring-offset-0 dark:placeholder:text-[var(--text-muted)] [&::-webkit-scrollbar]:hidden'
|
className='relative z-[2] m-0 box-border h-auto max-h-[120px] min-h-[48px] w-full resize-none overflow-y-auto overflow-x-hidden break-words border-0 bg-transparent px-[2px] py-1 font-medium font-sans text-sm text-transparent leading-[1.25rem] caret-foreground outline-none [-ms-overflow-style:none] [scrollbar-width:none] [text-rendering:auto] placeholder:text-[var(--text-muted)] focus-visible:ring-0 focus-visible:ring-offset-0 dark:placeholder:text-[var(--text-muted)] [&::-webkit-scrollbar]:hidden'
|
||||||
/>
|
/>
|
||||||
|
|
||||||
{/* Mention Menu Portal */}
|
{/* Mention Menu Portal */}
|
||||||
@@ -863,7 +870,7 @@ const UserInput = forwardRef<UserInputRef, UserInputProps>(
|
|||||||
<ModelSelector
|
<ModelSelector
|
||||||
selectedModel={selectedModel}
|
selectedModel={selectedModel}
|
||||||
isNearTop={isNearTop}
|
isNearTop={isNearTop}
|
||||||
onModelSelect={(model: string) => setSelectedModel(model as any)}
|
onModelSelect={handleModelSelect}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
@@ -11,8 +11,6 @@ import {
|
|||||||
ButtonGroupItem,
|
ButtonGroupItem,
|
||||||
Checkbox,
|
Checkbox,
|
||||||
Code,
|
Code,
|
||||||
Combobox,
|
|
||||||
type ComboboxOption,
|
|
||||||
Input,
|
Input,
|
||||||
Label,
|
Label,
|
||||||
TagInput,
|
TagInput,
|
||||||
@@ -83,8 +81,7 @@ interface A2aDeployProps {
|
|||||||
workflowNeedsRedeployment?: boolean
|
workflowNeedsRedeployment?: boolean
|
||||||
onSubmittingChange?: (submitting: boolean) => void
|
onSubmittingChange?: (submitting: boolean) => void
|
||||||
onCanSaveChange?: (canSave: boolean) => void
|
onCanSaveChange?: (canSave: boolean) => void
|
||||||
onAgentExistsChange?: (exists: boolean) => void
|
/** Callback for when republish status changes - depends on local form state */
|
||||||
onPublishedChange?: (published: boolean) => void
|
|
||||||
onNeedsRepublishChange?: (needsRepublish: boolean) => void
|
onNeedsRepublishChange?: (needsRepublish: boolean) => void
|
||||||
onDeployWorkflow?: () => Promise<void>
|
onDeployWorkflow?: () => Promise<void>
|
||||||
}
|
}
|
||||||
@@ -99,8 +96,6 @@ export function A2aDeploy({
|
|||||||
workflowNeedsRedeployment,
|
workflowNeedsRedeployment,
|
||||||
onSubmittingChange,
|
onSubmittingChange,
|
||||||
onCanSaveChange,
|
onCanSaveChange,
|
||||||
onAgentExistsChange,
|
|
||||||
onPublishedChange,
|
|
||||||
onNeedsRepublishChange,
|
onNeedsRepublishChange,
|
||||||
onDeployWorkflow,
|
onDeployWorkflow,
|
||||||
}: A2aDeployProps) {
|
}: A2aDeployProps) {
|
||||||
@@ -236,14 +231,6 @@ export function A2aDeploy({
|
|||||||
}
|
}
|
||||||
}, [existingAgent, workflowName, workflowDescription])
|
}, [existingAgent, workflowName, workflowDescription])
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
onAgentExistsChange?.(!!existingAgent)
|
|
||||||
}, [existingAgent, onAgentExistsChange])
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
onPublishedChange?.(existingAgent?.isPublished ?? false)
|
|
||||||
}, [existingAgent?.isPublished, onPublishedChange])
|
|
||||||
|
|
||||||
const hasFormChanges = useMemo(() => {
|
const hasFormChanges = useMemo(() => {
|
||||||
if (!existingAgent) return false
|
if (!existingAgent) return false
|
||||||
const savedSchemes = existingAgent.authentication?.schemes || []
|
const savedSchemes = existingAgent.authentication?.schemes || []
|
||||||
@@ -282,14 +269,6 @@ export function A2aDeploy({
|
|||||||
onNeedsRepublishChange?.(!!needsRepublish)
|
onNeedsRepublishChange?.(!!needsRepublish)
|
||||||
}, [needsRepublish, onNeedsRepublishChange])
|
}, [needsRepublish, onNeedsRepublishChange])
|
||||||
|
|
||||||
const authSchemeOptions: ComboboxOption[] = useMemo(
|
|
||||||
() => [
|
|
||||||
{ label: 'API Key', value: 'apiKey' },
|
|
||||||
{ label: 'None (Public)', value: 'none' },
|
|
||||||
],
|
|
||||||
[]
|
|
||||||
)
|
|
||||||
|
|
||||||
const canSave = name.trim().length > 0 && description.trim().length > 0
|
const canSave = name.trim().length > 0 && description.trim().length > 0
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
onCanSaveChange?.(canSave)
|
onCanSaveChange?.(canSave)
|
||||||
@@ -769,17 +748,18 @@ console.log(data);`
|
|||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* Authentication */}
|
{/* Access */}
|
||||||
<div>
|
<div>
|
||||||
<Label className='mb-[6.5px] block pl-[2px] font-medium text-[13px] text-[var(--text-primary)]'>
|
<Label className='mb-[6.5px] block pl-[2px] font-medium text-[13px] text-[var(--text-primary)]'>
|
||||||
Authentication
|
Access
|
||||||
</Label>
|
</Label>
|
||||||
<Combobox
|
<ButtonGroup
|
||||||
options={authSchemeOptions}
|
|
||||||
value={authScheme}
|
value={authScheme}
|
||||||
onChange={(v) => setAuthScheme(v as AuthScheme)}
|
onValueChange={(value) => setAuthScheme(value as AuthScheme)}
|
||||||
placeholder='Select authentication...'
|
>
|
||||||
/>
|
<ButtonGroupItem value='apiKey'>API Key</ButtonGroupItem>
|
||||||
|
<ButtonGroupItem value='none'>Public</ButtonGroupItem>
|
||||||
|
</ButtonGroup>
|
||||||
<p className='mt-[6.5px] text-[11px] text-[var(--text-secondary)]'>
|
<p className='mt-[6.5px] text-[11px] text-[var(--text-secondary)]'>
|
||||||
{authScheme === 'none'
|
{authScheme === 'none'
|
||||||
? 'Anyone can call this agent without authentication'
|
? 'Anyone can call this agent without authentication'
|
||||||
|
|||||||
@@ -29,9 +29,11 @@ import { OutputSelect } from '@/app/workspace/[workspaceId]/w/[workflowId]/compo
|
|||||||
import {
|
import {
|
||||||
type AuthType,
|
type AuthType,
|
||||||
type ChatFormData,
|
type ChatFormData,
|
||||||
useChatDeployment,
|
useCreateChat,
|
||||||
useIdentifierValidation,
|
useDeleteChat,
|
||||||
} from './hooks'
|
useUpdateChat,
|
||||||
|
} from '@/hooks/queries/chats'
|
||||||
|
import { useIdentifierValidation } from './hooks'
|
||||||
|
|
||||||
const logger = createLogger('ChatDeploy')
|
const logger = createLogger('ChatDeploy')
|
||||||
|
|
||||||
@@ -45,7 +47,6 @@ interface ChatDeployProps {
|
|||||||
existingChat: ExistingChat | null
|
existingChat: ExistingChat | null
|
||||||
isLoadingChat: boolean
|
isLoadingChat: boolean
|
||||||
onRefetchChat: () => Promise<void>
|
onRefetchChat: () => Promise<void>
|
||||||
onChatExistsChange?: (exists: boolean) => void
|
|
||||||
chatSubmitting: boolean
|
chatSubmitting: boolean
|
||||||
setChatSubmitting: (submitting: boolean) => void
|
setChatSubmitting: (submitting: boolean) => void
|
||||||
onValidationChange?: (isValid: boolean) => void
|
onValidationChange?: (isValid: boolean) => void
|
||||||
@@ -97,7 +98,6 @@ export function ChatDeploy({
|
|||||||
existingChat,
|
existingChat,
|
||||||
isLoadingChat,
|
isLoadingChat,
|
||||||
onRefetchChat,
|
onRefetchChat,
|
||||||
onChatExistsChange,
|
|
||||||
chatSubmitting,
|
chatSubmitting,
|
||||||
setChatSubmitting,
|
setChatSubmitting,
|
||||||
onValidationChange,
|
onValidationChange,
|
||||||
@@ -121,8 +121,11 @@ export function ChatDeploy({
|
|||||||
|
|
||||||
const [formData, setFormData] = useState<ChatFormData>(initialFormData)
|
const [formData, setFormData] = useState<ChatFormData>(initialFormData)
|
||||||
const [errors, setErrors] = useState<FormErrors>({})
|
const [errors, setErrors] = useState<FormErrors>({})
|
||||||
const { deployChat } = useChatDeployment()
|
|
||||||
const formRef = useRef<HTMLFormElement>(null)
|
const formRef = useRef<HTMLFormElement>(null)
|
||||||
|
|
||||||
|
const createChatMutation = useCreateChat()
|
||||||
|
const updateChatMutation = useUpdateChat()
|
||||||
|
const deleteChatMutation = useDeleteChat()
|
||||||
const [isIdentifierValid, setIsIdentifierValid] = useState(false)
|
const [isIdentifierValid, setIsIdentifierValid] = useState(false)
|
||||||
const [hasInitializedForm, setHasInitializedForm] = useState(false)
|
const [hasInitializedForm, setHasInitializedForm] = useState(false)
|
||||||
|
|
||||||
@@ -231,15 +234,26 @@ export function ChatDeploy({
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
const chatUrl = await deployChat(
|
let chatUrl: string
|
||||||
workflowId,
|
|
||||||
formData,
|
if (existingChat?.id) {
|
||||||
deploymentInfo,
|
const result = await updateChatMutation.mutateAsync({
|
||||||
existingChat?.id,
|
chatId: existingChat.id,
|
||||||
imageUrl
|
workflowId,
|
||||||
)
|
formData,
|
||||||
|
imageUrl,
|
||||||
|
})
|
||||||
|
chatUrl = result.chatUrl
|
||||||
|
} else {
|
||||||
|
const result = await createChatMutation.mutateAsync({
|
||||||
|
workflowId,
|
||||||
|
formData,
|
||||||
|
apiKey: deploymentInfo?.apiKey,
|
||||||
|
imageUrl,
|
||||||
|
})
|
||||||
|
chatUrl = result.chatUrl
|
||||||
|
}
|
||||||
|
|
||||||
onChatExistsChange?.(true)
|
|
||||||
onDeployed?.()
|
onDeployed?.()
|
||||||
onVersionActivated?.()
|
onVersionActivated?.()
|
||||||
|
|
||||||
@@ -266,18 +280,13 @@ export function ChatDeploy({
|
|||||||
try {
|
try {
|
||||||
setIsDeleting(true)
|
setIsDeleting(true)
|
||||||
|
|
||||||
const response = await fetch(`/api/chat/manage/${existingChat.id}`, {
|
await deleteChatMutation.mutateAsync({
|
||||||
method: 'DELETE',
|
chatId: existingChat.id,
|
||||||
|
workflowId,
|
||||||
})
|
})
|
||||||
|
|
||||||
if (!response.ok) {
|
|
||||||
const error = await response.json()
|
|
||||||
throw new Error(error.error || 'Failed to delete chat')
|
|
||||||
}
|
|
||||||
|
|
||||||
setImageUrl(null)
|
setImageUrl(null)
|
||||||
setHasInitializedForm(false)
|
setHasInitializedForm(false)
|
||||||
onChatExistsChange?.(false)
|
|
||||||
await onRefetchChat()
|
await onRefetchChat()
|
||||||
|
|
||||||
onDeploymentComplete?.()
|
onDeploymentComplete?.()
|
||||||
@@ -400,7 +409,11 @@ export function ChatDeploy({
|
|||||||
<ModalHeader>Delete Chat</ModalHeader>
|
<ModalHeader>Delete Chat</ModalHeader>
|
||||||
<ModalBody>
|
<ModalBody>
|
||||||
<p className='text-[12px] text-[var(--text-secondary)]'>
|
<p className='text-[12px] text-[var(--text-secondary)]'>
|
||||||
Are you sure you want to delete this chat?{' '}
|
Are you sure you want to delete{' '}
|
||||||
|
<span className='font-medium text-[var(--text-primary)]'>
|
||||||
|
{existingChat?.title || 'this chat'}
|
||||||
|
</span>
|
||||||
|
?{' '}
|
||||||
<span className='text-[var(--text-error)]'>
|
<span className='text-[var(--text-error)]'>
|
||||||
This will remove the chat at "{getEmailDomain()}/chat/{existingChat?.identifier}"
|
This will remove the chat at "{getEmailDomain()}/chat/{existingChat?.identifier}"
|
||||||
and make it unavailable to all users.
|
and make it unavailable to all users.
|
||||||
@@ -415,7 +428,7 @@ export function ChatDeploy({
|
|||||||
>
|
>
|
||||||
Cancel
|
Cancel
|
||||||
</Button>
|
</Button>
|
||||||
<Button variant='default' onClick={handleDelete} disabled={isDeleting}>
|
<Button variant='destructive' onClick={handleDelete} disabled={isDeleting}>
|
||||||
{isDeleting ? 'Deleting...' : 'Delete'}
|
{isDeleting ? 'Deleting...' : 'Delete'}
|
||||||
</Button>
|
</Button>
|
||||||
</ModalFooter>
|
</ModalFooter>
|
||||||
@@ -548,7 +561,7 @@ function IdentifierInput({
|
|||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{error && <p className='mt-[6.5px] text-[11px] text-[var(--text-error)]'>{error}</p>}
|
{error && <p className='mt-[6.5px] text-[12px] text-[var(--text-error)]'>{error}</p>}
|
||||||
<p className='mt-[6.5px] truncate text-[11px] text-[var(--text-secondary)]'>
|
<p className='mt-[6.5px] truncate text-[11px] text-[var(--text-secondary)]'>
|
||||||
{isEditingExisting && value ? (
|
{isEditingExisting && value ? (
|
||||||
<>
|
<>
|
||||||
@@ -768,7 +781,7 @@ function AuthSelector({
|
|||||||
disabled={disabled}
|
disabled={disabled}
|
||||||
/>
|
/>
|
||||||
{emailError && (
|
{emailError && (
|
||||||
<p className='mt-[6.5px] text-[11px] text-[var(--text-error)]'>{emailError}</p>
|
<p className='mt-[6.5px] text-[12px] text-[var(--text-error)]'>{emailError}</p>
|
||||||
)}
|
)}
|
||||||
<p className='mt-[6.5px] text-[11px] text-[var(--text-secondary)]'>
|
<p className='mt-[6.5px] text-[11px] text-[var(--text-secondary)]'>
|
||||||
{authType === 'email'
|
{authType === 'email'
|
||||||
@@ -778,7 +791,7 @@ function AuthSelector({
|
|||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{error && <p className='mt-[6.5px] text-[11px] text-[var(--text-error)]'>{error}</p>}
|
{error && <p className='mt-[6.5px] text-[12px] text-[var(--text-error)]'>{error}</p>}
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,2 +1 @@
|
|||||||
export { type AuthType, type ChatFormData, useChatDeployment } from './use-chat-deployment'
|
|
||||||
export { useIdentifierValidation } from './use-identifier-validation'
|
export { useIdentifierValidation } from './use-identifier-validation'
|
||||||
|
|||||||
@@ -1,131 +0,0 @@
|
|||||||
import { useCallback } from 'react'
|
|
||||||
import { createLogger } from '@sim/logger'
|
|
||||||
import { z } from 'zod'
|
|
||||||
import type { OutputConfig } from '@/stores/chat/types'
|
|
||||||
|
|
||||||
const logger = createLogger('ChatDeployment')
|
|
||||||
|
|
||||||
export type AuthType = 'public' | 'password' | 'email' | 'sso'
|
|
||||||
|
|
||||||
export interface ChatFormData {
|
|
||||||
identifier: string
|
|
||||||
title: string
|
|
||||||
description: string
|
|
||||||
authType: AuthType
|
|
||||||
password: string
|
|
||||||
emails: string[]
|
|
||||||
welcomeMessage: string
|
|
||||||
selectedOutputBlocks: string[]
|
|
||||||
}
|
|
||||||
|
|
||||||
const chatSchema = z.object({
|
|
||||||
workflowId: z.string().min(1, 'Workflow ID is required'),
|
|
||||||
identifier: z
|
|
||||||
.string()
|
|
||||||
.min(1, 'Identifier is required')
|
|
||||||
.regex(/^[a-z0-9-]+$/, 'Identifier can only contain lowercase letters, numbers, and hyphens'),
|
|
||||||
title: z.string().min(1, 'Title is required'),
|
|
||||||
description: z.string().optional(),
|
|
||||||
customizations: z.object({
|
|
||||||
primaryColor: z.string(),
|
|
||||||
welcomeMessage: z.string(),
|
|
||||||
imageUrl: z.string().optional(),
|
|
||||||
}),
|
|
||||||
authType: z.enum(['public', 'password', 'email', 'sso']).default('public'),
|
|
||||||
password: z.string().optional(),
|
|
||||||
allowedEmails: z.array(z.string()).optional().default([]),
|
|
||||||
outputConfigs: z
|
|
||||||
.array(
|
|
||||||
z.object({
|
|
||||||
blockId: z.string(),
|
|
||||||
path: z.string(),
|
|
||||||
})
|
|
||||||
)
|
|
||||||
.optional()
|
|
||||||
.default([]),
|
|
||||||
})
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Parses output block selections into structured output configs
|
|
||||||
*/
|
|
||||||
function parseOutputConfigs(selectedOutputBlocks: string[]): OutputConfig[] {
|
|
||||||
return selectedOutputBlocks
|
|
||||||
.map((outputId) => {
|
|
||||||
const firstUnderscoreIndex = outputId.indexOf('_')
|
|
||||||
if (firstUnderscoreIndex !== -1) {
|
|
||||||
const blockId = outputId.substring(0, firstUnderscoreIndex)
|
|
||||||
const path = outputId.substring(firstUnderscoreIndex + 1)
|
|
||||||
if (blockId && path) {
|
|
||||||
return { blockId, path }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null
|
|
||||||
})
|
|
||||||
.filter((config): config is OutputConfig => config !== null)
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Hook for deploying or updating a chat interface
|
|
||||||
*/
|
|
||||||
export function useChatDeployment() {
|
|
||||||
const deployChat = useCallback(
|
|
||||||
async (
|
|
||||||
workflowId: string,
|
|
||||||
formData: ChatFormData,
|
|
||||||
deploymentInfo: { apiKey: string } | null,
|
|
||||||
existingChatId?: string,
|
|
||||||
imageUrl?: string | null
|
|
||||||
): Promise<string> => {
|
|
||||||
const outputConfigs = parseOutputConfigs(formData.selectedOutputBlocks)
|
|
||||||
|
|
||||||
const payload = {
|
|
||||||
workflowId,
|
|
||||||
identifier: formData.identifier.trim(),
|
|
||||||
title: formData.title.trim(),
|
|
||||||
description: formData.description.trim(),
|
|
||||||
customizations: {
|
|
||||||
primaryColor: 'var(--brand-primary-hover-hex)',
|
|
||||||
welcomeMessage: formData.welcomeMessage.trim(),
|
|
||||||
...(imageUrl && { imageUrl }),
|
|
||||||
},
|
|
||||||
authType: formData.authType,
|
|
||||||
password: formData.authType === 'password' ? formData.password : undefined,
|
|
||||||
allowedEmails:
|
|
||||||
formData.authType === 'email' || formData.authType === 'sso' ? formData.emails : [],
|
|
||||||
outputConfigs,
|
|
||||||
apiKey: deploymentInfo?.apiKey,
|
|
||||||
deployApiEnabled: !existingChatId,
|
|
||||||
}
|
|
||||||
|
|
||||||
chatSchema.parse(payload)
|
|
||||||
|
|
||||||
const endpoint = existingChatId ? `/api/chat/manage/${existingChatId}` : '/api/chat'
|
|
||||||
const method = existingChatId ? 'PATCH' : 'POST'
|
|
||||||
|
|
||||||
const response = await fetch(endpoint, {
|
|
||||||
method,
|
|
||||||
headers: { 'Content-Type': 'application/json' },
|
|
||||||
body: JSON.stringify(payload),
|
|
||||||
})
|
|
||||||
|
|
||||||
const result = await response.json()
|
|
||||||
|
|
||||||
if (!response.ok) {
|
|
||||||
if (result.error === 'Identifier already in use') {
|
|
||||||
throw new Error('This identifier is already in use')
|
|
||||||
}
|
|
||||||
throw new Error(result.error || `Failed to ${existingChatId ? 'update' : 'deploy'} chat`)
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!result.chatUrl) {
|
|
||||||
throw new Error('Response missing chatUrl')
|
|
||||||
}
|
|
||||||
|
|
||||||
logger.info(`Chat ${existingChatId ? 'updated' : 'deployed'} successfully:`, result.chatUrl)
|
|
||||||
return result.chatUrl
|
|
||||||
},
|
|
||||||
[]
|
|
||||||
)
|
|
||||||
|
|
||||||
return { deployChat }
|
|
||||||
}
|
|
||||||
@@ -216,7 +216,7 @@ export function FormBuilder({
|
|||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
{titleError && (
|
{titleError && (
|
||||||
<p className='mt-[4px] text-[11px] text-[var(--text-error)]'>{titleError}</p>
|
<p className='mt-[4px] text-[12px] text-[var(--text-error)]'>{titleError}</p>
|
||||||
)}
|
)}
|
||||||
<div className='mt-[4px] flex items-center gap-[6px]'>
|
<div className='mt-[4px] flex items-center gap-[6px]'>
|
||||||
<input
|
<input
|
||||||
|
|||||||
@@ -17,11 +17,18 @@ import { Skeleton } from '@/components/ui'
|
|||||||
import { isDev } from '@/lib/core/config/feature-flags'
|
import { isDev } from '@/lib/core/config/feature-flags'
|
||||||
import { cn } from '@/lib/core/utils/cn'
|
import { cn } from '@/lib/core/utils/cn'
|
||||||
import { getBaseUrl, getEmailDomain } from '@/lib/core/utils/urls'
|
import { getBaseUrl, getEmailDomain } from '@/lib/core/utils/urls'
|
||||||
|
import { isValidStartBlockType } from '@/lib/workflows/triggers/start-block-types'
|
||||||
|
import {
|
||||||
|
type FieldConfig,
|
||||||
|
useCreateForm,
|
||||||
|
useDeleteForm,
|
||||||
|
useFormByWorkflow,
|
||||||
|
useUpdateForm,
|
||||||
|
} from '@/hooks/queries/forms'
|
||||||
import { useSubBlockStore } from '@/stores/workflows/subblock/store'
|
import { useSubBlockStore } from '@/stores/workflows/subblock/store'
|
||||||
import { useWorkflowStore } from '@/stores/workflows/workflow/store'
|
import { useWorkflowStore } from '@/stores/workflows/workflow/store'
|
||||||
import { EmbedCodeGenerator } from './components/embed-code-generator'
|
import { EmbedCodeGenerator } from './components/embed-code-generator'
|
||||||
import { FormBuilder } from './components/form-builder'
|
import { FormBuilder } from './components/form-builder'
|
||||||
import { useFormDeployment } from './hooks/use-form-deployment'
|
|
||||||
import { useIdentifierValidation } from './hooks/use-identifier-validation'
|
import { useIdentifierValidation } from './hooks/use-identifier-validation'
|
||||||
|
|
||||||
const logger = createLogger('FormDeploy')
|
const logger = createLogger('FormDeploy')
|
||||||
@@ -34,38 +41,11 @@ interface FormErrors {
|
|||||||
general?: string
|
general?: string
|
||||||
}
|
}
|
||||||
|
|
||||||
interface FieldConfig {
|
|
||||||
name: string
|
|
||||||
type: string
|
|
||||||
label: string
|
|
||||||
description?: string
|
|
||||||
required?: boolean
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface ExistingForm {
|
|
||||||
id: string
|
|
||||||
identifier: string
|
|
||||||
title: string
|
|
||||||
description?: string
|
|
||||||
customizations: {
|
|
||||||
primaryColor?: string
|
|
||||||
thankYouMessage?: string
|
|
||||||
logoUrl?: string
|
|
||||||
fieldConfigs?: FieldConfig[]
|
|
||||||
}
|
|
||||||
authType: 'public' | 'password' | 'email'
|
|
||||||
hasPassword?: boolean
|
|
||||||
allowedEmails?: string[]
|
|
||||||
showBranding: boolean
|
|
||||||
isActive: boolean
|
|
||||||
}
|
|
||||||
|
|
||||||
interface FormDeployProps {
|
interface FormDeployProps {
|
||||||
workflowId: string
|
workflowId: string
|
||||||
onDeploymentComplete?: () => void
|
onDeploymentComplete?: () => void
|
||||||
onValidationChange?: (isValid: boolean) => void
|
onValidationChange?: (isValid: boolean) => void
|
||||||
onSubmittingChange?: (isSubmitting: boolean) => void
|
onSubmittingChange?: (isSubmitting: boolean) => void
|
||||||
onExistingFormChange?: (exists: boolean) => void
|
|
||||||
formSubmitting?: boolean
|
formSubmitting?: boolean
|
||||||
setFormSubmitting?: (submitting: boolean) => void
|
setFormSubmitting?: (submitting: boolean) => void
|
||||||
onDeployed?: () => Promise<void>
|
onDeployed?: () => Promise<void>
|
||||||
@@ -81,7 +61,6 @@ export function FormDeploy({
|
|||||||
onDeploymentComplete,
|
onDeploymentComplete,
|
||||||
onValidationChange,
|
onValidationChange,
|
||||||
onSubmittingChange,
|
onSubmittingChange,
|
||||||
onExistingFormChange,
|
|
||||||
formSubmitting,
|
formSubmitting,
|
||||||
setFormSubmitting,
|
setFormSubmitting,
|
||||||
onDeployed,
|
onDeployed,
|
||||||
@@ -95,8 +74,6 @@ export function FormDeploy({
|
|||||||
const [authType, setAuthType] = useState<'public' | 'password' | 'email'>('public')
|
const [authType, setAuthType] = useState<'public' | 'password' | 'email'>('public')
|
||||||
const [password, setPassword] = useState('')
|
const [password, setPassword] = useState('')
|
||||||
const [emailItems, setEmailItems] = useState<TagItem[]>([])
|
const [emailItems, setEmailItems] = useState<TagItem[]>([])
|
||||||
const [existingForm, setExistingForm] = useState<ExistingForm | null>(null)
|
|
||||||
const [isLoading, setIsLoading] = useState(true)
|
|
||||||
const [formUrl, setFormUrl] = useState('')
|
const [formUrl, setFormUrl] = useState('')
|
||||||
const [inputFields, setInputFields] = useState<{ name: string; type: string }[]>([])
|
const [inputFields, setInputFields] = useState<{ name: string; type: string }[]>([])
|
||||||
const [showPasswordField, setShowPasswordField] = useState(false)
|
const [showPasswordField, setShowPasswordField] = useState(false)
|
||||||
@@ -104,7 +81,12 @@ export function FormDeploy({
|
|||||||
const [errors, setErrors] = useState<FormErrors>({})
|
const [errors, setErrors] = useState<FormErrors>({})
|
||||||
const [isIdentifierValid, setIsIdentifierValid] = useState(false)
|
const [isIdentifierValid, setIsIdentifierValid] = useState(false)
|
||||||
|
|
||||||
const { createForm, updateForm, deleteForm, isSubmitting } = useFormDeployment()
|
const { data: existingForm, isLoading } = useFormByWorkflow(workflowId)
|
||||||
|
const createFormMutation = useCreateForm()
|
||||||
|
const updateFormMutation = useUpdateForm()
|
||||||
|
const deleteFormMutation = useDeleteForm()
|
||||||
|
|
||||||
|
const isSubmitting = createFormMutation.isPending || updateFormMutation.isPending
|
||||||
|
|
||||||
const {
|
const {
|
||||||
isChecking: isCheckingIdentifier,
|
isChecking: isCheckingIdentifier,
|
||||||
@@ -124,85 +106,54 @@ export function FormDeploy({
|
|||||||
setErrors((prev) => ({ ...prev, [field]: undefined }))
|
setErrors((prev) => ({ ...prev, [field]: undefined }))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fetch existing form deployment
|
// Populate form fields when existing form data is loaded
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
async function fetchExistingForm() {
|
if (existingForm) {
|
||||||
if (!workflowId) return
|
setIdentifier(existingForm.identifier)
|
||||||
|
setTitle(existingForm.title)
|
||||||
try {
|
setDescription(existingForm.description || '')
|
||||||
setIsLoading(true)
|
setThankYouMessage(
|
||||||
const response = await fetch(`/api/workflows/${workflowId}/form/status`)
|
existingForm.customizations?.thankYouMessage ||
|
||||||
|
'Your response has been submitted successfully.'
|
||||||
if (response.ok) {
|
)
|
||||||
const data = await response.json()
|
setAuthType(existingForm.authType)
|
||||||
if (data.isDeployed && data.form) {
|
setEmailItems(
|
||||||
const detailResponse = await fetch(`/api/form/manage/${data.form.id}`)
|
(existingForm.allowedEmails || []).map((email) => ({ value: email, isValid: true }))
|
||||||
if (detailResponse.ok) {
|
)
|
||||||
const formDetail = await detailResponse.json()
|
if (existingForm.customizations?.fieldConfigs) {
|
||||||
const form = formDetail.form as ExistingForm
|
setFieldConfigs(existingForm.customizations.fieldConfigs)
|
||||||
setExistingForm(form)
|
|
||||||
onExistingFormChange?.(true)
|
|
||||||
|
|
||||||
setIdentifier(form.identifier)
|
|
||||||
setTitle(form.title)
|
|
||||||
setDescription(form.description || '')
|
|
||||||
setThankYouMessage(
|
|
||||||
form.customizations?.thankYouMessage ||
|
|
||||||
'Your response has been submitted successfully.'
|
|
||||||
)
|
|
||||||
setAuthType(form.authType)
|
|
||||||
setEmailItems(
|
|
||||||
(form.allowedEmails || []).map((email) => ({ value: email, isValid: true }))
|
|
||||||
)
|
|
||||||
if (form.customizations?.fieldConfigs) {
|
|
||||||
setFieldConfigs(form.customizations.fieldConfigs)
|
|
||||||
}
|
|
||||||
|
|
||||||
const baseUrl = getBaseUrl()
|
|
||||||
try {
|
|
||||||
const url = new URL(baseUrl)
|
|
||||||
let host = url.host
|
|
||||||
if (host.startsWith('www.')) host = host.substring(4)
|
|
||||||
setFormUrl(`${url.protocol}//${host}/form/${form.identifier}`)
|
|
||||||
} catch {
|
|
||||||
setFormUrl(
|
|
||||||
isDev
|
|
||||||
? `http://localhost:3000/form/${form.identifier}`
|
|
||||||
: `https://sim.ai/form/${form.identifier}`
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
setExistingForm(null)
|
|
||||||
onExistingFormChange?.(false)
|
|
||||||
|
|
||||||
const workflowName =
|
|
||||||
useWorkflowStore.getState().blocks[Object.keys(useWorkflowStore.getState().blocks)[0]]
|
|
||||||
?.name || 'Form'
|
|
||||||
setTitle(`${workflowName} Form`)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (err) {
|
|
||||||
logger.error('Error fetching form deployment:', err)
|
|
||||||
} finally {
|
|
||||||
setIsLoading(false)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const baseUrl = getBaseUrl()
|
||||||
|
try {
|
||||||
|
const url = new URL(baseUrl)
|
||||||
|
let host = url.host
|
||||||
|
if (host.startsWith('www.')) host = host.substring(4)
|
||||||
|
setFormUrl(`${url.protocol}//${host}/form/${existingForm.identifier}`)
|
||||||
|
} catch {
|
||||||
|
setFormUrl(
|
||||||
|
isDev
|
||||||
|
? `http://localhost:3000/form/${existingForm.identifier}`
|
||||||
|
: `https://sim.ai/form/${existingForm.identifier}`
|
||||||
|
)
|
||||||
|
}
|
||||||
|
} else if (!isLoading) {
|
||||||
|
const workflowName =
|
||||||
|
useWorkflowStore.getState().blocks[Object.keys(useWorkflowStore.getState().blocks)[0]]
|
||||||
|
?.name || 'Form'
|
||||||
|
setTitle(`${workflowName} Form`)
|
||||||
}
|
}
|
||||||
|
}, [existingForm, isLoading])
|
||||||
|
|
||||||
fetchExistingForm()
|
|
||||||
}, [workflowId, onExistingFormChange])
|
|
||||||
|
|
||||||
// Get input fields from start block and initialize field configs
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const blocks = Object.values(useWorkflowStore.getState().blocks)
|
const blocks = Object.values(useWorkflowStore.getState().blocks)
|
||||||
const startBlock = blocks.find((b) => b.type === 'starter' || b.type === 'start_trigger')
|
const startBlock = blocks.find((b) => isValidStartBlockType(b.type))
|
||||||
|
|
||||||
if (startBlock) {
|
if (startBlock) {
|
||||||
const inputFormat = useSubBlockStore.getState().getValue(startBlock.id, 'inputFormat')
|
const inputFormat = useSubBlockStore.getState().getValue(startBlock.id, 'inputFormat')
|
||||||
if (inputFormat && Array.isArray(inputFormat)) {
|
if (inputFormat && Array.isArray(inputFormat)) {
|
||||||
setInputFields(inputFormat)
|
setInputFields(inputFormat)
|
||||||
|
|
||||||
// Initialize field configs if not already set
|
|
||||||
if (fieldConfigs.length === 0) {
|
if (fieldConfigs.length === 0) {
|
||||||
setFieldConfigs(
|
setFieldConfigs(
|
||||||
inputFormat.map((f: { name: string; type?: string }) => ({
|
inputFormat.map((f: { name: string; type?: string }) => ({
|
||||||
@@ -222,7 +173,6 @@ export function FormDeploy({
|
|||||||
|
|
||||||
const allowedEmails = emailItems.filter((item) => item.isValid).map((item) => item.value)
|
const allowedEmails = emailItems.filter((item) => item.isValid).map((item) => item.value)
|
||||||
|
|
||||||
// Validate form
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const isValid =
|
const isValid =
|
||||||
inputFields.length > 0 &&
|
inputFields.length > 0 &&
|
||||||
@@ -253,7 +203,6 @@ export function FormDeploy({
|
|||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
setErrors({})
|
setErrors({})
|
||||||
|
|
||||||
// Validate before submit
|
|
||||||
if (!isIdentifierValid && identifier !== existingForm?.identifier) {
|
if (!isIdentifierValid && identifier !== existingForm?.identifier) {
|
||||||
setError('identifier', 'Please wait for identifier validation to complete')
|
setError('identifier', 'Please wait for identifier validation to complete')
|
||||||
return
|
return
|
||||||
@@ -281,17 +230,21 @@ export function FormDeploy({
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
if (existingForm) {
|
if (existingForm) {
|
||||||
await updateForm(existingForm.id, {
|
await updateFormMutation.mutateAsync({
|
||||||
identifier,
|
formId: existingForm.id,
|
||||||
title,
|
workflowId,
|
||||||
description,
|
data: {
|
||||||
customizations,
|
identifier,
|
||||||
authType,
|
title,
|
||||||
password: password || undefined,
|
description,
|
||||||
allowedEmails,
|
customizations,
|
||||||
|
authType,
|
||||||
|
password: password || undefined,
|
||||||
|
allowedEmails,
|
||||||
|
},
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
const result = await createForm({
|
const result = await createFormMutation.mutateAsync({
|
||||||
workflowId,
|
workflowId,
|
||||||
identifier,
|
identifier,
|
||||||
title,
|
title,
|
||||||
@@ -304,7 +257,6 @@ export function FormDeploy({
|
|||||||
|
|
||||||
if (result?.formUrl) {
|
if (result?.formUrl) {
|
||||||
setFormUrl(result.formUrl)
|
setFormUrl(result.formUrl)
|
||||||
// Open the form in a new window after successful deployment
|
|
||||||
window.open(result.formUrl, '_blank', 'noopener,noreferrer')
|
window.open(result.formUrl, '_blank', 'noopener,noreferrer')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -318,7 +270,6 @@ export function FormDeploy({
|
|||||||
const message = err instanceof Error ? err.message : 'An error occurred'
|
const message = err instanceof Error ? err.message : 'An error occurred'
|
||||||
logger.error('Error deploying form:', err)
|
logger.error('Error deploying form:', err)
|
||||||
|
|
||||||
// Parse error message and show inline
|
|
||||||
if (message.toLowerCase().includes('identifier')) {
|
if (message.toLowerCase().includes('identifier')) {
|
||||||
setError('identifier', message)
|
setError('identifier', message)
|
||||||
} else if (message.toLowerCase().includes('password')) {
|
} else if (message.toLowerCase().includes('password')) {
|
||||||
@@ -342,8 +293,8 @@ export function FormDeploy({
|
|||||||
password,
|
password,
|
||||||
allowedEmails,
|
allowedEmails,
|
||||||
isIdentifierValid,
|
isIdentifierValid,
|
||||||
createForm,
|
createFormMutation,
|
||||||
updateForm,
|
updateFormMutation,
|
||||||
onDeployed,
|
onDeployed,
|
||||||
onDeploymentComplete,
|
onDeploymentComplete,
|
||||||
]
|
]
|
||||||
@@ -353,9 +304,10 @@ export function FormDeploy({
|
|||||||
if (!existingForm) return
|
if (!existingForm) return
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await deleteForm(existingForm.id)
|
await deleteFormMutation.mutateAsync({
|
||||||
setExistingForm(null)
|
formId: existingForm.id,
|
||||||
onExistingFormChange?.(false)
|
workflowId,
|
||||||
|
})
|
||||||
setIdentifier('')
|
setIdentifier('')
|
||||||
setTitle('')
|
setTitle('')
|
||||||
setDescription('')
|
setDescription('')
|
||||||
@@ -363,7 +315,7 @@ export function FormDeploy({
|
|||||||
} catch (err) {
|
} catch (err) {
|
||||||
logger.error('Error deleting form:', err)
|
logger.error('Error deleting form:', err)
|
||||||
}
|
}
|
||||||
}, [existingForm, deleteForm, onExistingFormChange])
|
}, [existingForm, deleteFormMutation, workflowId])
|
||||||
|
|
||||||
if (isLoading) {
|
if (isLoading) {
|
||||||
return (
|
return (
|
||||||
@@ -447,7 +399,7 @@ export function FormDeploy({
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{(identifierError || errors.identifier) && (
|
{(identifierError || errors.identifier) && (
|
||||||
<p className='mt-[6.5px] text-[11px] text-[var(--text-error)]'>
|
<p className='mt-[6.5px] text-[12px] text-[var(--text-error)]'>
|
||||||
{identifierError || errors.identifier}
|
{identifierError || errors.identifier}
|
||||||
</p>
|
</p>
|
||||||
)}
|
)}
|
||||||
@@ -531,7 +483,7 @@ export function FormDeploy({
|
|||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
{errors.password && (
|
{errors.password && (
|
||||||
<p className='mt-[6.5px] text-[11px] text-[var(--text-error)]'>{errors.password}</p>
|
<p className='mt-[6.5px] text-[12px] text-[var(--text-error)]'>{errors.password}</p>
|
||||||
)}
|
)}
|
||||||
<p className='mt-[6.5px] text-[11px] text-[var(--text-secondary)]'>
|
<p className='mt-[6.5px] text-[11px] text-[var(--text-secondary)]'>
|
||||||
{existingForm?.hasPassword
|
{existingForm?.hasPassword
|
||||||
@@ -568,7 +520,7 @@ export function FormDeploy({
|
|||||||
placeholderWithTags='Add another'
|
placeholderWithTags='Add another'
|
||||||
/>
|
/>
|
||||||
{errors.emails && (
|
{errors.emails && (
|
||||||
<p className='mt-[6.5px] text-[11px] text-[var(--text-error)]'>{errors.emails}</p>
|
<p className='mt-[6.5px] text-[12px] text-[var(--text-error)]'>{errors.emails}</p>
|
||||||
)}
|
)}
|
||||||
<p className='mt-[6.5px] text-[11px] text-[var(--text-secondary)]'>
|
<p className='mt-[6.5px] text-[11px] text-[var(--text-secondary)]'>
|
||||||
Add specific emails or entire domains (@example.com)
|
Add specific emails or entire domains (@example.com)
|
||||||
@@ -599,7 +551,7 @@ export function FormDeploy({
|
|||||||
)}
|
)}
|
||||||
|
|
||||||
{errors.general && (
|
{errors.general && (
|
||||||
<p className='mt-[6.5px] text-[11px] text-[var(--text-error)]'>{errors.general}</p>
|
<p className='mt-[6.5px] text-[12px] text-[var(--text-error)]'>{errors.general}</p>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
<button type='button' data-delete-trigger onClick={handleDelete} className='hidden' />
|
<button type='button' data-delete-trigger onClick={handleDelete} className='hidden' />
|
||||||
|
|||||||
@@ -1,151 +0,0 @@
|
|||||||
import { useCallback, useState } from 'react'
|
|
||||||
import { createLogger } from '@sim/logger'
|
|
||||||
|
|
||||||
const logger = createLogger('useFormDeployment')
|
|
||||||
|
|
||||||
interface CreateFormParams {
|
|
||||||
workflowId: string
|
|
||||||
identifier: string
|
|
||||||
title: string
|
|
||||||
description?: string
|
|
||||||
customizations?: {
|
|
||||||
primaryColor?: string
|
|
||||||
welcomeMessage?: string
|
|
||||||
thankYouTitle?: string
|
|
||||||
thankYouMessage?: string
|
|
||||||
logoUrl?: string
|
|
||||||
}
|
|
||||||
authType?: 'public' | 'password' | 'email'
|
|
||||||
password?: string
|
|
||||||
allowedEmails?: string[]
|
|
||||||
showBranding?: boolean
|
|
||||||
}
|
|
||||||
|
|
||||||
interface UpdateFormParams {
|
|
||||||
identifier?: string
|
|
||||||
title?: string
|
|
||||||
description?: string
|
|
||||||
customizations?: {
|
|
||||||
primaryColor?: string
|
|
||||||
welcomeMessage?: string
|
|
||||||
thankYouTitle?: string
|
|
||||||
thankYouMessage?: string
|
|
||||||
logoUrl?: string
|
|
||||||
}
|
|
||||||
authType?: 'public' | 'password' | 'email'
|
|
||||||
password?: string
|
|
||||||
allowedEmails?: string[]
|
|
||||||
showBranding?: boolean
|
|
||||||
isActive?: boolean
|
|
||||||
}
|
|
||||||
|
|
||||||
interface CreateFormResult {
|
|
||||||
id: string
|
|
||||||
formUrl: string
|
|
||||||
}
|
|
||||||
|
|
||||||
export function useFormDeployment() {
|
|
||||||
const [isSubmitting, setIsSubmitting] = useState(false)
|
|
||||||
const [error, setError] = useState<string | null>(null)
|
|
||||||
|
|
||||||
const createForm = useCallback(
|
|
||||||
async (params: CreateFormParams): Promise<CreateFormResult | null> => {
|
|
||||||
setIsSubmitting(true)
|
|
||||||
setError(null)
|
|
||||||
|
|
||||||
try {
|
|
||||||
const response = await fetch('/api/form', {
|
|
||||||
method: 'POST',
|
|
||||||
headers: {
|
|
||||||
'Content-Type': 'application/json',
|
|
||||||
},
|
|
||||||
body: JSON.stringify(params),
|
|
||||||
})
|
|
||||||
|
|
||||||
const data = await response.json()
|
|
||||||
|
|
||||||
if (!response.ok) {
|
|
||||||
throw new Error(data.error || 'Failed to create form')
|
|
||||||
}
|
|
||||||
|
|
||||||
logger.info('Form created successfully:', { id: data.id })
|
|
||||||
return {
|
|
||||||
id: data.id,
|
|
||||||
formUrl: data.formUrl,
|
|
||||||
}
|
|
||||||
} catch (err: any) {
|
|
||||||
const errorMessage = err.message || 'Failed to create form'
|
|
||||||
setError(errorMessage)
|
|
||||||
logger.error('Error creating form:', err)
|
|
||||||
throw err
|
|
||||||
} finally {
|
|
||||||
setIsSubmitting(false)
|
|
||||||
}
|
|
||||||
},
|
|
||||||
[]
|
|
||||||
)
|
|
||||||
|
|
||||||
const updateForm = useCallback(async (formId: string, params: UpdateFormParams) => {
|
|
||||||
setIsSubmitting(true)
|
|
||||||
setError(null)
|
|
||||||
|
|
||||||
try {
|
|
||||||
const response = await fetch(`/api/form/manage/${formId}`, {
|
|
||||||
method: 'PATCH',
|
|
||||||
headers: {
|
|
||||||
'Content-Type': 'application/json',
|
|
||||||
},
|
|
||||||
body: JSON.stringify(params),
|
|
||||||
})
|
|
||||||
|
|
||||||
const data = await response.json()
|
|
||||||
|
|
||||||
if (!response.ok) {
|
|
||||||
throw new Error(data.error || 'Failed to update form')
|
|
||||||
}
|
|
||||||
|
|
||||||
logger.info('Form updated successfully:', { id: formId })
|
|
||||||
} catch (err: any) {
|
|
||||||
const errorMessage = err.message || 'Failed to update form'
|
|
||||||
setError(errorMessage)
|
|
||||||
logger.error('Error updating form:', err)
|
|
||||||
throw err
|
|
||||||
} finally {
|
|
||||||
setIsSubmitting(false)
|
|
||||||
}
|
|
||||||
}, [])
|
|
||||||
|
|
||||||
const deleteForm = useCallback(async (formId: string) => {
|
|
||||||
setIsSubmitting(true)
|
|
||||||
setError(null)
|
|
||||||
|
|
||||||
try {
|
|
||||||
const response = await fetch(`/api/form/manage/${formId}`, {
|
|
||||||
method: 'DELETE',
|
|
||||||
})
|
|
||||||
|
|
||||||
const data = await response.json()
|
|
||||||
|
|
||||||
if (!response.ok) {
|
|
||||||
throw new Error(data.error || 'Failed to delete form')
|
|
||||||
}
|
|
||||||
|
|
||||||
logger.info('Form deleted successfully:', { id: formId })
|
|
||||||
} catch (err: any) {
|
|
||||||
const errorMessage = err.message || 'Failed to delete form'
|
|
||||||
setError(errorMessage)
|
|
||||||
logger.error('Error deleting form:', err)
|
|
||||||
throw err
|
|
||||||
} finally {
|
|
||||||
setIsSubmitting(false)
|
|
||||||
}
|
|
||||||
}, [])
|
|
||||||
|
|
||||||
return {
|
|
||||||
createForm,
|
|
||||||
updateForm,
|
|
||||||
deleteForm,
|
|
||||||
isSubmitting,
|
|
||||||
error,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -15,7 +15,7 @@ import {
|
|||||||
import { Skeleton } from '@/components/ui'
|
import { Skeleton } from '@/components/ui'
|
||||||
import { generateToolInputSchema, sanitizeToolName } from '@/lib/mcp/workflow-tool-schema'
|
import { generateToolInputSchema, sanitizeToolName } from '@/lib/mcp/workflow-tool-schema'
|
||||||
import { normalizeInputFormatValue } from '@/lib/workflows/input-format'
|
import { normalizeInputFormatValue } from '@/lib/workflows/input-format'
|
||||||
import { isValidStartBlockType } from '@/lib/workflows/triggers/trigger-utils'
|
import { isValidStartBlockType } from '@/lib/workflows/triggers/start-block-types'
|
||||||
import type { InputFormatField } from '@/lib/workflows/types'
|
import type { InputFormatField } from '@/lib/workflows/types'
|
||||||
import {
|
import {
|
||||||
useAddWorkflowMcpTool,
|
useAddWorkflowMcpTool,
|
||||||
@@ -43,7 +43,6 @@ interface McpDeployProps {
|
|||||||
onAddedToServer?: () => void
|
onAddedToServer?: () => void
|
||||||
onSubmittingChange?: (submitting: boolean) => void
|
onSubmittingChange?: (submitting: boolean) => void
|
||||||
onCanSaveChange?: (canSave: boolean) => void
|
onCanSaveChange?: (canSave: boolean) => void
|
||||||
onHasServersChange?: (hasServers: boolean) => void
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -92,7 +91,6 @@ export function McpDeploy({
|
|||||||
onAddedToServer,
|
onAddedToServer,
|
||||||
onSubmittingChange,
|
onSubmittingChange,
|
||||||
onCanSaveChange,
|
onCanSaveChange,
|
||||||
onHasServersChange,
|
|
||||||
}: McpDeployProps) {
|
}: McpDeployProps) {
|
||||||
const params = useParams()
|
const params = useParams()
|
||||||
const workspaceId = params.workspaceId as string
|
const workspaceId = params.workspaceId as string
|
||||||
@@ -257,10 +255,6 @@ export function McpDeploy({
|
|||||||
onCanSaveChange?.(hasChanges && hasDeployedTools && !!toolName.trim())
|
onCanSaveChange?.(hasChanges && hasDeployedTools && !!toolName.trim())
|
||||||
}, [hasChanges, hasDeployedTools, toolName, onCanSaveChange])
|
}, [hasChanges, hasDeployedTools, toolName, onCanSaveChange])
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
onHasServersChange?.(servers.length > 0)
|
|
||||||
}, [servers.length, onHasServersChange])
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Save tool configuration to all deployed servers
|
* Save tool configuration to all deployed servers
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ import { useSession } from '@/lib/auth/auth-client'
|
|||||||
import { cn } from '@/lib/core/utils/cn'
|
import { cn } from '@/lib/core/utils/cn'
|
||||||
import { captureAndUploadOGImage, OG_IMAGE_HEIGHT, OG_IMAGE_WIDTH } from '@/lib/og'
|
import { captureAndUploadOGImage, OG_IMAGE_HEIGHT, OG_IMAGE_WIDTH } from '@/lib/og'
|
||||||
import { WorkflowPreview } from '@/app/workspace/[workspaceId]/w/components/preview'
|
import { WorkflowPreview } from '@/app/workspace/[workspaceId]/w/components/preview'
|
||||||
|
import { useCreatorProfiles } from '@/hooks/queries/creator-profile'
|
||||||
import {
|
import {
|
||||||
useCreateTemplate,
|
useCreateTemplate,
|
||||||
useDeleteTemplate,
|
useDeleteTemplate,
|
||||||
@@ -47,26 +48,11 @@ const initialFormData: TemplateFormData = {
|
|||||||
tags: [],
|
tags: [],
|
||||||
}
|
}
|
||||||
|
|
||||||
interface CreatorOption {
|
|
||||||
id: string
|
|
||||||
name: string
|
|
||||||
referenceType: 'user' | 'organization'
|
|
||||||
referenceId: string
|
|
||||||
}
|
|
||||||
|
|
||||||
interface TemplateStatus {
|
|
||||||
status: 'pending' | 'approved' | 'rejected' | null
|
|
||||||
views?: number
|
|
||||||
stars?: number
|
|
||||||
}
|
|
||||||
|
|
||||||
interface TemplateDeployProps {
|
interface TemplateDeployProps {
|
||||||
workflowId: string
|
workflowId: string
|
||||||
onDeploymentComplete?: () => void
|
onDeploymentComplete?: () => void
|
||||||
onValidationChange?: (isValid: boolean) => void
|
onValidationChange?: (isValid: boolean) => void
|
||||||
onSubmittingChange?: (isSubmitting: boolean) => void
|
onSubmittingChange?: (isSubmitting: boolean) => void
|
||||||
onExistingTemplateChange?: (exists: boolean) => void
|
|
||||||
onTemplateStatusChange?: (status: TemplateStatus | null) => void
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function TemplateDeploy({
|
export function TemplateDeploy({
|
||||||
@@ -74,13 +60,9 @@ export function TemplateDeploy({
|
|||||||
onDeploymentComplete,
|
onDeploymentComplete,
|
||||||
onValidationChange,
|
onValidationChange,
|
||||||
onSubmittingChange,
|
onSubmittingChange,
|
||||||
onExistingTemplateChange,
|
|
||||||
onTemplateStatusChange,
|
|
||||||
}: TemplateDeployProps) {
|
}: TemplateDeployProps) {
|
||||||
const { data: session } = useSession()
|
const { data: session } = useSession()
|
||||||
const [showDeleteDialog, setShowDeleteDialog] = useState(false)
|
const [showDeleteDialog, setShowDeleteDialog] = useState(false)
|
||||||
const [creatorOptions, setCreatorOptions] = useState<CreatorOption[]>([])
|
|
||||||
const [loadingCreators, setLoadingCreators] = useState(false)
|
|
||||||
const [isCapturing, setIsCapturing] = useState(false)
|
const [isCapturing, setIsCapturing] = useState(false)
|
||||||
const previewContainerRef = useRef<HTMLDivElement>(null)
|
const previewContainerRef = useRef<HTMLDivElement>(null)
|
||||||
const ogCaptureRef = useRef<HTMLDivElement>(null)
|
const ogCaptureRef = useRef<HTMLDivElement>(null)
|
||||||
@@ -88,6 +70,7 @@ export function TemplateDeploy({
|
|||||||
const [formData, setFormData] = useState<TemplateFormData>(initialFormData)
|
const [formData, setFormData] = useState<TemplateFormData>(initialFormData)
|
||||||
|
|
||||||
const { data: existingTemplate, isLoading: isLoadingTemplate } = useTemplateByWorkflow(workflowId)
|
const { data: existingTemplate, isLoading: isLoadingTemplate } = useTemplateByWorkflow(workflowId)
|
||||||
|
const { data: creatorProfiles = [], isLoading: loadingCreators } = useCreatorProfiles()
|
||||||
const createMutation = useCreateTemplate()
|
const createMutation = useCreateTemplate()
|
||||||
const updateMutation = useUpdateTemplate()
|
const updateMutation = useUpdateTemplate()
|
||||||
const deleteMutation = useDeleteTemplate()
|
const deleteMutation = useDeleteTemplate()
|
||||||
@@ -112,63 +95,15 @@ export function TemplateDeploy({
|
|||||||
}, [isSubmitting, onSubmittingChange])
|
}, [isSubmitting, onSubmittingChange])
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
onExistingTemplateChange?.(!!existingTemplate)
|
if (creatorProfiles.length === 1 && !formData.creatorId) {
|
||||||
}, [existingTemplate, onExistingTemplateChange])
|
updateField('creatorId', creatorProfiles[0].id)
|
||||||
|
logger.info('Auto-selected single creator profile:', creatorProfiles[0].name)
|
||||||
useEffect(() => {
|
|
||||||
if (existingTemplate) {
|
|
||||||
onTemplateStatusChange?.({
|
|
||||||
status: existingTemplate.status as 'pending' | 'approved' | 'rejected',
|
|
||||||
views: existingTemplate.views,
|
|
||||||
stars: existingTemplate.stars,
|
|
||||||
})
|
|
||||||
} else {
|
|
||||||
onTemplateStatusChange?.(null)
|
|
||||||
}
|
}
|
||||||
}, [existingTemplate, onTemplateStatusChange])
|
}, [creatorProfiles, formData.creatorId])
|
||||||
|
|
||||||
const fetchCreatorOptions = async () => {
|
|
||||||
if (!session?.user?.id) return
|
|
||||||
|
|
||||||
setLoadingCreators(true)
|
|
||||||
try {
|
|
||||||
const response = await fetch('/api/creators')
|
|
||||||
if (response.ok) {
|
|
||||||
const data = await response.json()
|
|
||||||
const profiles = (data.profiles || []).map((profile: any) => ({
|
|
||||||
id: profile.id,
|
|
||||||
name: profile.name,
|
|
||||||
referenceType: profile.referenceType,
|
|
||||||
referenceId: profile.referenceId,
|
|
||||||
}))
|
|
||||||
setCreatorOptions(profiles)
|
|
||||||
return profiles
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
logger.error('Error fetching creator profiles:', error)
|
|
||||||
} finally {
|
|
||||||
setLoadingCreators(false)
|
|
||||||
}
|
|
||||||
return []
|
|
||||||
}
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
fetchCreatorOptions()
|
const handleCreatorProfileSaved = () => {
|
||||||
}, [session?.user?.id])
|
logger.info('Creator profile saved, reopening deploy modal...')
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
if (creatorOptions.length === 1 && !formData.creatorId) {
|
|
||||||
updateField('creatorId', creatorOptions[0].id)
|
|
||||||
logger.info('Auto-selected single creator profile:', creatorOptions[0].name)
|
|
||||||
}
|
|
||||||
}, [creatorOptions, formData.creatorId])
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
const handleCreatorProfileSaved = async () => {
|
|
||||||
logger.info('Creator profile saved, refreshing profiles...')
|
|
||||||
|
|
||||||
await fetchCreatorOptions()
|
|
||||||
|
|
||||||
window.dispatchEvent(new CustomEvent('close-settings'))
|
window.dispatchEvent(new CustomEvent('close-settings'))
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
window.dispatchEvent(new CustomEvent('open-deploy-modal', { detail: { tab: 'template' } }))
|
window.dispatchEvent(new CustomEvent('open-deploy-modal', { detail: { tab: 'template' } }))
|
||||||
@@ -357,7 +292,7 @@ export function TemplateDeploy({
|
|||||||
<Label className='mb-[6.5px] block pl-[2px] font-medium text-[13px] text-[var(--text-primary)]'>
|
<Label className='mb-[6.5px] block pl-[2px] font-medium text-[13px] text-[var(--text-primary)]'>
|
||||||
Creator <span className='text-[var(--text-error)]'>*</span>
|
Creator <span className='text-[var(--text-error)]'>*</span>
|
||||||
</Label>
|
</Label>
|
||||||
{creatorOptions.length === 0 && !loadingCreators ? (
|
{creatorProfiles.length === 0 && !loadingCreators ? (
|
||||||
<div className='space-y-[8px]'>
|
<div className='space-y-[8px]'>
|
||||||
<p className='text-[12px] text-[var(--text-tertiary)]'>
|
<p className='text-[12px] text-[var(--text-tertiary)]'>
|
||||||
A creator profile is required to publish templates.
|
A creator profile is required to publish templates.
|
||||||
@@ -385,9 +320,9 @@ export function TemplateDeploy({
|
|||||||
</div>
|
</div>
|
||||||
) : (
|
) : (
|
||||||
<Combobox
|
<Combobox
|
||||||
options={creatorOptions.map((option) => ({
|
options={creatorProfiles.map((profile) => ({
|
||||||
label: option.name,
|
label: profile.name,
|
||||||
value: option.id,
|
value: profile.id,
|
||||||
}))}
|
}))}
|
||||||
value={formData.creatorId}
|
value={formData.creatorId}
|
||||||
selectedValue={formData.creatorId}
|
selectedValue={formData.creatorId}
|
||||||
@@ -440,8 +375,11 @@ export function TemplateDeploy({
|
|||||||
<ModalHeader>Delete Template</ModalHeader>
|
<ModalHeader>Delete Template</ModalHeader>
|
||||||
<ModalBody>
|
<ModalBody>
|
||||||
<p className='text-[12px] text-[var(--text-secondary)]'>
|
<p className='text-[12px] text-[var(--text-secondary)]'>
|
||||||
Are you sure you want to delete this template?{' '}
|
Are you sure you want to delete{' '}
|
||||||
<span className='text-[var(--text-error)]'>This action cannot be undone.</span>
|
<span className='font-medium text-[var(--text-primary)]'>
|
||||||
|
{existingTemplate?.name || formData.name || 'this template'}
|
||||||
|
</span>
|
||||||
|
? <span className='text-[var(--text-error)]'>This action cannot be undone.</span>
|
||||||
</p>
|
</p>
|
||||||
</ModalBody>
|
</ModalBody>
|
||||||
<ModalFooter>
|
<ModalFooter>
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
'use client'
|
'use client'
|
||||||
|
|
||||||
import { useCallback, useEffect, useState } from 'react'
|
import { useCallback, useEffect, useMemo, useState } from 'react'
|
||||||
import { createLogger } from '@sim/logger'
|
import { createLogger } from '@sim/logger'
|
||||||
|
import { useQueryClient } from '@tanstack/react-query'
|
||||||
import {
|
import {
|
||||||
Badge,
|
Badge,
|
||||||
Button,
|
Button,
|
||||||
@@ -17,11 +18,22 @@ import {
|
|||||||
} from '@/components/emcn'
|
} from '@/components/emcn'
|
||||||
import { getBaseUrl } from '@/lib/core/utils/urls'
|
import { getBaseUrl } from '@/lib/core/utils/urls'
|
||||||
import { getInputFormatExample as getInputFormatExampleUtil } from '@/lib/workflows/operations/deployment-utils'
|
import { getInputFormatExample as getInputFormatExampleUtil } from '@/lib/workflows/operations/deployment-utils'
|
||||||
import type { WorkflowDeploymentVersionResponse } from '@/lib/workflows/persistence/utils'
|
|
||||||
import { useUserPermissionsContext } from '@/app/workspace/[workspaceId]/providers/workspace-permissions-provider'
|
import { useUserPermissionsContext } from '@/app/workspace/[workspaceId]/providers/workspace-permissions-provider'
|
||||||
import { CreateApiKeyModal } from '@/app/workspace/[workspaceId]/w/components/sidebar/components/settings-modal/components/api-keys/components'
|
import { CreateApiKeyModal } from '@/app/workspace/[workspaceId]/w/components/sidebar/components/settings-modal/components/api-keys/components'
|
||||||
import { startsWithUuid } from '@/executor/constants'
|
import { startsWithUuid } from '@/executor/constants'
|
||||||
|
import { useA2AAgentByWorkflow } from '@/hooks/queries/a2a/agents'
|
||||||
import { useApiKeys } from '@/hooks/queries/api-keys'
|
import { useApiKeys } from '@/hooks/queries/api-keys'
|
||||||
|
import {
|
||||||
|
deploymentKeys,
|
||||||
|
useActivateDeploymentVersion,
|
||||||
|
useChatDeploymentInfo,
|
||||||
|
useDeploymentInfo,
|
||||||
|
useDeploymentVersions,
|
||||||
|
useDeployWorkflow,
|
||||||
|
useUndeployWorkflow,
|
||||||
|
} from '@/hooks/queries/deployments'
|
||||||
|
import { useTemplateByWorkflow } from '@/hooks/queries/templates'
|
||||||
|
import { useWorkflowMcpServers } from '@/hooks/queries/workflow-mcp-servers'
|
||||||
import { useWorkspaceSettings } from '@/hooks/queries/workspace'
|
import { useWorkspaceSettings } from '@/hooks/queries/workspace'
|
||||||
import { usePermissionConfig } from '@/hooks/use-permission-config'
|
import { usePermissionConfig } from '@/hooks/use-permission-config'
|
||||||
import { useSettingsModalStore } from '@/stores/modals/settings/store'
|
import { useSettingsModalStore } from '@/stores/modals/settings/store'
|
||||||
@@ -48,7 +60,7 @@ interface DeployModalProps {
|
|||||||
refetchDeployedState: () => Promise<void>
|
refetchDeployedState: () => Promise<void>
|
||||||
}
|
}
|
||||||
|
|
||||||
interface WorkflowDeploymentInfo {
|
interface WorkflowDeploymentInfoUI {
|
||||||
isDeployed: boolean
|
isDeployed: boolean
|
||||||
deployedAt?: string
|
deployedAt?: string
|
||||||
apiKey: string
|
apiKey: string
|
||||||
@@ -69,16 +81,12 @@ export function DeployModal({
|
|||||||
isLoadingDeployedState,
|
isLoadingDeployedState,
|
||||||
refetchDeployedState,
|
refetchDeployedState,
|
||||||
}: DeployModalProps) {
|
}: DeployModalProps) {
|
||||||
|
const queryClient = useQueryClient()
|
||||||
const openSettingsModal = useSettingsModalStore((state) => state.openModal)
|
const openSettingsModal = useSettingsModalStore((state) => state.openModal)
|
||||||
const deploymentStatus = useWorkflowRegistry((state) =>
|
const deploymentStatus = useWorkflowRegistry((state) =>
|
||||||
state.getWorkflowDeploymentStatus(workflowId)
|
state.getWorkflowDeploymentStatus(workflowId)
|
||||||
)
|
)
|
||||||
const isDeployed = deploymentStatus?.isDeployed ?? isDeployedProp
|
const isDeployed = deploymentStatus?.isDeployed ?? isDeployedProp
|
||||||
const setDeploymentStatus = useWorkflowRegistry((state) => state.setDeploymentStatus)
|
|
||||||
const [isSubmitting, setIsSubmitting] = useState(false)
|
|
||||||
const [isUndeploying, setIsUndeploying] = useState(false)
|
|
||||||
const [deploymentInfo, setDeploymentInfo] = useState<WorkflowDeploymentInfo | null>(null)
|
|
||||||
const [isLoading, setIsLoading] = useState(false)
|
|
||||||
const workflowMetadata = useWorkflowRegistry((state) =>
|
const workflowMetadata = useWorkflowRegistry((state) =>
|
||||||
workflowId ? state.workflows[workflowId] : undefined
|
workflowId ? state.workflows[workflowId] : undefined
|
||||||
)
|
)
|
||||||
@@ -86,33 +94,18 @@ export function DeployModal({
|
|||||||
const [activeTab, setActiveTab] = useState<TabView>('general')
|
const [activeTab, setActiveTab] = useState<TabView>('general')
|
||||||
const [chatSubmitting, setChatSubmitting] = useState(false)
|
const [chatSubmitting, setChatSubmitting] = useState(false)
|
||||||
const [apiDeployError, setApiDeployError] = useState<string | null>(null)
|
const [apiDeployError, setApiDeployError] = useState<string | null>(null)
|
||||||
const [chatExists, setChatExists] = useState(false)
|
|
||||||
const [isChatFormValid, setIsChatFormValid] = useState(false)
|
const [isChatFormValid, setIsChatFormValid] = useState(false)
|
||||||
const [selectedStreamingOutputs, setSelectedStreamingOutputs] = useState<string[]>([])
|
const [selectedStreamingOutputs, setSelectedStreamingOutputs] = useState<string[]>([])
|
||||||
|
|
||||||
const [versions, setVersions] = useState<WorkflowDeploymentVersionResponse[]>([])
|
|
||||||
const [versionsLoading, setVersionsLoading] = useState(false)
|
|
||||||
const [showUndeployConfirm, setShowUndeployConfirm] = useState(false)
|
const [showUndeployConfirm, setShowUndeployConfirm] = useState(false)
|
||||||
const [templateFormValid, setTemplateFormValid] = useState(false)
|
const [templateFormValid, setTemplateFormValid] = useState(false)
|
||||||
const [templateSubmitting, setTemplateSubmitting] = useState(false)
|
const [templateSubmitting, setTemplateSubmitting] = useState(false)
|
||||||
const [mcpToolSubmitting, setMcpToolSubmitting] = useState(false)
|
const [mcpToolSubmitting, setMcpToolSubmitting] = useState(false)
|
||||||
const [mcpToolCanSave, setMcpToolCanSave] = useState(false)
|
const [mcpToolCanSave, setMcpToolCanSave] = useState(false)
|
||||||
const [hasMcpServers, setHasMcpServers] = useState(false)
|
|
||||||
const [a2aSubmitting, setA2aSubmitting] = useState(false)
|
const [a2aSubmitting, setA2aSubmitting] = useState(false)
|
||||||
const [a2aCanSave, setA2aCanSave] = useState(false)
|
const [a2aCanSave, setA2aCanSave] = useState(false)
|
||||||
const [hasA2aAgent, setHasA2aAgent] = useState(false)
|
|
||||||
const [isA2aPublished, setIsA2aPublished] = useState(false)
|
|
||||||
const [a2aNeedsRepublish, setA2aNeedsRepublish] = useState(false)
|
const [a2aNeedsRepublish, setA2aNeedsRepublish] = useState(false)
|
||||||
const [showA2aDeleteConfirm, setShowA2aDeleteConfirm] = useState(false)
|
const [showA2aDeleteConfirm, setShowA2aDeleteConfirm] = useState(false)
|
||||||
const [hasExistingTemplate, setHasExistingTemplate] = useState(false)
|
|
||||||
const [templateStatus, setTemplateStatus] = useState<{
|
|
||||||
status: 'pending' | 'approved' | 'rejected' | null
|
|
||||||
views?: number
|
|
||||||
stars?: number
|
|
||||||
} | null>(null)
|
|
||||||
|
|
||||||
const [existingChat, setExistingChat] = useState<ExistingChat | null>(null)
|
|
||||||
const [isLoadingChat, setIsLoadingChat] = useState(false)
|
|
||||||
|
|
||||||
const [chatSuccess, setChatSuccess] = useState(false)
|
const [chatSuccess, setChatSuccess] = useState(false)
|
||||||
|
|
||||||
@@ -133,193 +126,107 @@ export function DeployModal({
|
|||||||
const createButtonDisabled =
|
const createButtonDisabled =
|
||||||
isApiKeysLoading || (!allowPersonalApiKeys && !canManageWorkspaceKeys)
|
isApiKeysLoading || (!allowPersonalApiKeys && !canManageWorkspaceKeys)
|
||||||
|
|
||||||
const getApiKeyLabel = (value?: string | null) => {
|
const {
|
||||||
if (value && value.trim().length > 0) {
|
data: deploymentInfoData,
|
||||||
return value
|
isLoading: isLoadingDeploymentInfo,
|
||||||
}
|
refetch: refetchDeploymentInfo,
|
||||||
return workflowWorkspaceId ? 'Workspace API keys' : 'Personal API keys'
|
} = useDeploymentInfo(workflowId, { enabled: open && isDeployed })
|
||||||
}
|
|
||||||
|
|
||||||
const getApiHeaderPlaceholder = () =>
|
const {
|
||||||
workflowWorkspaceId ? 'YOUR_WORKSPACE_API_KEY' : 'YOUR_PERSONAL_API_KEY'
|
data: versionsData,
|
||||||
|
isLoading: versionsLoading,
|
||||||
|
refetch: refetchVersions,
|
||||||
|
} = useDeploymentVersions(workflowId, { enabled: open })
|
||||||
|
|
||||||
const getInputFormatExample = (includeStreaming = false) => {
|
const {
|
||||||
return getInputFormatExampleUtil(includeStreaming, selectedStreamingOutputs)
|
isLoading: isLoadingChat,
|
||||||
}
|
chatExists,
|
||||||
|
existingChat,
|
||||||
|
refetch: refetchChatInfo,
|
||||||
|
} = useChatDeploymentInfo(workflowId, { enabled: open })
|
||||||
|
|
||||||
const fetchChatDeploymentInfo = useCallback(async () => {
|
const { data: mcpServers = [] } = useWorkflowMcpServers(workflowWorkspaceId || '')
|
||||||
if (!workflowId) return
|
const hasMcpServers = mcpServers.length > 0
|
||||||
|
|
||||||
try {
|
const { data: existingA2aAgent } = useA2AAgentByWorkflow(
|
||||||
setIsLoadingChat(true)
|
workflowWorkspaceId || '',
|
||||||
const response = await fetch(`/api/workflows/${workflowId}/chat/status`)
|
workflowId || ''
|
||||||
|
)
|
||||||
|
const hasA2aAgent = !!existingA2aAgent
|
||||||
|
const isA2aPublished = existingA2aAgent?.isPublished ?? false
|
||||||
|
|
||||||
if (response.ok) {
|
const { data: existingTemplate } = useTemplateByWorkflow(workflowId || '', {
|
||||||
const data = await response.json()
|
enabled: !!workflowId,
|
||||||
if (data.isDeployed && data.deployment) {
|
})
|
||||||
const detailResponse = await fetch(`/api/chat/manage/${data.deployment.id}`)
|
const hasExistingTemplate = !!existingTemplate
|
||||||
if (detailResponse.ok) {
|
const templateStatus = existingTemplate
|
||||||
const chatDetail = await detailResponse.json()
|
? {
|
||||||
setExistingChat(chatDetail)
|
status: existingTemplate.status as 'pending' | 'approved' | 'rejected' | null,
|
||||||
setChatExists(true)
|
views: existingTemplate.views,
|
||||||
} else {
|
stars: existingTemplate.stars,
|
||||||
setExistingChat(null)
|
|
||||||
setChatExists(false)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
setExistingChat(null)
|
|
||||||
setChatExists(false)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
setExistingChat(null)
|
|
||||||
setChatExists(false)
|
|
||||||
}
|
}
|
||||||
} catch (error) {
|
: null
|
||||||
logger.error('Error fetching chat deployment info:', { error })
|
|
||||||
setExistingChat(null)
|
const deployMutation = useDeployWorkflow()
|
||||||
setChatExists(false)
|
const undeployMutation = useUndeployWorkflow()
|
||||||
} finally {
|
const activateVersionMutation = useActivateDeploymentVersion()
|
||||||
setIsLoadingChat(false)
|
|
||||||
|
const versions = versionsData?.versions ?? []
|
||||||
|
|
||||||
|
const getApiKeyLabel = useCallback(
|
||||||
|
(value?: string | null) => {
|
||||||
|
if (value && value.trim().length > 0) {
|
||||||
|
return value
|
||||||
|
}
|
||||||
|
return workflowWorkspaceId ? 'Workspace API keys' : 'Personal API keys'
|
||||||
|
},
|
||||||
|
[workflowWorkspaceId]
|
||||||
|
)
|
||||||
|
|
||||||
|
const getApiHeaderPlaceholder = useCallback(
|
||||||
|
() => (workflowWorkspaceId ? 'YOUR_WORKSPACE_API_KEY' : 'YOUR_PERSONAL_API_KEY'),
|
||||||
|
[workflowWorkspaceId]
|
||||||
|
)
|
||||||
|
|
||||||
|
const getInputFormatExample = useCallback(
|
||||||
|
(includeStreaming = false) => {
|
||||||
|
return getInputFormatExampleUtil(includeStreaming, selectedStreamingOutputs)
|
||||||
|
},
|
||||||
|
[selectedStreamingOutputs]
|
||||||
|
)
|
||||||
|
|
||||||
|
const deploymentInfo: WorkflowDeploymentInfoUI | null = useMemo(() => {
|
||||||
|
if (!deploymentInfoData?.isDeployed || !workflowId) {
|
||||||
|
return null
|
||||||
}
|
}
|
||||||
}, [workflowId])
|
|
||||||
|
const endpoint = `${getBaseUrl()}/api/workflows/${workflowId}/execute`
|
||||||
|
const inputFormatExample = getInputFormatExample(selectedStreamingOutputs.length > 0)
|
||||||
|
const placeholderKey = getApiHeaderPlaceholder()
|
||||||
|
|
||||||
|
return {
|
||||||
|
isDeployed: deploymentInfoData.isDeployed,
|
||||||
|
deployedAt: deploymentInfoData.deployedAt ?? undefined,
|
||||||
|
apiKey: getApiKeyLabel(deploymentInfoData.apiKey),
|
||||||
|
endpoint,
|
||||||
|
exampleCommand: `curl -X POST -H "X-API-Key: ${placeholderKey}" -H "Content-Type: application/json"${inputFormatExample} ${endpoint}`,
|
||||||
|
needsRedeployment: deploymentInfoData.needsRedeployment,
|
||||||
|
}
|
||||||
|
}, [
|
||||||
|
deploymentInfoData,
|
||||||
|
workflowId,
|
||||||
|
selectedStreamingOutputs,
|
||||||
|
getInputFormatExample,
|
||||||
|
getApiHeaderPlaceholder,
|
||||||
|
getApiKeyLabel,
|
||||||
|
])
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (open && workflowId) {
|
if (open && workflowId) {
|
||||||
setActiveTab('general')
|
setActiveTab('general')
|
||||||
setApiDeployError(null)
|
setApiDeployError(null)
|
||||||
fetchChatDeploymentInfo()
|
|
||||||
}
|
}
|
||||||
}, [open, workflowId, fetchChatDeploymentInfo])
|
}, [open, workflowId])
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
async function fetchDeploymentInfo() {
|
|
||||||
if (!open || !workflowId || !isDeployed) {
|
|
||||||
setDeploymentInfo(null)
|
|
||||||
setIsLoading(false)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if (deploymentInfo?.isDeployed && !needsRedeployment) {
|
|
||||||
setIsLoading(false)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
setIsLoading(true)
|
|
||||||
|
|
||||||
const response = await fetch(`/api/workflows/${workflowId}/deploy`)
|
|
||||||
|
|
||||||
if (!response.ok) {
|
|
||||||
throw new Error('Failed to fetch deployment information')
|
|
||||||
}
|
|
||||||
|
|
||||||
const data = await response.json()
|
|
||||||
const endpoint = `${getBaseUrl()}/api/workflows/${workflowId}/execute`
|
|
||||||
const inputFormatExample = getInputFormatExample(selectedStreamingOutputs.length > 0)
|
|
||||||
const placeholderKey = workflowWorkspaceId ? 'YOUR_WORKSPACE_API_KEY' : 'YOUR_API_KEY'
|
|
||||||
|
|
||||||
setDeploymentInfo({
|
|
||||||
isDeployed: data.isDeployed,
|
|
||||||
deployedAt: data.deployedAt,
|
|
||||||
apiKey: data.apiKey || placeholderKey,
|
|
||||||
endpoint,
|
|
||||||
exampleCommand: `curl -X POST -H "X-API-Key: ${placeholderKey}" -H "Content-Type: application/json"${inputFormatExample} ${endpoint}`,
|
|
||||||
needsRedeployment,
|
|
||||||
})
|
|
||||||
} catch (error) {
|
|
||||||
logger.error('Error fetching deployment info:', { error })
|
|
||||||
} finally {
|
|
||||||
setIsLoading(false)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fetchDeploymentInfo()
|
|
||||||
}, [open, workflowId, isDeployed, needsRedeployment, deploymentInfo?.isDeployed])
|
|
||||||
|
|
||||||
const onDeploy = async () => {
|
|
||||||
setApiDeployError(null)
|
|
||||||
|
|
||||||
try {
|
|
||||||
setIsSubmitting(true)
|
|
||||||
|
|
||||||
const response = await fetch(`/api/workflows/${workflowId}/deploy`, {
|
|
||||||
method: 'POST',
|
|
||||||
headers: {
|
|
||||||
'Content-Type': 'application/json',
|
|
||||||
},
|
|
||||||
body: JSON.stringify({
|
|
||||||
deployChatEnabled: false,
|
|
||||||
}),
|
|
||||||
})
|
|
||||||
|
|
||||||
if (!response.ok) {
|
|
||||||
const errorData = await response.json()
|
|
||||||
throw new Error(errorData.error || 'Failed to deploy workflow')
|
|
||||||
}
|
|
||||||
|
|
||||||
const responseData = await response.json()
|
|
||||||
|
|
||||||
const isDeployedStatus = responseData.isDeployed ?? false
|
|
||||||
const deployedAtTime = responseData.deployedAt ? new Date(responseData.deployedAt) : undefined
|
|
||||||
const apiKeyLabel = getApiKeyLabel(responseData.apiKey)
|
|
||||||
|
|
||||||
setDeploymentStatus(workflowId, isDeployedStatus, deployedAtTime, apiKeyLabel)
|
|
||||||
|
|
||||||
if (workflowId) {
|
|
||||||
useWorkflowRegistry.getState().setWorkflowNeedsRedeployment(workflowId, false)
|
|
||||||
}
|
|
||||||
|
|
||||||
await refetchDeployedState()
|
|
||||||
await fetchVersions()
|
|
||||||
|
|
||||||
const deploymentInfoResponse = await fetch(`/api/workflows/${workflowId}/deploy`)
|
|
||||||
if (deploymentInfoResponse.ok) {
|
|
||||||
const deploymentData = await deploymentInfoResponse.json()
|
|
||||||
const apiEndpoint = `${getBaseUrl()}/api/workflows/${workflowId}/execute`
|
|
||||||
const inputFormatExample = getInputFormatExample(selectedStreamingOutputs.length > 0)
|
|
||||||
const placeholderKey = getApiHeaderPlaceholder()
|
|
||||||
|
|
||||||
setDeploymentInfo({
|
|
||||||
isDeployed: deploymentData.isDeployed,
|
|
||||||
deployedAt: deploymentData.deployedAt,
|
|
||||||
apiKey: getApiKeyLabel(deploymentData.apiKey),
|
|
||||||
endpoint: apiEndpoint,
|
|
||||||
exampleCommand: `curl -X POST -H "X-API-Key: ${placeholderKey}" -H "Content-Type: application/json"${inputFormatExample} ${apiEndpoint}`,
|
|
||||||
needsRedeployment: false,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
setApiDeployError(null)
|
|
||||||
} catch (error: unknown) {
|
|
||||||
logger.error('Error deploying workflow:', { error })
|
|
||||||
const errorMessage = error instanceof Error ? error.message : 'Failed to deploy workflow'
|
|
||||||
setApiDeployError(errorMessage)
|
|
||||||
} finally {
|
|
||||||
setIsSubmitting(false)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const fetchVersions = useCallback(async () => {
|
|
||||||
if (!workflowId) return
|
|
||||||
try {
|
|
||||||
const res = await fetch(`/api/workflows/${workflowId}/deployments`)
|
|
||||||
if (res.ok) {
|
|
||||||
const data = await res.json()
|
|
||||||
setVersions(Array.isArray(data.versions) ? data.versions : [])
|
|
||||||
} else {
|
|
||||||
setVersions([])
|
|
||||||
}
|
|
||||||
} catch {
|
|
||||||
setVersions([])
|
|
||||||
}
|
|
||||||
}, [workflowId])
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
if (open && workflowId) {
|
|
||||||
setVersionsLoading(true)
|
|
||||||
fetchVersions().finally(() => setVersionsLoading(false))
|
|
||||||
}
|
|
||||||
}, [open, workflowId, fetchVersions])
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!open || selectedStreamingOutputs.length === 0) return
|
if (!open || selectedStreamingOutputs.length === 0) return
|
||||||
@@ -369,181 +276,88 @@ export function DeployModal({
|
|||||||
}
|
}
|
||||||
}, [onOpenChange])
|
}, [onOpenChange])
|
||||||
|
|
||||||
|
const onDeploy = useCallback(async () => {
|
||||||
|
if (!workflowId) return
|
||||||
|
|
||||||
|
setApiDeployError(null)
|
||||||
|
|
||||||
|
try {
|
||||||
|
await deployMutation.mutateAsync({ workflowId, deployChatEnabled: false })
|
||||||
|
await refetchDeployedState()
|
||||||
|
} catch (error: unknown) {
|
||||||
|
logger.error('Error deploying workflow:', { error })
|
||||||
|
const errorMessage = error instanceof Error ? error.message : 'Failed to deploy workflow'
|
||||||
|
setApiDeployError(errorMessage)
|
||||||
|
}
|
||||||
|
}, [workflowId, deployMutation, refetchDeployedState])
|
||||||
|
|
||||||
const handlePromoteToLive = useCallback(
|
const handlePromoteToLive = useCallback(
|
||||||
async (version: number) => {
|
async (version: number) => {
|
||||||
if (!workflowId) return
|
if (!workflowId) return
|
||||||
|
|
||||||
const previousVersions = [...versions]
|
|
||||||
setVersions((prev) =>
|
|
||||||
prev.map((v) => ({
|
|
||||||
...v,
|
|
||||||
isActive: v.version === version,
|
|
||||||
}))
|
|
||||||
)
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await fetch(
|
await activateVersionMutation.mutateAsync({ workflowId, version })
|
||||||
`/api/workflows/${workflowId}/deployments/${version}/activate`,
|
await refetchDeployedState()
|
||||||
{
|
|
||||||
method: 'POST',
|
|
||||||
headers: {
|
|
||||||
'Content-Type': 'application/json',
|
|
||||||
},
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
if (!response.ok) {
|
|
||||||
const errorData = await response.json()
|
|
||||||
throw new Error(errorData.error || 'Failed to promote version')
|
|
||||||
}
|
|
||||||
|
|
||||||
const responseData = await response.json()
|
|
||||||
|
|
||||||
const deployedAtTime = responseData.deployedAt
|
|
||||||
? new Date(responseData.deployedAt)
|
|
||||||
: undefined
|
|
||||||
const apiKeyLabel = getApiKeyLabel(responseData.apiKey)
|
|
||||||
|
|
||||||
setDeploymentStatus(workflowId, true, deployedAtTime, apiKeyLabel)
|
|
||||||
|
|
||||||
refetchDeployedState()
|
|
||||||
fetchVersions()
|
|
||||||
|
|
||||||
const deploymentInfoResponse = await fetch(`/api/workflows/${workflowId}/deploy`)
|
|
||||||
if (deploymentInfoResponse.ok) {
|
|
||||||
const deploymentData = await deploymentInfoResponse.json()
|
|
||||||
const apiEndpoint = `${getBaseUrl()}/api/workflows/${workflowId}/execute`
|
|
||||||
const inputFormatExample = getInputFormatExample(selectedStreamingOutputs.length > 0)
|
|
||||||
const placeholderKey = getApiHeaderPlaceholder()
|
|
||||||
|
|
||||||
setDeploymentInfo({
|
|
||||||
isDeployed: deploymentData.isDeployed,
|
|
||||||
deployedAt: deploymentData.deployedAt,
|
|
||||||
apiKey: getApiKeyLabel(deploymentData.apiKey),
|
|
||||||
endpoint: apiEndpoint,
|
|
||||||
exampleCommand: `curl -X POST -H "X-API-Key: ${placeholderKey}" -H "Content-Type: application/json"${inputFormatExample} ${apiEndpoint}`,
|
|
||||||
needsRedeployment: false,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
setVersions(previousVersions)
|
logger.error('Error promoting version:', { error })
|
||||||
throw error
|
throw error
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
[workflowId, versions, refetchDeployedState, fetchVersions, selectedStreamingOutputs]
|
[workflowId, activateVersionMutation, refetchDeployedState]
|
||||||
)
|
)
|
||||||
|
|
||||||
const handleUndeploy = async () => {
|
const handleUndeploy = useCallback(async () => {
|
||||||
|
if (!workflowId) return
|
||||||
|
|
||||||
try {
|
try {
|
||||||
setIsUndeploying(true)
|
await undeployMutation.mutateAsync({ workflowId })
|
||||||
|
|
||||||
const response = await fetch(`/api/workflows/${workflowId}/deploy`, {
|
|
||||||
method: 'DELETE',
|
|
||||||
})
|
|
||||||
|
|
||||||
if (!response.ok) {
|
|
||||||
const errorData = await response.json()
|
|
||||||
throw new Error(errorData.error || 'Failed to undeploy workflow')
|
|
||||||
}
|
|
||||||
|
|
||||||
setDeploymentStatus(workflowId, false)
|
|
||||||
setChatExists(false)
|
|
||||||
setShowUndeployConfirm(false)
|
setShowUndeployConfirm(false)
|
||||||
onOpenChange(false)
|
onOpenChange(false)
|
||||||
} catch (error: unknown) {
|
} catch (error: unknown) {
|
||||||
logger.error('Error undeploying workflow:', { error })
|
logger.error('Error undeploying workflow:', { error })
|
||||||
} finally {
|
|
||||||
setIsUndeploying(false)
|
|
||||||
}
|
}
|
||||||
}
|
}, [workflowId, undeployMutation, onOpenChange])
|
||||||
|
|
||||||
|
const handleRedeploy = useCallback(async () => {
|
||||||
|
if (!workflowId) return
|
||||||
|
|
||||||
|
setApiDeployError(null)
|
||||||
|
|
||||||
const handleRedeploy = async () => {
|
|
||||||
try {
|
try {
|
||||||
setIsSubmitting(true)
|
await deployMutation.mutateAsync({ workflowId, deployChatEnabled: false })
|
||||||
|
|
||||||
const response = await fetch(`/api/workflows/${workflowId}/deploy`, {
|
|
||||||
method: 'POST',
|
|
||||||
headers: {
|
|
||||||
'Content-Type': 'application/json',
|
|
||||||
},
|
|
||||||
body: JSON.stringify({
|
|
||||||
deployChatEnabled: false,
|
|
||||||
}),
|
|
||||||
})
|
|
||||||
|
|
||||||
if (!response.ok) {
|
|
||||||
const errorData = await response.json()
|
|
||||||
throw new Error(errorData.error || 'Failed to redeploy workflow')
|
|
||||||
}
|
|
||||||
|
|
||||||
const { isDeployed: newDeployStatus, deployedAt, apiKey } = await response.json()
|
|
||||||
|
|
||||||
setDeploymentStatus(
|
|
||||||
workflowId,
|
|
||||||
newDeployStatus,
|
|
||||||
deployedAt ? new Date(deployedAt) : undefined,
|
|
||||||
getApiKeyLabel(apiKey)
|
|
||||||
)
|
|
||||||
|
|
||||||
if (workflowId) {
|
|
||||||
useWorkflowRegistry.getState().setWorkflowNeedsRedeployment(workflowId, false)
|
|
||||||
}
|
|
||||||
|
|
||||||
await refetchDeployedState()
|
await refetchDeployedState()
|
||||||
await fetchVersions()
|
|
||||||
|
|
||||||
setDeploymentInfo((prev) => (prev ? { ...prev, needsRedeployment: false } : prev))
|
|
||||||
} catch (error: unknown) {
|
} catch (error: unknown) {
|
||||||
logger.error('Error redeploying workflow:', { error })
|
logger.error('Error redeploying workflow:', { error })
|
||||||
const errorMessage = error instanceof Error ? error.message : 'Failed to redeploy workflow'
|
const errorMessage = error instanceof Error ? error.message : 'Failed to redeploy workflow'
|
||||||
setApiDeployError(errorMessage)
|
setApiDeployError(errorMessage)
|
||||||
} finally {
|
|
||||||
setIsSubmitting(false)
|
|
||||||
}
|
}
|
||||||
}
|
}, [workflowId, deployMutation, refetchDeployedState])
|
||||||
|
|
||||||
const handleCloseModal = () => {
|
const handleCloseModal = useCallback(() => {
|
||||||
setIsSubmitting(false)
|
|
||||||
setChatSubmitting(false)
|
setChatSubmitting(false)
|
||||||
setApiDeployError(null)
|
setApiDeployError(null)
|
||||||
onOpenChange(false)
|
onOpenChange(false)
|
||||||
}
|
}, [onOpenChange])
|
||||||
|
|
||||||
const handleChatDeployed = async () => {
|
const handleChatDeployed = useCallback(async () => {
|
||||||
await handlePostDeploymentUpdate()
|
|
||||||
setChatSuccess(true)
|
|
||||||
setTimeout(() => setChatSuccess(false), 2000)
|
|
||||||
}
|
|
||||||
|
|
||||||
const handlePostDeploymentUpdate = async () => {
|
|
||||||
if (!workflowId) return
|
if (!workflowId) return
|
||||||
|
|
||||||
setDeploymentStatus(workflowId, true, new Date(), getApiKeyLabel())
|
queryClient.invalidateQueries({ queryKey: deploymentKeys.info(workflowId) })
|
||||||
|
queryClient.invalidateQueries({ queryKey: deploymentKeys.versions(workflowId) })
|
||||||
const deploymentInfoResponse = await fetch(`/api/workflows/${workflowId}/deploy`)
|
queryClient.invalidateQueries({ queryKey: deploymentKeys.chatStatus(workflowId) })
|
||||||
if (deploymentInfoResponse.ok) {
|
|
||||||
const deploymentData = await deploymentInfoResponse.json()
|
|
||||||
const apiEndpoint = `${getBaseUrl()}/api/workflows/${workflowId}/execute`
|
|
||||||
const inputFormatExample = getInputFormatExample(selectedStreamingOutputs.length > 0)
|
|
||||||
|
|
||||||
const placeholderKey = getApiHeaderPlaceholder()
|
|
||||||
|
|
||||||
setDeploymentInfo({
|
|
||||||
isDeployed: deploymentData.isDeployed,
|
|
||||||
deployedAt: deploymentData.deployedAt,
|
|
||||||
apiKey: getApiKeyLabel(deploymentData.apiKey),
|
|
||||||
endpoint: apiEndpoint,
|
|
||||||
exampleCommand: `curl -X POST -H "X-API-Key: ${placeholderKey}" -H "Content-Type: application/json"${inputFormatExample} ${apiEndpoint}`,
|
|
||||||
needsRedeployment: false,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
await refetchDeployedState()
|
await refetchDeployedState()
|
||||||
await fetchVersions()
|
|
||||||
useWorkflowRegistry.getState().setWorkflowNeedsRedeployment(workflowId, false)
|
useWorkflowRegistry.getState().setWorkflowNeedsRedeployment(workflowId, false)
|
||||||
}
|
|
||||||
|
|
||||||
const handleChatFormSubmit = () => {
|
setChatSuccess(true)
|
||||||
|
setTimeout(() => setChatSuccess(false), 2000)
|
||||||
|
}, [workflowId, queryClient, refetchDeployedState])
|
||||||
|
|
||||||
|
const handleRefetchChat = useCallback(async () => {
|
||||||
|
await refetchChatInfo()
|
||||||
|
}, [refetchChatInfo])
|
||||||
|
|
||||||
|
const handleChatFormSubmit = useCallback(() => {
|
||||||
const form = document.getElementById('chat-deploy-form') as HTMLFormElement
|
const form = document.getElementById('chat-deploy-form') as HTMLFormElement
|
||||||
if (form) {
|
if (form) {
|
||||||
const updateTrigger = form.querySelector('[data-update-trigger]') as HTMLButtonElement
|
const updateTrigger = form.querySelector('[data-update-trigger]') as HTMLButtonElement
|
||||||
@@ -553,9 +367,9 @@ export function DeployModal({
|
|||||||
form.requestSubmit()
|
form.requestSubmit()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}, [])
|
||||||
|
|
||||||
const handleChatDelete = () => {
|
const handleChatDelete = useCallback(() => {
|
||||||
const form = document.getElementById('chat-deploy-form') as HTMLFormElement
|
const form = document.getElementById('chat-deploy-form') as HTMLFormElement
|
||||||
if (form) {
|
if (form) {
|
||||||
const deleteButton = form.querySelector('[data-delete-trigger]') as HTMLButtonElement
|
const deleteButton = form.querySelector('[data-delete-trigger]') as HTMLButtonElement
|
||||||
@@ -563,7 +377,7 @@ export function DeployModal({
|
|||||||
deleteButton.click()
|
deleteButton.click()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}, [])
|
||||||
|
|
||||||
const handleTemplateFormSubmit = useCallback(() => {
|
const handleTemplateFormSubmit = useCallback(() => {
|
||||||
const form = document.getElementById('template-deploy-form') as HTMLFormElement
|
const form = document.getElementById('template-deploy-form') as HTMLFormElement
|
||||||
@@ -623,6 +437,13 @@ export function DeployModal({
|
|||||||
deleteTrigger?.click()
|
deleteTrigger?.click()
|
||||||
}, [])
|
}, [])
|
||||||
|
|
||||||
|
const handleFetchVersions = useCallback(async () => {
|
||||||
|
await refetchVersions()
|
||||||
|
}, [refetchVersions])
|
||||||
|
|
||||||
|
const isSubmitting = deployMutation.isPending
|
||||||
|
const isUndeploying = undeployMutation.isPending
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<Modal open={open} onOpenChange={handleCloseModal}>
|
<Modal open={open} onOpenChange={handleCloseModal}>
|
||||||
@@ -670,7 +491,7 @@ export function DeployModal({
|
|||||||
versionsLoading={versionsLoading}
|
versionsLoading={versionsLoading}
|
||||||
onPromoteToLive={handlePromoteToLive}
|
onPromoteToLive={handlePromoteToLive}
|
||||||
onLoadDeploymentComplete={handleCloseModal}
|
onLoadDeploymentComplete={handleCloseModal}
|
||||||
fetchVersions={fetchVersions}
|
fetchVersions={handleFetchVersions}
|
||||||
/>
|
/>
|
||||||
</ModalTabsContent>
|
</ModalTabsContent>
|
||||||
|
|
||||||
@@ -678,7 +499,7 @@ export function DeployModal({
|
|||||||
<ApiDeploy
|
<ApiDeploy
|
||||||
workflowId={workflowId}
|
workflowId={workflowId}
|
||||||
deploymentInfo={deploymentInfo}
|
deploymentInfo={deploymentInfo}
|
||||||
isLoading={isLoading}
|
isLoading={isLoadingDeploymentInfo}
|
||||||
needsRedeployment={needsRedeployment}
|
needsRedeployment={needsRedeployment}
|
||||||
apiDeployError={apiDeployError}
|
apiDeployError={apiDeployError}
|
||||||
getInputFormatExample={getInputFormatExample}
|
getInputFormatExample={getInputFormatExample}
|
||||||
@@ -691,10 +512,9 @@ export function DeployModal({
|
|||||||
<ChatDeploy
|
<ChatDeploy
|
||||||
workflowId={workflowId || ''}
|
workflowId={workflowId || ''}
|
||||||
deploymentInfo={deploymentInfo}
|
deploymentInfo={deploymentInfo}
|
||||||
existingChat={existingChat}
|
existingChat={existingChat as ExistingChat | null}
|
||||||
isLoadingChat={isLoadingChat}
|
isLoadingChat={isLoadingChat}
|
||||||
onRefetchChat={fetchChatDeploymentInfo}
|
onRefetchChat={handleRefetchChat}
|
||||||
onChatExistsChange={setChatExists}
|
|
||||||
chatSubmitting={chatSubmitting}
|
chatSubmitting={chatSubmitting}
|
||||||
setChatSubmitting={setChatSubmitting}
|
setChatSubmitting={setChatSubmitting}
|
||||||
onValidationChange={setIsChatFormValid}
|
onValidationChange={setIsChatFormValid}
|
||||||
@@ -711,8 +531,6 @@ export function DeployModal({
|
|||||||
onDeploymentComplete={handleCloseModal}
|
onDeploymentComplete={handleCloseModal}
|
||||||
onValidationChange={setTemplateFormValid}
|
onValidationChange={setTemplateFormValid}
|
||||||
onSubmittingChange={setTemplateSubmitting}
|
onSubmittingChange={setTemplateSubmitting}
|
||||||
onExistingTemplateChange={setHasExistingTemplate}
|
|
||||||
onTemplateStatusChange={setTemplateStatus}
|
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
</ModalTabsContent>
|
</ModalTabsContent>
|
||||||
@@ -741,7 +559,6 @@ export function DeployModal({
|
|||||||
isDeployed={isDeployed}
|
isDeployed={isDeployed}
|
||||||
onSubmittingChange={setMcpToolSubmitting}
|
onSubmittingChange={setMcpToolSubmitting}
|
||||||
onCanSaveChange={setMcpToolCanSave}
|
onCanSaveChange={setMcpToolCanSave}
|
||||||
onHasServersChange={setHasMcpServers}
|
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
</ModalTabsContent>
|
</ModalTabsContent>
|
||||||
@@ -756,8 +573,6 @@ export function DeployModal({
|
|||||||
workflowNeedsRedeployment={needsRedeployment}
|
workflowNeedsRedeployment={needsRedeployment}
|
||||||
onSubmittingChange={setA2aSubmitting}
|
onSubmittingChange={setA2aSubmitting}
|
||||||
onCanSaveChange={setA2aCanSave}
|
onCanSaveChange={setA2aCanSave}
|
||||||
onAgentExistsChange={setHasA2aAgent}
|
|
||||||
onPublishedChange={setIsA2aPublished}
|
|
||||||
onNeedsRepublishChange={setA2aNeedsRepublish}
|
onNeedsRepublishChange={setA2aNeedsRepublish}
|
||||||
onDeployWorkflow={onDeploy}
|
onDeployWorkflow={onDeploy}
|
||||||
/>
|
/>
|
||||||
@@ -843,7 +658,7 @@ export function DeployModal({
|
|||||||
onClick={handleMcpToolFormSubmit}
|
onClick={handleMcpToolFormSubmit}
|
||||||
disabled={mcpToolSubmitting || !mcpToolCanSave}
|
disabled={mcpToolSubmitting || !mcpToolCanSave}
|
||||||
>
|
>
|
||||||
{mcpToolSubmitting ? 'Saving...' : 'Save Tool Schema'}
|
{mcpToolSubmitting ? 'Saving...' : 'Save Tool'}
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
</ModalFooter>
|
</ModalFooter>
|
||||||
@@ -1031,7 +846,11 @@ export function DeployModal({
|
|||||||
<ModalHeader>Delete A2A Agent</ModalHeader>
|
<ModalHeader>Delete A2A Agent</ModalHeader>
|
||||||
<ModalBody>
|
<ModalBody>
|
||||||
<p className='text-[12px] text-[var(--text-secondary)]'>
|
<p className='text-[12px] text-[var(--text-secondary)]'>
|
||||||
Are you sure you want to delete this agent?{' '}
|
Are you sure you want to delete{' '}
|
||||||
|
<span className='font-medium text-[var(--text-primary)]'>
|
||||||
|
{existingA2aAgent?.name || 'this agent'}
|
||||||
|
</span>
|
||||||
|
?{' '}
|
||||||
<span className='text-[var(--text-error)]'>
|
<span className='text-[var(--text-error)]'>
|
||||||
This will permanently remove the agent configuration.
|
This will permanently remove the agent configuration.
|
||||||
</span>
|
</span>
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import type { ReactElement } from 'react'
|
import type { ReactElement } from 'react'
|
||||||
import { useEffect, useImperativeHandle, useMemo, useRef, useState } from 'react'
|
import { memo, useCallback, useEffect, useImperativeHandle, useMemo, useRef, useState } from 'react'
|
||||||
import { Check, Copy, Wand2 } from 'lucide-react'
|
import { Check, Copy, Wand2 } from 'lucide-react'
|
||||||
import { useParams } from 'next/navigation'
|
import { useParams } from 'next/navigation'
|
||||||
import 'prismjs/components/prism-python'
|
import 'prismjs/components/prism-python'
|
||||||
@@ -170,7 +170,7 @@ interface CodeProps {
|
|||||||
hideInternalWand?: boolean
|
hideInternalWand?: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
export function Code({
|
export const Code = memo(function Code({
|
||||||
blockId,
|
blockId,
|
||||||
subBlockId,
|
subBlockId,
|
||||||
placeholder = 'Write JavaScript...',
|
placeholder = 'Write JavaScript...',
|
||||||
@@ -206,6 +206,8 @@ export function Code({
|
|||||||
const handleGeneratedContentRef = useRef<(generatedCode: string) => void>(() => {})
|
const handleGeneratedContentRef = useRef<(generatedCode: string) => void>(() => {})
|
||||||
const handleStreamChunkRef = useRef<(chunk: string) => void>(() => {})
|
const handleStreamChunkRef = useRef<(chunk: string) => void>(() => {})
|
||||||
const hasEditedSinceFocusRef = useRef(false)
|
const hasEditedSinceFocusRef = useRef(false)
|
||||||
|
const codeRef = useRef(code)
|
||||||
|
codeRef.current = code
|
||||||
|
|
||||||
const accessiblePrefixes = useAccessibleReferencePrefixes(blockId)
|
const accessiblePrefixes = useAccessibleReferencePrefixes(blockId)
|
||||||
const emitTagSelection = useTagSelection(blockId, subBlockId)
|
const emitTagSelection = useTagSelection(blockId, subBlockId)
|
||||||
@@ -307,25 +309,18 @@ export function Code({
|
|||||||
? getDefaultValueString()
|
? getDefaultValueString()
|
||||||
: storeValue
|
: storeValue
|
||||||
|
|
||||||
const lastValidationStatus = useRef<boolean>(true)
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!onValidationChange) return
|
if (!onValidationChange) return
|
||||||
|
|
||||||
const nextStatus = shouldValidateJson ? isValidJson : true
|
const isValid = !shouldValidateJson || isValidJson
|
||||||
if (lastValidationStatus.current === nextStatus) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
lastValidationStatus.current = nextStatus
|
if (isValid) {
|
||||||
|
onValidationChange(true)
|
||||||
if (!shouldValidateJson) {
|
|
||||||
onValidationChange(nextStatus)
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
const timeoutId = setTimeout(() => {
|
const timeoutId = setTimeout(() => {
|
||||||
onValidationChange(nextStatus)
|
onValidationChange(false)
|
||||||
}, 150)
|
}, 150)
|
||||||
|
|
||||||
return () => clearTimeout(timeoutId)
|
return () => clearTimeout(timeoutId)
|
||||||
@@ -337,7 +332,7 @@ export function Code({
|
|||||||
}
|
}
|
||||||
|
|
||||||
handleStreamChunkRef.current = (chunk: string) => {
|
handleStreamChunkRef.current = (chunk: string) => {
|
||||||
setCode((prev) => prev + chunk)
|
setCode((prev: string) => prev + chunk)
|
||||||
}
|
}
|
||||||
|
|
||||||
handleGeneratedContentRef.current = (generatedCode: string) => {
|
handleGeneratedContentRef.current = (generatedCode: string) => {
|
||||||
@@ -434,12 +429,12 @@ export function Code({
|
|||||||
`
|
`
|
||||||
document.body.appendChild(tempContainer)
|
document.body.appendChild(tempContainer)
|
||||||
|
|
||||||
lines.forEach((line) => {
|
lines.forEach((line: string) => {
|
||||||
const lineDiv = document.createElement('div')
|
const lineDiv = document.createElement('div')
|
||||||
|
|
||||||
if (line.includes('<') && line.includes('>')) {
|
if (line.includes('<') && line.includes('>')) {
|
||||||
const parts = line.split(/(<[^>]+>)/g)
|
const parts = line.split(/(<[^>]+>)/g)
|
||||||
parts.forEach((part) => {
|
parts.forEach((part: string) => {
|
||||||
const span = document.createElement('span')
|
const span = document.createElement('span')
|
||||||
span.textContent = part
|
span.textContent = part
|
||||||
lineDiv.appendChild(span)
|
lineDiv.appendChild(span)
|
||||||
@@ -472,7 +467,6 @@ export function Code({
|
|||||||
}
|
}
|
||||||
}, [code])
|
}, [code])
|
||||||
|
|
||||||
// Event Handlers
|
|
||||||
/**
|
/**
|
||||||
* Handles drag-and-drop events for inserting reference tags into the code editor.
|
* Handles drag-and-drop events for inserting reference tags into the code editor.
|
||||||
* @param e - The drag event
|
* @param e - The drag event
|
||||||
@@ -500,7 +494,6 @@ export function Code({
|
|||||||
textarea.selectionStart = newCursorPosition
|
textarea.selectionStart = newCursorPosition
|
||||||
textarea.selectionEnd = newCursorPosition
|
textarea.selectionEnd = newCursorPosition
|
||||||
|
|
||||||
// Show tag dropdown after cursor is positioned
|
|
||||||
setShowTags(true)
|
setShowTags(true)
|
||||||
if (data.connectionData?.sourceBlockId) {
|
if (data.connectionData?.sourceBlockId) {
|
||||||
setActiveSourceBlockId(data.connectionData.sourceBlockId)
|
setActiveSourceBlockId(data.connectionData.sourceBlockId)
|
||||||
@@ -559,44 +552,45 @@ export function Code({
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Helper Functions
|
|
||||||
/**
|
/**
|
||||||
* Determines whether a `<...>` segment should be highlighted as a reference.
|
* Determines whether a `<...>` segment should be highlighted as a reference.
|
||||||
* @param part - The code segment to check
|
* @param part - The code segment to check
|
||||||
* @returns True if the segment should be highlighted as a reference
|
* @returns True if the segment should be highlighted as a reference
|
||||||
*/
|
*/
|
||||||
const shouldHighlightReference = (part: string): boolean => {
|
const shouldHighlightReference = useCallback(
|
||||||
if (!part.startsWith('<') || !part.endsWith('>')) {
|
(part: string): boolean => {
|
||||||
return false
|
if (!part.startsWith('<') || !part.endsWith('>')) {
|
||||||
}
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
if (!isLikelyReferenceSegment(part)) {
|
if (!isLikelyReferenceSegment(part)) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
const split = splitReferenceSegment(part)
|
const split = splitReferenceSegment(part)
|
||||||
if (!split) {
|
if (!split) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
const reference = split.reference
|
const reference = split.reference
|
||||||
|
|
||||||
if (!accessiblePrefixes) {
|
if (!accessiblePrefixes) {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
const inner = reference.slice(1, -1)
|
const inner = reference.slice(1, -1)
|
||||||
const [prefix] = inner.split('.')
|
const [prefix] = inner.split('.')
|
||||||
const normalizedPrefix = normalizeName(prefix)
|
const normalizedPrefix = normalizeName(prefix)
|
||||||
|
|
||||||
if (SYSTEM_REFERENCE_PREFIXES.has(normalizedPrefix)) {
|
if (SYSTEM_REFERENCE_PREFIXES.has(normalizedPrefix)) {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
return accessiblePrefixes.has(normalizedPrefix)
|
return accessiblePrefixes.has(normalizedPrefix)
|
||||||
}
|
},
|
||||||
|
[accessiblePrefixes]
|
||||||
|
)
|
||||||
|
|
||||||
// Expose wand control handlers to parent via ref
|
|
||||||
useImperativeHandle(
|
useImperativeHandle(
|
||||||
wandControlRef,
|
wandControlRef,
|
||||||
() => ({
|
() => ({
|
||||||
@@ -609,6 +603,62 @@ export function Code({
|
|||||||
[generateCodeStream, isPromptVisible, isAiStreaming]
|
[generateCodeStream, isPromptVisible, isAiStreaming]
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const highlightCode = useMemo(
|
||||||
|
() => createHighlightFunction(effectiveLanguage, shouldHighlightReference),
|
||||||
|
[effectiveLanguage, shouldHighlightReference]
|
||||||
|
)
|
||||||
|
|
||||||
|
const handleValueChange = useCallback(
|
||||||
|
(newCode: string) => {
|
||||||
|
if (!isAiStreaming && !isPreview && !disabled && !readOnly) {
|
||||||
|
hasEditedSinceFocusRef.current = true
|
||||||
|
setCode(newCode)
|
||||||
|
setStoreValue(newCode)
|
||||||
|
|
||||||
|
const textarea = editorRef.current?.querySelector('textarea')
|
||||||
|
if (textarea) {
|
||||||
|
const pos = textarea.selectionStart
|
||||||
|
setCursorPosition(pos)
|
||||||
|
|
||||||
|
const tagTrigger = checkTagTrigger(newCode, pos)
|
||||||
|
setShowTags(tagTrigger.show)
|
||||||
|
if (!tagTrigger.show) {
|
||||||
|
setActiveSourceBlockId(null)
|
||||||
|
}
|
||||||
|
|
||||||
|
const envVarTrigger = checkEnvVarTrigger(newCode, pos)
|
||||||
|
setShowEnvVars(envVarTrigger.show)
|
||||||
|
setSearchTerm(envVarTrigger.show ? envVarTrigger.searchTerm : '')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
[isAiStreaming, isPreview, disabled, readOnly, setStoreValue]
|
||||||
|
)
|
||||||
|
|
||||||
|
const handleKeyDown = useCallback(
|
||||||
|
(e: React.KeyboardEvent<HTMLDivElement | HTMLTextAreaElement>) => {
|
||||||
|
if (e.key === 'Escape') {
|
||||||
|
setShowTags(false)
|
||||||
|
setShowEnvVars(false)
|
||||||
|
}
|
||||||
|
if (isAiStreaming) {
|
||||||
|
e.preventDefault()
|
||||||
|
}
|
||||||
|
if (e.key === 'z' && (e.metaKey || e.ctrlKey) && !hasEditedSinceFocusRef.current) {
|
||||||
|
e.preventDefault()
|
||||||
|
}
|
||||||
|
},
|
||||||
|
[isAiStreaming]
|
||||||
|
)
|
||||||
|
|
||||||
|
const handleEditorFocus = useCallback(() => {
|
||||||
|
hasEditedSinceFocusRef.current = false
|
||||||
|
if (!isPreview && !disabled && !readOnly && codeRef.current.trim() === '') {
|
||||||
|
setShowTags(true)
|
||||||
|
setCursorPosition(0)
|
||||||
|
}
|
||||||
|
}, [isPreview, disabled, readOnly])
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Renders the line numbers, aligned with wrapped visual lines and highlighting the active line.
|
* Renders the line numbers, aligned with wrapped visual lines and highlighting the active line.
|
||||||
* @returns Array of React elements representing the line numbers
|
* @returns Array of React elements representing the line numbers
|
||||||
@@ -617,7 +667,7 @@ export function Code({
|
|||||||
const numbers: ReactElement[] = []
|
const numbers: ReactElement[] = []
|
||||||
let lineNumber = 1
|
let lineNumber = 1
|
||||||
|
|
||||||
visualLineHeights.forEach((height) => {
|
visualLineHeights.forEach((height: number) => {
|
||||||
const isActive = lineNumber === activeLineNumber
|
const isActive = lineNumber === activeLineNumber
|
||||||
numbers.push(
|
numbers.push(
|
||||||
<div
|
<div
|
||||||
@@ -724,50 +774,10 @@ export function Code({
|
|||||||
|
|
||||||
<Editor
|
<Editor
|
||||||
value={code}
|
value={code}
|
||||||
onValueChange={(newCode) => {
|
onValueChange={handleValueChange}
|
||||||
if (!isAiStreaming && !isPreview && !disabled && !readOnly) {
|
onKeyDown={handleKeyDown}
|
||||||
hasEditedSinceFocusRef.current = true
|
onFocus={handleEditorFocus}
|
||||||
setCode(newCode)
|
highlight={highlightCode}
|
||||||
setStoreValue(newCode)
|
|
||||||
|
|
||||||
const textarea = editorRef.current?.querySelector('textarea')
|
|
||||||
if (textarea) {
|
|
||||||
const pos = textarea.selectionStart
|
|
||||||
setCursorPosition(pos)
|
|
||||||
|
|
||||||
const tagTrigger = checkTagTrigger(newCode, pos)
|
|
||||||
setShowTags(tagTrigger.show)
|
|
||||||
if (!tagTrigger.show) {
|
|
||||||
setActiveSourceBlockId(null)
|
|
||||||
}
|
|
||||||
|
|
||||||
const envVarTrigger = checkEnvVarTrigger(newCode, pos)
|
|
||||||
setShowEnvVars(envVarTrigger.show)
|
|
||||||
setSearchTerm(envVarTrigger.show ? envVarTrigger.searchTerm : '')
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}}
|
|
||||||
onKeyDown={(e) => {
|
|
||||||
if (e.key === 'Escape') {
|
|
||||||
setShowTags(false)
|
|
||||||
setShowEnvVars(false)
|
|
||||||
}
|
|
||||||
if (isAiStreaming) {
|
|
||||||
e.preventDefault()
|
|
||||||
}
|
|
||||||
if (e.key === 'z' && (e.metaKey || e.ctrlKey) && !hasEditedSinceFocusRef.current) {
|
|
||||||
e.preventDefault()
|
|
||||||
}
|
|
||||||
}}
|
|
||||||
onFocus={() => {
|
|
||||||
hasEditedSinceFocusRef.current = false
|
|
||||||
// Show tag dropdown on focus when code is empty
|
|
||||||
if (!isPreview && !disabled && !readOnly && code.trim() === '') {
|
|
||||||
setShowTags(true)
|
|
||||||
setCursorPosition(0)
|
|
||||||
}
|
|
||||||
}}
|
|
||||||
highlight={createHighlightFunction(effectiveLanguage, shouldHighlightReference)}
|
|
||||||
{...getCodeEditorProps({ isStreaming: isAiStreaming, isPreview, disabled })}
|
{...getCodeEditorProps({ isStreaming: isAiStreaming, isPreview, disabled })}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
@@ -810,4 +820,4 @@ export function Code({
|
|||||||
</CodeEditor.Container>
|
</CodeEditor.Container>
|
||||||
</>
|
</>
|
||||||
)
|
)
|
||||||
}
|
})
|
||||||
|
|||||||
@@ -1,17 +1,21 @@
|
|||||||
import { useCallback, useEffect, useMemo, useRef, useState } from 'react'
|
import { memo, useCallback, useEffect, useMemo, useRef, useState } from 'react'
|
||||||
|
import { isEqual } from 'lodash'
|
||||||
import { useReactFlow } from 'reactflow'
|
import { useReactFlow } from 'reactflow'
|
||||||
import { Combobox, type ComboboxOption } from '@/components/emcn/components'
|
import { Combobox, type ComboboxOption } from '@/components/emcn/components'
|
||||||
import { cn } from '@/lib/core/utils/cn'
|
import { cn } from '@/lib/core/utils/cn'
|
||||||
|
import { buildCanonicalIndex, resolveDependencyValue } from '@/lib/workflows/subblocks/visibility'
|
||||||
import { formatDisplayText } from '@/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/editor/components/sub-block/components/formatted-text'
|
import { formatDisplayText } from '@/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/editor/components/sub-block/components/formatted-text'
|
||||||
import { SubBlockInputController } from '@/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/editor/components/sub-block/components/sub-block-input-controller'
|
import { SubBlockInputController } from '@/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/editor/components/sub-block/components/sub-block-input-controller'
|
||||||
import { useSubBlockValue } from '@/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/editor/components/sub-block/hooks/use-sub-block-value'
|
import { useSubBlockValue } from '@/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/editor/components/sub-block/hooks/use-sub-block-value'
|
||||||
import { useAccessibleReferencePrefixes } from '@/app/workspace/[workspaceId]/w/[workflowId]/hooks/use-accessible-reference-prefixes'
|
import { useAccessibleReferencePrefixes } from '@/app/workspace/[workspaceId]/w/[workflowId]/hooks/use-accessible-reference-prefixes'
|
||||||
|
import { getBlock } from '@/blocks/registry'
|
||||||
import type { SubBlockConfig } from '@/blocks/types'
|
import type { SubBlockConfig } from '@/blocks/types'
|
||||||
import { getDependsOnFields } from '@/blocks/utils'
|
import { getDependsOnFields } from '@/blocks/utils'
|
||||||
import { usePermissionConfig } from '@/hooks/use-permission-config'
|
import { usePermissionConfig } from '@/hooks/use-permission-config'
|
||||||
import { getProviderFromModel } from '@/providers/utils'
|
import { getProviderFromModel } from '@/providers/utils'
|
||||||
import { useWorkflowRegistry } from '@/stores/workflows/registry/store'
|
import { useWorkflowRegistry } from '@/stores/workflows/registry/store'
|
||||||
import { useSubBlockStore } from '@/stores/workflows/subblock/store'
|
import { useSubBlockStore } from '@/stores/workflows/subblock/store'
|
||||||
|
import { useWorkflowStore } from '@/stores/workflows/workflow/store'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constants for ComboBox component behavior
|
* Constants for ComboBox component behavior
|
||||||
@@ -68,7 +72,7 @@ interface ComboBoxProps {
|
|||||||
dependsOn?: SubBlockConfig['dependsOn']
|
dependsOn?: SubBlockConfig['dependsOn']
|
||||||
}
|
}
|
||||||
|
|
||||||
export function ComboBox({
|
export const ComboBox = memo(function ComboBox({
|
||||||
options,
|
options,
|
||||||
defaultValue,
|
defaultValue,
|
||||||
blockId,
|
blockId,
|
||||||
@@ -91,16 +95,26 @@ export function ComboBox({
|
|||||||
// Dependency tracking for fetchOptions
|
// Dependency tracking for fetchOptions
|
||||||
const dependsOnFields = useMemo(() => getDependsOnFields(dependsOn), [dependsOn])
|
const dependsOnFields = useMemo(() => getDependsOnFields(dependsOn), [dependsOn])
|
||||||
const activeWorkflowId = useWorkflowRegistry((s) => s.activeWorkflowId)
|
const activeWorkflowId = useWorkflowRegistry((s) => s.activeWorkflowId)
|
||||||
|
const blockState = useWorkflowStore((state) => state.blocks[blockId])
|
||||||
|
const blockConfig = blockState?.type ? getBlock(blockState.type) : null
|
||||||
|
const canonicalIndex = useMemo(
|
||||||
|
() => buildCanonicalIndex(blockConfig?.subBlocks || []),
|
||||||
|
[blockConfig?.subBlocks]
|
||||||
|
)
|
||||||
|
const canonicalModeOverrides = blockState?.data?.canonicalModes
|
||||||
const dependencyValues = useSubBlockStore(
|
const dependencyValues = useSubBlockStore(
|
||||||
useCallback(
|
useCallback(
|
||||||
(state) => {
|
(state) => {
|
||||||
if (dependsOnFields.length === 0 || !activeWorkflowId) return []
|
if (dependsOnFields.length === 0 || !activeWorkflowId) return []
|
||||||
const workflowValues = state.workflowValues[activeWorkflowId] || {}
|
const workflowValues = state.workflowValues[activeWorkflowId] || {}
|
||||||
const blockValues = workflowValues[blockId] || {}
|
const blockValues = workflowValues[blockId] || {}
|
||||||
return dependsOnFields.map((depKey) => blockValues[depKey] ?? null)
|
return dependsOnFields.map((depKey) =>
|
||||||
|
resolveDependencyValue(depKey, blockValues, canonicalIndex, canonicalModeOverrides)
|
||||||
|
)
|
||||||
},
|
},
|
||||||
[dependsOnFields, activeWorkflowId, blockId]
|
[dependsOnFields, activeWorkflowId, blockId, canonicalIndex, canonicalModeOverrides]
|
||||||
)
|
),
|
||||||
|
isEqual
|
||||||
)
|
)
|
||||||
|
|
||||||
// State management
|
// State management
|
||||||
@@ -269,34 +283,17 @@ export function ComboBox({
|
|||||||
setStoreInitialized(true)
|
setStoreInitialized(true)
|
||||||
}, [])
|
}, [])
|
||||||
|
|
||||||
// Check if current value is valid (exists in allowed options)
|
|
||||||
const isValueValid = useMemo(() => {
|
|
||||||
if (value === null || value === undefined) return false
|
|
||||||
return evaluatedOptions.some((opt) => getOptionValue(opt) === value)
|
|
||||||
}, [value, evaluatedOptions, getOptionValue])
|
|
||||||
|
|
||||||
// Set default value once store is initialized and permissions are loaded
|
// Set default value once store is initialized and permissions are loaded
|
||||||
// Also reset if current value becomes invalid (e.g., provider was blocked)
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (isPermissionLoading) return
|
if (isPermissionLoading) return
|
||||||
if (!storeInitialized) return
|
if (!storeInitialized) return
|
||||||
if (defaultOptionValue === undefined) return
|
if (defaultOptionValue === undefined) return
|
||||||
|
|
||||||
const needsDefault = value === null || value === undefined
|
// Only set default when no value exists (initial block add)
|
||||||
const needsReset = subBlockId === 'model' && value && !isValueValid
|
if (value === null || value === undefined) {
|
||||||
|
|
||||||
if (needsDefault || needsReset) {
|
|
||||||
setStoreValue(defaultOptionValue)
|
setStoreValue(defaultOptionValue)
|
||||||
}
|
}
|
||||||
}, [
|
}, [storeInitialized, value, defaultOptionValue, setStoreValue, isPermissionLoading])
|
||||||
storeInitialized,
|
|
||||||
value,
|
|
||||||
defaultOptionValue,
|
|
||||||
setStoreValue,
|
|
||||||
isPermissionLoading,
|
|
||||||
subBlockId,
|
|
||||||
isValueValid,
|
|
||||||
])
|
|
||||||
|
|
||||||
// Clear fetched options and hydrated option when dependencies change
|
// Clear fetched options and hydrated option when dependencies change
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@@ -425,6 +422,18 @@ export function ComboBox({
|
|||||||
[reactFlowInstance]
|
[reactFlowInstance]
|
||||||
)
|
)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handles combobox open state changes to trigger option fetching
|
||||||
|
*/
|
||||||
|
const handleOpenChange = useCallback(
|
||||||
|
(open: boolean) => {
|
||||||
|
if (open) {
|
||||||
|
void fetchOptionsIfNeeded()
|
||||||
|
}
|
||||||
|
},
|
||||||
|
[fetchOptionsIfNeeded]
|
||||||
|
)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the icon for the currently selected option
|
* Gets the icon for the currently selected option
|
||||||
*/
|
*/
|
||||||
@@ -454,6 +463,75 @@ export function ComboBox({
|
|||||||
)
|
)
|
||||||
}, [inputValue, accessiblePrefixes, selectedOption, selectedOptionIcon])
|
}, [inputValue, accessiblePrefixes, selectedOption, selectedOptionIcon])
|
||||||
|
|
||||||
|
const ctrlOnChangeRef = useRef<
|
||||||
|
((e: React.ChangeEvent<HTMLTextAreaElement | HTMLInputElement>) => void) | null
|
||||||
|
>(null)
|
||||||
|
const onDropRef = useRef<
|
||||||
|
((e: React.DragEvent<HTMLTextAreaElement | HTMLInputElement>) => void) | null
|
||||||
|
>(null)
|
||||||
|
const onDragOverRef = useRef<
|
||||||
|
((e: React.DragEvent<HTMLTextAreaElement | HTMLInputElement>) => void) | null
|
||||||
|
>(null)
|
||||||
|
const inputRefFromController = useRef<HTMLInputElement | null>(null)
|
||||||
|
|
||||||
|
const comboboxOnChange = useCallback(
|
||||||
|
(newValue: string) => {
|
||||||
|
const matchedComboboxOption = comboboxOptions.find((option) => option.value === newValue)
|
||||||
|
if (matchedComboboxOption) {
|
||||||
|
setInputValue(matchedComboboxOption.label)
|
||||||
|
} else {
|
||||||
|
setInputValue(newValue)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Use controller's handler so env vars, tags, and DnD still work
|
||||||
|
const syntheticEvent = {
|
||||||
|
target: { value: newValue, selectionStart: newValue.length },
|
||||||
|
} as React.ChangeEvent<HTMLInputElement>
|
||||||
|
ctrlOnChangeRef.current?.(syntheticEvent)
|
||||||
|
},
|
||||||
|
[comboboxOptions, setInputValue]
|
||||||
|
)
|
||||||
|
|
||||||
|
const comboboxInputProps = useMemo(
|
||||||
|
() => ({
|
||||||
|
onDrop: ((e: React.DragEvent<HTMLInputElement>) => {
|
||||||
|
onDropRef.current?.(e)
|
||||||
|
}) as (e: React.DragEvent<HTMLInputElement>) => void,
|
||||||
|
onDragOver: ((e: React.DragEvent<HTMLInputElement>) => {
|
||||||
|
onDragOverRef.current?.(e)
|
||||||
|
}) as (e: React.DragEvent<HTMLInputElement>) => void,
|
||||||
|
onWheel: handleWheel,
|
||||||
|
autoComplete: 'off' as const,
|
||||||
|
}),
|
||||||
|
[handleWheel]
|
||||||
|
)
|
||||||
|
|
||||||
|
// Stable onChange for SubBlockInputController
|
||||||
|
const controllerOnChange = useCallback(
|
||||||
|
(newValue: string) => {
|
||||||
|
if (isPreview) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
const matchedOption = evaluatedOptions.find((option) => {
|
||||||
|
if (typeof option === 'string') {
|
||||||
|
return option === newValue
|
||||||
|
}
|
||||||
|
return option.id === newValue
|
||||||
|
})
|
||||||
|
|
||||||
|
// If a matching option is found, store its ID; otherwise store the raw value
|
||||||
|
// (allows expressions like <block.output> to be entered directly)
|
||||||
|
const nextValue = matchedOption
|
||||||
|
? typeof matchedOption === 'string'
|
||||||
|
? matchedOption
|
||||||
|
: matchedOption.id
|
||||||
|
: newValue
|
||||||
|
setStoreValue(nextValue)
|
||||||
|
},
|
||||||
|
[isPreview, evaluatedOptions, setStoreValue]
|
||||||
|
)
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className='relative w-full'>
|
<div className='relative w-full'>
|
||||||
<SubBlockInputController
|
<SubBlockInputController
|
||||||
@@ -461,76 +539,43 @@ export function ComboBox({
|
|||||||
subBlockId={subBlockId}
|
subBlockId={subBlockId}
|
||||||
config={config}
|
config={config}
|
||||||
value={propValue}
|
value={propValue}
|
||||||
onChange={(newValue) => {
|
onChange={controllerOnChange}
|
||||||
if (isPreview) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
const matchedOption = evaluatedOptions.find((option) => {
|
|
||||||
if (typeof option === 'string') {
|
|
||||||
return option === newValue
|
|
||||||
}
|
|
||||||
return option.id === newValue
|
|
||||||
})
|
|
||||||
|
|
||||||
// If a matching option is found, store its ID; otherwise store the raw value
|
|
||||||
// (allows expressions like <block.output> to be entered directly)
|
|
||||||
const nextValue = matchedOption
|
|
||||||
? typeof matchedOption === 'string'
|
|
||||||
? matchedOption
|
|
||||||
: matchedOption.id
|
|
||||||
: newValue
|
|
||||||
setStoreValue(nextValue)
|
|
||||||
}}
|
|
||||||
isPreview={isPreview}
|
isPreview={isPreview}
|
||||||
disabled={disabled}
|
disabled={disabled}
|
||||||
previewValue={previewValue}
|
previewValue={previewValue}
|
||||||
>
|
>
|
||||||
{({ ref, onChange: ctrlOnChange, onDrop, onDragOver }) => (
|
{({ ref, onChange: ctrlOnChange, onDrop, onDragOver }) => {
|
||||||
<Combobox
|
// Update refs with latest handlers from render prop
|
||||||
options={comboboxOptions}
|
ctrlOnChangeRef.current = ctrlOnChange
|
||||||
value={inputValue}
|
onDropRef.current = onDrop
|
||||||
selectedValue={value ?? ''}
|
onDragOverRef.current = onDragOver
|
||||||
onChange={(newValue) => {
|
// Store the input ref for passing to Combobox
|
||||||
const matchedComboboxOption = comboboxOptions.find(
|
if (ref.current) {
|
||||||
(option) => option.value === newValue
|
inputRefFromController.current = ref.current as HTMLInputElement
|
||||||
)
|
}
|
||||||
if (matchedComboboxOption) {
|
|
||||||
setInputValue(matchedComboboxOption.label)
|
|
||||||
} else {
|
|
||||||
setInputValue(newValue)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Use controller's handler so env vars, tags, and DnD still work
|
return (
|
||||||
const syntheticEvent = {
|
<Combobox
|
||||||
target: { value: newValue, selectionStart: newValue.length },
|
options={comboboxOptions}
|
||||||
} as React.ChangeEvent<HTMLInputElement>
|
value={inputValue}
|
||||||
ctrlOnChange(syntheticEvent)
|
selectedValue={value ?? ''}
|
||||||
}}
|
onChange={comboboxOnChange}
|
||||||
placeholder={placeholder}
|
placeholder={placeholder}
|
||||||
disabled={disabled}
|
disabled={disabled}
|
||||||
editable
|
editable
|
||||||
overlayContent={overlayContent}
|
overlayContent={overlayContent}
|
||||||
inputRef={ref as React.RefObject<HTMLInputElement>}
|
inputRef={ref as React.RefObject<HTMLInputElement>}
|
||||||
filterOptions
|
filterOptions
|
||||||
searchable={config.searchable}
|
searchable={config.searchable}
|
||||||
className={cn('allow-scroll overflow-x-auto', selectedOptionIcon && 'pl-[28px]')}
|
className={cn('allow-scroll overflow-x-auto', selectedOptionIcon && 'pl-[28px]')}
|
||||||
inputProps={{
|
inputProps={comboboxInputProps}
|
||||||
onDrop: onDrop as (e: React.DragEvent<HTMLInputElement>) => void,
|
isLoading={isLoadingOptions}
|
||||||
onDragOver: onDragOver as (e: React.DragEvent<HTMLInputElement>) => void,
|
error={fetchError}
|
||||||
onWheel: handleWheel,
|
onOpenChange={handleOpenChange}
|
||||||
autoComplete: 'off',
|
/>
|
||||||
}}
|
)
|
||||||
isLoading={isLoadingOptions}
|
}}
|
||||||
error={fetchError}
|
|
||||||
onOpenChange={(open) => {
|
|
||||||
if (open) {
|
|
||||||
void fetchOptionsIfNeeded()
|
|
||||||
}
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
</SubBlockInputController>
|
</SubBlockInputController>
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
}
|
})
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import type { ReactElement } from 'react'
|
import type { ReactElement } from 'react'
|
||||||
import { useEffect, useRef, useState } from 'react'
|
import { useEffect, useRef, useState } from 'react'
|
||||||
import { createLogger } from '@sim/logger'
|
import { createLogger } from '@sim/logger'
|
||||||
import { ChevronDown, ChevronUp, Plus } from 'lucide-react'
|
import { ChevronDown, ChevronsUpDown, ChevronUp, Plus } from 'lucide-react'
|
||||||
import { useParams } from 'next/navigation'
|
import { useParams } from 'next/navigation'
|
||||||
import Editor from 'react-simple-code-editor'
|
import Editor from 'react-simple-code-editor'
|
||||||
import { useUpdateNodeInternals } from 'reactflow'
|
import { useUpdateNodeInternals } from 'reactflow'
|
||||||
@@ -39,6 +39,16 @@ import { useWorkflowStore } from '@/stores/workflows/workflow/store'
|
|||||||
|
|
||||||
const logger = createLogger('ConditionInput')
|
const logger = createLogger('ConditionInput')
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Default height for router textareas in pixels
|
||||||
|
*/
|
||||||
|
const ROUTER_DEFAULT_HEIGHT_PX = 100
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Minimum height for router textareas in pixels
|
||||||
|
*/
|
||||||
|
const ROUTER_MIN_HEIGHT_PX = 80
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a single conditional block (if/else if/else).
|
* Represents a single conditional block (if/else if/else).
|
||||||
*/
|
*/
|
||||||
@@ -743,6 +753,61 @@ export function ConditionInput({
|
|||||||
}
|
}
|
||||||
}, [conditionalBlocks, isRouterMode])
|
}, [conditionalBlocks, isRouterMode])
|
||||||
|
|
||||||
|
// State for tracking individual router textarea heights
|
||||||
|
const [routerHeights, setRouterHeights] = useState<{ [key: string]: number }>({})
|
||||||
|
const isResizing = useRef(false)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the height for a specific router block, returning default if not set.
|
||||||
|
*
|
||||||
|
* @param blockId - ID of the router block
|
||||||
|
* @returns Height in pixels
|
||||||
|
*/
|
||||||
|
const getRouterHeight = (blockId: string): number => {
|
||||||
|
return routerHeights[blockId] ?? ROUTER_DEFAULT_HEIGHT_PX
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handles mouse-based resize for router textareas.
|
||||||
|
*
|
||||||
|
* @param e - Mouse event from the resize handle
|
||||||
|
* @param blockId - ID of the block being resized
|
||||||
|
*/
|
||||||
|
const startRouterResize = (e: React.MouseEvent, blockId: string) => {
|
||||||
|
if (isPreview || disabled) return
|
||||||
|
e.preventDefault()
|
||||||
|
e.stopPropagation()
|
||||||
|
isResizing.current = true
|
||||||
|
|
||||||
|
const startY = e.clientY
|
||||||
|
const startHeight = getRouterHeight(blockId)
|
||||||
|
|
||||||
|
const handleMouseMove = (moveEvent: MouseEvent) => {
|
||||||
|
if (!isResizing.current) return
|
||||||
|
|
||||||
|
const deltaY = moveEvent.clientY - startY
|
||||||
|
const newHeight = Math.max(ROUTER_MIN_HEIGHT_PX, startHeight + deltaY)
|
||||||
|
|
||||||
|
// Update the textarea height directly for smooth resizing
|
||||||
|
const textarea = inputRefs.current.get(blockId)
|
||||||
|
if (textarea) {
|
||||||
|
textarea.style.height = `${newHeight}px`
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update state to keep track
|
||||||
|
setRouterHeights((prev) => ({ ...prev, [blockId]: newHeight }))
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleMouseUp = () => {
|
||||||
|
isResizing.current = false
|
||||||
|
document.removeEventListener('mousemove', handleMouseMove)
|
||||||
|
document.removeEventListener('mouseup', handleMouseUp)
|
||||||
|
}
|
||||||
|
|
||||||
|
document.addEventListener('mousemove', handleMouseMove)
|
||||||
|
document.addEventListener('mouseup', handleMouseUp)
|
||||||
|
}
|
||||||
|
|
||||||
// Show loading or empty state if not ready or no blocks
|
// Show loading or empty state if not ready or no blocks
|
||||||
if (!isReady || conditionalBlocks.length === 0) {
|
if (!isReady || conditionalBlocks.length === 0) {
|
||||||
return (
|
return (
|
||||||
@@ -907,10 +972,24 @@ export function ConditionInput({
|
|||||||
}}
|
}}
|
||||||
placeholder='Describe when this route should be taken...'
|
placeholder='Describe when this route should be taken...'
|
||||||
disabled={disabled || isPreview}
|
disabled={disabled || isPreview}
|
||||||
className='min-h-[60px] resize-none rounded-none border-0 px-3 py-2 text-sm placeholder:text-muted-foreground/50 focus-visible:ring-0 focus-visible:ring-offset-0'
|
className='min-h-[100px] resize-none rounded-none border-0 px-3 py-2 text-sm placeholder:text-muted-foreground/50 focus-visible:ring-0 focus-visible:ring-offset-0'
|
||||||
rows={2}
|
rows={4}
|
||||||
|
style={{ height: `${getRouterHeight(block.id)}px` }}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
|
{/* Custom resize handle */}
|
||||||
|
{!isPreview && !disabled && (
|
||||||
|
<div
|
||||||
|
className='absolute right-1 bottom-1 flex h-4 w-4 cursor-ns-resize items-center justify-center rounded-[4px] border border-[var(--border-1)] bg-[var(--surface-5)] dark:bg-[var(--surface-5)]'
|
||||||
|
onMouseDown={(e) => startRouterResize(e, block.id)}
|
||||||
|
onDragStart={(e) => {
|
||||||
|
e.preventDefault()
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<ChevronsUpDown className='h-3 w-3 text-[var(--text-muted)]' />
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
{block.showEnvVars && (
|
{block.showEnvVars && (
|
||||||
<EnvVarDropdown
|
<EnvVarDropdown
|
||||||
visible={block.showEnvVars}
|
visible={block.showEnvVars}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
'use client'
|
'use client'
|
||||||
|
|
||||||
import { useMemo } from 'react'
|
import { useMemo, useState } from 'react'
|
||||||
import { createLogger } from '@sim/logger'
|
import { createLogger } from '@sim/logger'
|
||||||
import { Check } from 'lucide-react'
|
import { Check } from 'lucide-react'
|
||||||
import {
|
import {
|
||||||
@@ -41,6 +41,7 @@ const SCOPE_DESCRIPTIONS: Record<string, string> = {
|
|||||||
'https://www.googleapis.com/auth/calendar': 'View and manage calendar',
|
'https://www.googleapis.com/auth/calendar': 'View and manage calendar',
|
||||||
'https://www.googleapis.com/auth/userinfo.email': 'View email address',
|
'https://www.googleapis.com/auth/userinfo.email': 'View email address',
|
||||||
'https://www.googleapis.com/auth/userinfo.profile': 'View basic profile info',
|
'https://www.googleapis.com/auth/userinfo.profile': 'View basic profile info',
|
||||||
|
'https://www.googleapis.com/auth/forms.body': 'View and manage Google Forms',
|
||||||
'https://www.googleapis.com/auth/forms.responses.readonly': 'View responses to Google Forms',
|
'https://www.googleapis.com/auth/forms.responses.readonly': 'View responses to Google Forms',
|
||||||
'https://www.googleapis.com/auth/ediscovery': 'Access Google Vault for eDiscovery',
|
'https://www.googleapis.com/auth/ediscovery': 'Access Google Vault for eDiscovery',
|
||||||
'https://www.googleapis.com/auth/devstorage.read_only': 'Read files from Google Cloud Storage',
|
'https://www.googleapis.com/auth/devstorage.read_only': 'Read files from Google Cloud Storage',
|
||||||
@@ -308,6 +309,7 @@ export function OAuthRequiredModal({
|
|||||||
serviceId,
|
serviceId,
|
||||||
newScopes = [],
|
newScopes = [],
|
||||||
}: OAuthRequiredModalProps) {
|
}: OAuthRequiredModalProps) {
|
||||||
|
const [error, setError] = useState<string | null>(null)
|
||||||
const { baseProvider } = parseProvider(provider)
|
const { baseProvider } = parseProvider(provider)
|
||||||
const baseProviderConfig = OAUTH_PROVIDERS[baseProvider]
|
const baseProviderConfig = OAUTH_PROVIDERS[baseProvider]
|
||||||
|
|
||||||
@@ -348,23 +350,24 @@ export function OAuthRequiredModal({
|
|||||||
}, [requiredScopes, newScopesSet])
|
}, [requiredScopes, newScopesSet])
|
||||||
|
|
||||||
const handleConnectDirectly = async () => {
|
const handleConnectDirectly = async () => {
|
||||||
|
setError(null)
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const providerId = getProviderIdFromServiceId(serviceId)
|
const providerId = getProviderIdFromServiceId(serviceId)
|
||||||
|
|
||||||
onClose()
|
|
||||||
|
|
||||||
logger.info('Linking OAuth2:', {
|
logger.info('Linking OAuth2:', {
|
||||||
providerId,
|
providerId,
|
||||||
requiredScopes,
|
requiredScopes,
|
||||||
})
|
})
|
||||||
|
|
||||||
if (providerId === 'trello') {
|
if (providerId === 'trello') {
|
||||||
|
onClose()
|
||||||
window.location.href = '/api/auth/trello/authorize'
|
window.location.href = '/api/auth/trello/authorize'
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if (providerId === 'shopify') {
|
if (providerId === 'shopify') {
|
||||||
// Pass the current URL so we can redirect back after OAuth
|
onClose()
|
||||||
const returnUrl = encodeURIComponent(window.location.href)
|
const returnUrl = encodeURIComponent(window.location.href)
|
||||||
window.location.href = `/api/auth/shopify/authorize?returnUrl=${returnUrl}`
|
window.location.href = `/api/auth/shopify/authorize?returnUrl=${returnUrl}`
|
||||||
return
|
return
|
||||||
@@ -374,8 +377,10 @@ export function OAuthRequiredModal({
|
|||||||
providerId,
|
providerId,
|
||||||
callbackURL: window.location.href,
|
callbackURL: window.location.href,
|
||||||
})
|
})
|
||||||
} catch (error) {
|
onClose()
|
||||||
logger.error('Error initiating OAuth flow:', { error })
|
} catch (err) {
|
||||||
|
logger.error('Error initiating OAuth flow:', { error: err })
|
||||||
|
setError('Failed to connect. Please try again.')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -425,10 +430,12 @@ export function OAuthRequiredModal({
|
|||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
|
{error && <p className='text-[12px] text-[var(--text-error)]'>{error}</p>}
|
||||||
</div>
|
</div>
|
||||||
</ModalBody>
|
</ModalBody>
|
||||||
<ModalFooter>
|
<ModalFooter>
|
||||||
<Button variant='active' onClick={onClose}>
|
<Button variant='default' onClick={onClose}>
|
||||||
Cancel
|
Cancel
|
||||||
</Button>
|
</Button>
|
||||||
<Button variant='tertiary' type='button' onClick={handleConnectDirectly}>
|
<Button variant='tertiary' type='button' onClick={handleConnectDirectly}>
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ interface DocumentSelectorProps {
|
|||||||
onDocumentSelect?: (documentId: string) => void
|
onDocumentSelect?: (documentId: string) => void
|
||||||
isPreview?: boolean
|
isPreview?: boolean
|
||||||
previewValue?: string | null
|
previewValue?: string | null
|
||||||
|
previewContextValues?: Record<string, unknown>
|
||||||
}
|
}
|
||||||
|
|
||||||
export function DocumentSelector({
|
export function DocumentSelector({
|
||||||
@@ -24,9 +25,15 @@ export function DocumentSelector({
|
|||||||
onDocumentSelect,
|
onDocumentSelect,
|
||||||
isPreview = false,
|
isPreview = false,
|
||||||
previewValue,
|
previewValue,
|
||||||
|
previewContextValues,
|
||||||
}: DocumentSelectorProps) {
|
}: DocumentSelectorProps) {
|
||||||
const { finalDisabled } = useDependsOnGate(blockId, subBlock, { disabled, isPreview })
|
const { finalDisabled } = useDependsOnGate(blockId, subBlock, {
|
||||||
const [knowledgeBaseIdValue] = useSubBlockValue(blockId, 'knowledgeBaseId')
|
disabled,
|
||||||
|
isPreview,
|
||||||
|
previewContextValues,
|
||||||
|
})
|
||||||
|
const [knowledgeBaseIdFromStore] = useSubBlockValue(blockId, 'knowledgeBaseId')
|
||||||
|
const knowledgeBaseIdValue = previewContextValues?.knowledgeBaseId ?? knowledgeBaseIdFromStore
|
||||||
const normalizedKnowledgeBaseId =
|
const normalizedKnowledgeBaseId =
|
||||||
typeof knowledgeBaseIdValue === 'string' && knowledgeBaseIdValue.trim().length > 0
|
typeof knowledgeBaseIdValue === 'string' && knowledgeBaseIdValue.trim().length > 0
|
||||||
? knowledgeBaseIdValue
|
? knowledgeBaseIdValue
|
||||||
|
|||||||
@@ -37,6 +37,7 @@ interface DocumentTagEntryProps {
|
|||||||
disabled?: boolean
|
disabled?: boolean
|
||||||
isPreview?: boolean
|
isPreview?: boolean
|
||||||
previewValue?: any
|
previewValue?: any
|
||||||
|
previewContextValues?: Record<string, unknown>
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -56,6 +57,7 @@ export function DocumentTagEntry({
|
|||||||
disabled = false,
|
disabled = false,
|
||||||
isPreview = false,
|
isPreview = false,
|
||||||
previewValue,
|
previewValue,
|
||||||
|
previewContextValues,
|
||||||
}: DocumentTagEntryProps) {
|
}: DocumentTagEntryProps) {
|
||||||
const [storeValue, setStoreValue] = useSubBlockValue<string>(blockId, subBlock.id)
|
const [storeValue, setStoreValue] = useSubBlockValue<string>(blockId, subBlock.id)
|
||||||
const accessiblePrefixes = useAccessibleReferencePrefixes(blockId)
|
const accessiblePrefixes = useAccessibleReferencePrefixes(blockId)
|
||||||
@@ -74,8 +76,12 @@ export function DocumentTagEntry({
|
|||||||
disabled,
|
disabled,
|
||||||
})
|
})
|
||||||
|
|
||||||
const [knowledgeBaseIdValue] = useSubBlockValue(blockId, 'knowledgeBaseId')
|
const [knowledgeBaseIdFromStore] = useSubBlockValue(blockId, 'knowledgeBaseId')
|
||||||
const knowledgeBaseId = knowledgeBaseIdValue || null
|
const knowledgeBaseIdValue = previewContextValues?.knowledgeBaseId ?? knowledgeBaseIdFromStore
|
||||||
|
const knowledgeBaseId =
|
||||||
|
typeof knowledgeBaseIdValue === 'string' && knowledgeBaseIdValue.trim().length > 0
|
||||||
|
? knowledgeBaseIdValue
|
||||||
|
: null
|
||||||
|
|
||||||
const { tagDefinitions, isLoading } = useKnowledgeBaseTagDefinitions(knowledgeBaseId)
|
const { tagDefinitions, isLoading } = useKnowledgeBaseTagDefinitions(knowledgeBaseId)
|
||||||
const emitTagSelection = useTagSelection(blockId, subBlock.id)
|
const emitTagSelection = useTagSelection(blockId, subBlock.id)
|
||||||
@@ -131,11 +137,16 @@ export function DocumentTagEntry({
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Removes a tag by ID (prevents removing the last tag)
|
* Removes a tag by ID, or resets it if it's the last one
|
||||||
*/
|
*/
|
||||||
const removeTag = (id: string) => {
|
const removeTag = (id: string) => {
|
||||||
if (isReadOnly || tags.length === 1) return
|
if (isReadOnly) return
|
||||||
updateTags(tags.filter((t) => t.id !== id))
|
if (tags.length === 1) {
|
||||||
|
// Reset the last tag instead of removing it
|
||||||
|
updateTags([createDefaultTag()])
|
||||||
|
} else {
|
||||||
|
updateTags(tags.filter((t) => t.id !== id))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -222,6 +233,7 @@ export function DocumentTagEntry({
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Renders the tag header with name, badge, and action buttons
|
* Renders the tag header with name, badge, and action buttons
|
||||||
|
* Shows tag name only when collapsed (as summary), generic label when expanded
|
||||||
*/
|
*/
|
||||||
const renderTagHeader = (tag: DocumentTag, index: number) => (
|
const renderTagHeader = (tag: DocumentTag, index: number) => (
|
||||||
<div
|
<div
|
||||||
@@ -230,9 +242,11 @@ export function DocumentTagEntry({
|
|||||||
>
|
>
|
||||||
<div className='flex min-w-0 flex-1 items-center gap-[8px]'>
|
<div className='flex min-w-0 flex-1 items-center gap-[8px]'>
|
||||||
<span className='block truncate font-medium text-[14px] text-[var(--text-tertiary)]'>
|
<span className='block truncate font-medium text-[14px] text-[var(--text-tertiary)]'>
|
||||||
{tag.tagName || `Tag ${index + 1}`}
|
{tag.collapsed ? tag.tagName || `Tag ${index + 1}` : `Tag ${index + 1}`}
|
||||||
</span>
|
</span>
|
||||||
{tag.tagName && <Badge size='sm'>{FIELD_TYPE_LABELS[tag.fieldType] || 'Text'}</Badge>}
|
{tag.collapsed && tag.tagName && (
|
||||||
|
<Badge size='sm'>{FIELD_TYPE_LABELS[tag.fieldType] || 'Text'}</Badge>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
<div className='flex items-center gap-[8px] pl-[8px]' onClick={(e) => e.stopPropagation()}>
|
<div className='flex items-center gap-[8px] pl-[8px]' onClick={(e) => e.stopPropagation()}>
|
||||||
<Button
|
<Button
|
||||||
@@ -247,7 +261,7 @@ export function DocumentTagEntry({
|
|||||||
<Button
|
<Button
|
||||||
variant='ghost'
|
variant='ghost'
|
||||||
onClick={() => removeTag(tag.id)}
|
onClick={() => removeTag(tag.id)}
|
||||||
disabled={isReadOnly || tags.length === 1}
|
disabled={isReadOnly}
|
||||||
className='h-auto p-0 text-[var(--text-error)] hover:text-[var(--text-error)]'
|
className='h-auto p-0 text-[var(--text-error)] hover:text-[var(--text-error)]'
|
||||||
>
|
>
|
||||||
<Trash className='h-[14px] w-[14px]' />
|
<Trash className='h-[14px] w-[14px]' />
|
||||||
@@ -341,7 +355,7 @@ export function DocumentTagEntry({
|
|||||||
|
|
||||||
const tagOptions: ComboboxOption[] = selectableTags.map((t) => ({
|
const tagOptions: ComboboxOption[] = selectableTags.map((t) => ({
|
||||||
value: t.displayName,
|
value: t.displayName,
|
||||||
label: `${t.displayName} (${FIELD_TYPE_LABELS[t.fieldType] || 'Text'})`,
|
label: t.displayName,
|
||||||
}))
|
}))
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
@@ -1,12 +1,16 @@
|
|||||||
import { useCallback, useEffect, useMemo, useRef, useState } from 'react'
|
import { memo, useCallback, useEffect, useMemo, useRef, useState } from 'react'
|
||||||
|
import { isEqual } from 'lodash'
|
||||||
import { Badge } from '@/components/emcn'
|
import { Badge } from '@/components/emcn'
|
||||||
import { Combobox, type ComboboxOption } from '@/components/emcn/components'
|
import { Combobox, type ComboboxOption } from '@/components/emcn/components'
|
||||||
|
import { buildCanonicalIndex, resolveDependencyValue } from '@/lib/workflows/subblocks/visibility'
|
||||||
import { useSubBlockValue } from '@/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/editor/components/sub-block/hooks/use-sub-block-value'
|
import { useSubBlockValue } from '@/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/editor/components/sub-block/hooks/use-sub-block-value'
|
||||||
|
import { getBlock } from '@/blocks/registry'
|
||||||
import type { SubBlockConfig } from '@/blocks/types'
|
import type { SubBlockConfig } from '@/blocks/types'
|
||||||
import { getDependsOnFields } from '@/blocks/utils'
|
import { getDependsOnFields } from '@/blocks/utils'
|
||||||
import { ResponseBlockHandler } from '@/executor/handlers/response/response-handler'
|
import { ResponseBlockHandler } from '@/executor/handlers/response/response-handler'
|
||||||
import { useWorkflowRegistry } from '@/stores/workflows/registry/store'
|
import { useWorkflowRegistry } from '@/stores/workflows/registry/store'
|
||||||
import { useSubBlockStore } from '@/stores/workflows/subblock/store'
|
import { useSubBlockStore } from '@/stores/workflows/subblock/store'
|
||||||
|
import { useWorkflowStore } from '@/stores/workflows/workflow/store'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Dropdown option type - can be a simple string or an object with label, id, and optional icon
|
* Dropdown option type - can be a simple string or an object with label, id, and optional icon
|
||||||
@@ -65,7 +69,7 @@ interface DropdownProps {
|
|||||||
* - Special handling for dataMode subblock to convert between JSON and structured formats
|
* - Special handling for dataMode subblock to convert between JSON and structured formats
|
||||||
* - Integrates with the workflow state management system
|
* - Integrates with the workflow state management system
|
||||||
*/
|
*/
|
||||||
export function Dropdown({
|
export const Dropdown = memo(function Dropdown({
|
||||||
options,
|
options,
|
||||||
defaultValue,
|
defaultValue,
|
||||||
blockId,
|
blockId,
|
||||||
@@ -89,16 +93,26 @@ export function Dropdown({
|
|||||||
const dependsOnFields = useMemo(() => getDependsOnFields(dependsOn), [dependsOn])
|
const dependsOnFields = useMemo(() => getDependsOnFields(dependsOn), [dependsOn])
|
||||||
|
|
||||||
const activeWorkflowId = useWorkflowRegistry((s) => s.activeWorkflowId)
|
const activeWorkflowId = useWorkflowRegistry((s) => s.activeWorkflowId)
|
||||||
|
const blockState = useWorkflowStore((state) => state.blocks[blockId])
|
||||||
|
const blockConfig = blockState?.type ? getBlock(blockState.type) : null
|
||||||
|
const canonicalIndex = useMemo(
|
||||||
|
() => buildCanonicalIndex(blockConfig?.subBlocks || []),
|
||||||
|
[blockConfig?.subBlocks]
|
||||||
|
)
|
||||||
|
const canonicalModeOverrides = blockState?.data?.canonicalModes
|
||||||
const dependencyValues = useSubBlockStore(
|
const dependencyValues = useSubBlockStore(
|
||||||
useCallback(
|
useCallback(
|
||||||
(state) => {
|
(state) => {
|
||||||
if (dependsOnFields.length === 0 || !activeWorkflowId) return []
|
if (dependsOnFields.length === 0 || !activeWorkflowId) return []
|
||||||
const workflowValues = state.workflowValues[activeWorkflowId] || {}
|
const workflowValues = state.workflowValues[activeWorkflowId] || {}
|
||||||
const blockValues = workflowValues[blockId] || {}
|
const blockValues = workflowValues[blockId] || {}
|
||||||
return dependsOnFields.map((depKey) => blockValues[depKey] ?? null)
|
return dependsOnFields.map((depKey) =>
|
||||||
|
resolveDependencyValue(depKey, blockValues, canonicalIndex, canonicalModeOverrides)
|
||||||
|
)
|
||||||
},
|
},
|
||||||
[dependsOnFields, activeWorkflowId, blockId]
|
[dependsOnFields, activeWorkflowId, blockId, canonicalIndex, canonicalModeOverrides]
|
||||||
)
|
),
|
||||||
|
isEqual
|
||||||
)
|
)
|
||||||
|
|
||||||
const [storeInitialized, setStoreInitialized] = useState(false)
|
const [storeInitialized, setStoreInitialized] = useState(false)
|
||||||
@@ -149,6 +163,18 @@ export function Dropdown({
|
|||||||
}
|
}
|
||||||
}, [fetchOptions, blockId, subBlockId, isPreview, disabled])
|
}, [fetchOptions, blockId, subBlockId, isPreview, disabled])
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handles combobox open state changes to trigger option fetching
|
||||||
|
*/
|
||||||
|
const handleOpenChange = useCallback(
|
||||||
|
(open: boolean) => {
|
||||||
|
if (open) {
|
||||||
|
void fetchOptionsIfNeeded()
|
||||||
|
}
|
||||||
|
},
|
||||||
|
[fetchOptionsIfNeeded]
|
||||||
|
)
|
||||||
|
|
||||||
const evaluatedOptions = useMemo(() => {
|
const evaluatedOptions = useMemo(() => {
|
||||||
return typeof options === 'function' ? options() : options
|
return typeof options === 'function' ? options() : options
|
||||||
}, [options])
|
}, [options])
|
||||||
@@ -459,11 +485,7 @@ export function Dropdown({
|
|||||||
placeholder={placeholder}
|
placeholder={placeholder}
|
||||||
disabled={disabled}
|
disabled={disabled}
|
||||||
editable={false}
|
editable={false}
|
||||||
onOpenChange={(open) => {
|
onOpenChange={handleOpenChange}
|
||||||
if (open) {
|
|
||||||
void fetchOptionsIfNeeded()
|
|
||||||
}
|
|
||||||
}}
|
|
||||||
overlayContent={multiSelectOverlay}
|
overlayContent={multiSelectOverlay}
|
||||||
multiSelect={multiSelect}
|
multiSelect={multiSelect}
|
||||||
isLoading={isLoadingOptions}
|
isLoading={isLoadingOptions}
|
||||||
@@ -472,4 +494,4 @@ export function Dropdown({
|
|||||||
searchPlaceholder='Search...'
|
searchPlaceholder='Search...'
|
||||||
/>
|
/>
|
||||||
)
|
)
|
||||||
}
|
})
|
||||||
|
|||||||
@@ -4,15 +4,19 @@ import { useMemo } from 'react'
|
|||||||
import { useParams } from 'next/navigation'
|
import { useParams } from 'next/navigation'
|
||||||
import { Tooltip } from '@/components/emcn'
|
import { Tooltip } from '@/components/emcn'
|
||||||
import { getProviderIdFromServiceId } from '@/lib/oauth'
|
import { getProviderIdFromServiceId } from '@/lib/oauth'
|
||||||
|
import { buildCanonicalIndex, resolveDependencyValue } from '@/lib/workflows/subblocks/visibility'
|
||||||
import { SelectorCombobox } from '@/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/editor/components/sub-block/components/selector-combobox/selector-combobox'
|
import { SelectorCombobox } from '@/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/editor/components/sub-block/components/selector-combobox/selector-combobox'
|
||||||
import { useDependsOnGate } from '@/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/editor/components/sub-block/hooks/use-depends-on-gate'
|
import { useDependsOnGate } from '@/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/editor/components/sub-block/hooks/use-depends-on-gate'
|
||||||
import { useForeignCredential } from '@/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/editor/components/sub-block/hooks/use-foreign-credential'
|
import { useForeignCredential } from '@/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/editor/components/sub-block/hooks/use-foreign-credential'
|
||||||
import { useSubBlockValue } from '@/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/editor/components/sub-block/hooks/use-sub-block-value'
|
import { useSubBlockValue } from '@/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/editor/components/sub-block/hooks/use-sub-block-value'
|
||||||
|
import { getBlock } from '@/blocks/registry'
|
||||||
import type { SubBlockConfig } from '@/blocks/types'
|
import type { SubBlockConfig } from '@/blocks/types'
|
||||||
import { isDependency } from '@/blocks/utils'
|
import { isDependency } from '@/blocks/utils'
|
||||||
import { resolveSelectorForSubBlock, type SelectorResolution } from '@/hooks/selectors/resolution'
|
import { resolveSelectorForSubBlock, type SelectorResolution } from '@/hooks/selectors/resolution'
|
||||||
import { useCollaborativeWorkflow } from '@/hooks/use-collaborative-workflow'
|
import { useCollaborativeWorkflow } from '@/hooks/use-collaborative-workflow'
|
||||||
import { useWorkflowRegistry } from '@/stores/workflows/registry/store'
|
import { useWorkflowRegistry } from '@/stores/workflows/registry/store'
|
||||||
|
import { useSubBlockStore } from '@/stores/workflows/subblock/store'
|
||||||
|
import { useWorkflowStore } from '@/stores/workflows/workflow/store'
|
||||||
|
|
||||||
interface FileSelectorInputProps {
|
interface FileSelectorInputProps {
|
||||||
blockId: string
|
blockId: string
|
||||||
@@ -42,21 +46,59 @@ export function FileSelectorInput({
|
|||||||
previewContextValues,
|
previewContextValues,
|
||||||
})
|
})
|
||||||
|
|
||||||
const [connectedCredentialFromStore] = useSubBlockValue(blockId, 'credential')
|
const blockState = useWorkflowStore((state) => state.blocks[blockId])
|
||||||
const [domainValueFromStore] = useSubBlockValue(blockId, 'domain')
|
const blockConfig = blockState?.type ? getBlock(blockState.type) : null
|
||||||
const [projectIdValueFromStore] = useSubBlockValue(blockId, 'projectId')
|
const canonicalIndex = useMemo(
|
||||||
const [planIdValueFromStore] = useSubBlockValue(blockId, 'planId')
|
() => buildCanonicalIndex(blockConfig?.subBlocks || []),
|
||||||
const [teamIdValueFromStore] = useSubBlockValue(blockId, 'teamId')
|
[blockConfig?.subBlocks]
|
||||||
const [siteIdValueFromStore] = useSubBlockValue(blockId, 'siteId')
|
)
|
||||||
const [collectionIdValueFromStore] = useSubBlockValue(blockId, 'collectionId')
|
const canonicalModeOverrides = blockState?.data?.canonicalModes
|
||||||
|
|
||||||
const connectedCredential = previewContextValues?.credential ?? connectedCredentialFromStore
|
const blockValues = useSubBlockStore((state) => {
|
||||||
|
if (!activeWorkflowId) return {}
|
||||||
|
const workflowValues = state.workflowValues[activeWorkflowId] || {}
|
||||||
|
return (workflowValues as Record<string, Record<string, unknown>>)[blockId] || {}
|
||||||
|
})
|
||||||
|
|
||||||
|
const [domainValueFromStore] = useSubBlockValue(blockId, 'domain')
|
||||||
|
|
||||||
|
const connectedCredential = previewContextValues?.credential ?? blockValues.credential
|
||||||
const domainValue = previewContextValues?.domain ?? domainValueFromStore
|
const domainValue = previewContextValues?.domain ?? domainValueFromStore
|
||||||
const projectIdValue = previewContextValues?.projectId ?? projectIdValueFromStore
|
|
||||||
const planIdValue = previewContextValues?.planId ?? planIdValueFromStore
|
const teamIdValue = useMemo(
|
||||||
const teamIdValue = previewContextValues?.teamId ?? teamIdValueFromStore
|
() =>
|
||||||
const siteIdValue = previewContextValues?.siteId ?? siteIdValueFromStore
|
previewContextValues?.teamId ??
|
||||||
const collectionIdValue = previewContextValues?.collectionId ?? collectionIdValueFromStore
|
resolveDependencyValue('teamId', blockValues, canonicalIndex, canonicalModeOverrides),
|
||||||
|
[previewContextValues?.teamId, blockValues, canonicalIndex, canonicalModeOverrides]
|
||||||
|
)
|
||||||
|
|
||||||
|
const siteIdValue = useMemo(
|
||||||
|
() =>
|
||||||
|
previewContextValues?.siteId ??
|
||||||
|
resolveDependencyValue('siteId', blockValues, canonicalIndex, canonicalModeOverrides),
|
||||||
|
[previewContextValues?.siteId, blockValues, canonicalIndex, canonicalModeOverrides]
|
||||||
|
)
|
||||||
|
|
||||||
|
const collectionIdValue = useMemo(
|
||||||
|
() =>
|
||||||
|
previewContextValues?.collectionId ??
|
||||||
|
resolveDependencyValue('collectionId', blockValues, canonicalIndex, canonicalModeOverrides),
|
||||||
|
[previewContextValues?.collectionId, blockValues, canonicalIndex, canonicalModeOverrides]
|
||||||
|
)
|
||||||
|
|
||||||
|
const projectIdValue = useMemo(
|
||||||
|
() =>
|
||||||
|
previewContextValues?.projectId ??
|
||||||
|
resolveDependencyValue('projectId', blockValues, canonicalIndex, canonicalModeOverrides),
|
||||||
|
[previewContextValues?.projectId, blockValues, canonicalIndex, canonicalModeOverrides]
|
||||||
|
)
|
||||||
|
|
||||||
|
const planIdValue = useMemo(
|
||||||
|
() =>
|
||||||
|
previewContextValues?.planId ??
|
||||||
|
resolveDependencyValue('planId', blockValues, canonicalIndex, canonicalModeOverrides),
|
||||||
|
[previewContextValues?.planId, blockValues, canonicalIndex, canonicalModeOverrides]
|
||||||
|
)
|
||||||
|
|
||||||
const normalizedCredentialId =
|
const normalizedCredentialId =
|
||||||
typeof connectedCredential === 'string'
|
typeof connectedCredential === 'string'
|
||||||
@@ -65,7 +107,6 @@ export function FileSelectorInput({
|
|||||||
? ((connectedCredential as Record<string, any>).id ?? '')
|
? ((connectedCredential as Record<string, any>).id ?? '')
|
||||||
: ''
|
: ''
|
||||||
|
|
||||||
// Derive provider from serviceId using OAuth config (same pattern as credential-selector)
|
|
||||||
const serviceId = subBlock.serviceId || ''
|
const serviceId = subBlock.serviceId || ''
|
||||||
const effectiveProviderId = useMemo(() => getProviderIdFromServiceId(serviceId), [serviceId])
|
const effectiveProviderId = useMemo(() => getProviderIdFromServiceId(serviceId), [serviceId])
|
||||||
|
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user