Skip to content

Commit 443e15e

Browse files
committed
Jobs
1 parent 7140867 commit 443e15e

File tree

5 files changed

+60
-22
lines changed

5 files changed

+60
-22
lines changed

apps/sim/app/workspace/[workspaceId]/schedules/components/schedules-view.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ export function SchedulesView() {
138138
const ws: WorkspaceScheduleData[] = []
139139
const j: WorkspaceScheduleData[] = []
140140
for (const item of allItems) {
141+
if (item.status === 'completed') continue
141142
if (item.sourceType === 'job') j.push(item)
142143
else ws.push(item)
143144
}

apps/sim/hooks/queries/schedules.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export const scheduleKeys = {
1414

1515
export interface ScheduleData {
1616
id: string
17-
status: 'active' | 'disabled'
17+
status: 'active' | 'disabled' | 'completed'
1818
cronExpression: string | null
1919
nextRunAt: string | null
2020
lastRanAt: string | null
@@ -37,7 +37,7 @@ export interface WorkspaceScheduleData extends ScheduleData {
3737

3838
export interface ScheduleInfo {
3939
id: string
40-
status: 'active' | 'disabled'
40+
status: 'active' | 'disabled' | 'completed'
4141
scheduleTiming: string
4242
nextRunAt: string | null
4343
lastRanAt: string | null

apps/sim/lib/copilot/vfs/workspace-vfs.ts

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { db } from '@sim/db'
22
import {
33
a2aAgent,
4-
account,
54
chat as chatTable,
65
copilotChats,
76
document,
@@ -45,7 +44,10 @@ import {
4544
serializeWorkflowMeta,
4645
} from '@/lib/copilot/vfs/serializers'
4746
import { type WorkspaceMdData, buildWorkspaceMd } from '@/lib/copilot/workspace-context'
48-
import { getAccessibleEnvCredentials } from '@/lib/credentials/environment'
47+
import {
48+
getAccessibleEnvCredentials,
49+
getAccessibleOAuthCredentials,
50+
} from '@/lib/credentials/environment'
4951
import { getPersonalAndWorkspaceEnv } from '@/lib/environment/utils'
5052
import { getKnowledgeBases } from '@/lib/knowledge/service'
5153
import { listTables } from '@/lib/table/service'
@@ -1017,25 +1019,27 @@ export class WorkspaceVFS {
10171019
userId: string
10181020
): Promise<WorkspaceMdData['credentials']> {
10191021
try {
1020-
const [envCredentials, apiKeyRows, envData, oauthAccounts] = await Promise.all([
1022+
const [envCredentials, oauthCredentials, apiKeyRows, envData] = await Promise.all([
10211023
getAccessibleEnvCredentials(workspaceId, userId),
1024+
getAccessibleOAuthCredentials(workspaceId, userId),
10221025
listApiKeys(workspaceId),
10231026
getPersonalAndWorkspaceEnv(userId, workspaceId),
1024-
db
1025-
.select({ providerId: account.providerId })
1026-
.from(account)
1027-
.where(eq(account.userId, userId)),
10281027
])
10291028

10301029
this.files.set(
10311030
'environment/credentials.json',
1032-
serializeCredentials(
1033-
envCredentials.map((c) => ({
1031+
serializeCredentials([
1032+
...envCredentials.map((c) => ({
10341033
providerId: c.envKey,
10351034
scope: c.type === 'env_workspace' ? 'workspace' : 'personal',
10361035
createdAt: c.updatedAt,
1037-
}))
1038-
)
1036+
})),
1037+
...oauthCredentials.map((c) => ({
1038+
providerId: c.providerId,
1039+
scope: null,
1040+
createdAt: c.updatedAt,
1041+
})),
1042+
])
10391043
)
10401044

10411045
this.files.set('environment/api-keys.json', serializeApiKeys(apiKeyRows))
@@ -1048,7 +1052,7 @@ export class WorkspaceVFS {
10481052
)
10491053

10501054
const envKeys = envCredentials.map((c) => c.envKey)
1051-
const oauthProviders = oauthAccounts.map((a) => a.providerId)
1055+
const oauthProviders = oauthCredentials.map((c) => c.providerId)
10521056
const allProviders = [...new Set([...oauthProviders, ...envKeys])]
10531057
return allProviders.map((key) => ({ providerId: key }))
10541058
} catch (err) {

apps/sim/lib/copilot/workspace-context.ts

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import { db } from '@sim/db'
2-
import { account, copilotChats, knowledgeBase, mcpServers, userTableDefinitions, userTableRows, workflow, workspace, workflowSchedule } from '@sim/db/schema'
2+
import { copilotChats, knowledgeBase, mcpServers, userTableDefinitions, userTableRows, workflow, workspace, workflowSchedule } from '@sim/db/schema'
33
import { createLogger } from '@sim/logger'
44
import { and, count, desc, eq, isNull } from 'drizzle-orm'
5+
import { getAccessibleOAuthCredentials } from '@/lib/credentials/environment'
56
import { listWorkspaceFiles } from '@/lib/uploads/contexts/workspace'
67
import { listCustomTools } from '@/lib/workflows/custom-tools/operations'
78
import { listSkills } from '@/lib/workflows/skills/operations'
@@ -205,13 +206,7 @@ export async function generateWorkspaceContext(
205206

206207
listWorkspaceFiles(workspaceId),
207208

208-
db
209-
.select({
210-
providerId: account.providerId,
211-
scope: account.scope,
212-
})
213-
.from(account)
214-
.where(eq(account.userId, userId)),
209+
getAccessibleOAuthCredentials(workspaceId, userId),
215210

216211
db
217212
.select({

apps/sim/lib/credentials/environment.ts

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,3 +358,41 @@ export async function getAccessibleEnvCredentials(
358358
updatedAt: row.updatedAt,
359359
}))
360360
}
361+
362+
export interface AccessibleOAuthCredential {
363+
providerId: string
364+
displayName: string
365+
updatedAt: Date
366+
}
367+
368+
export async function getAccessibleOAuthCredentials(
369+
workspaceId: string,
370+
userId: string
371+
): Promise<AccessibleOAuthCredential[]> {
372+
const rows = await db
373+
.select({
374+
providerId: credential.providerId,
375+
displayName: credential.displayName,
376+
updatedAt: credential.updatedAt,
377+
})
378+
.from(credential)
379+
.innerJoin(
380+
credentialMember,
381+
and(
382+
eq(credentialMember.credentialId, credential.id),
383+
eq(credentialMember.userId, userId),
384+
eq(credentialMember.status, 'active')
385+
)
386+
)
387+
.where(
388+
and(eq(credential.workspaceId, workspaceId), eq(credential.type, 'oauth'))
389+
)
390+
391+
return rows
392+
.filter((row): row is AccessibleOAuthCredential => Boolean(row.providerId))
393+
.map((row) => ({
394+
providerId: row.providerId!,
395+
displayName: row.displayName,
396+
updatedAt: row.updatedAt,
397+
}))
398+
}

0 commit comments

Comments
 (0)