Skip to content

Commit 9854e43

Browse files
committed
Plan prompt
1 parent 6635249 commit 9854e43

File tree

3 files changed

+20
-8
lines changed

3 files changed

+20
-8
lines changed

apps/sim/lib/copilot/orchestrator/stream/core.ts

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import { createLogger } from '@sim/logger'
2+
import { getHighestPrioritySubscription } from '@/lib/billing/core/plan'
3+
import { isPaid } from '@/lib/billing/plan-helpers'
24
import { ORCHESTRATION_TIMEOUT_MS } from '@/lib/copilot/constants'
35
import {
46
handleSubagentRouting,
@@ -80,16 +82,28 @@ export async function runStreamLoop(
8082
const errorText = await response.text().catch(() => '')
8183

8284
if (response.status === 402) {
85+
let action = 'upgrade_plan'
86+
let message = "You've reached your usage limit. Please upgrade your plan to continue."
87+
try {
88+
const sub = await getHighestPrioritySubscription(execContext.userId)
89+
if (sub && isPaid(sub.plan)) {
90+
action = 'increase_limit'
91+
message =
92+
"You've reached your usage limit for this billing period. Please increase your usage limit to continue."
93+
}
94+
} catch {
95+
// Fall back to upgrade_plan if we can't determine the plan
96+
}
97+
8398
const upgradePayload = JSON.stringify({
8499
reason: 'usage_limit',
85-
action: 'increase_limit',
86-
message:
87-
"You've reached your usage limit for this billing period. Please upgrade your plan or increase your usage limit to continue.",
100+
action,
101+
message,
88102
})
89103
const syntheticContent = `<usage_upgrade>${upgradePayload}</usage_upgrade>`
90104

91105
const syntheticEvents: SSEEvent[] = [
92-
{ type: 'content', data: syntheticContent },
106+
{ type: 'content', data: syntheticContent as unknown as Record<string, unknown> },
93107
{ type: 'done', data: {} },
94108
]
95109
for (const event of syntheticEvents) {

apps/sim/lib/copilot/tool-descriptions.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,5 @@ export function getCopilotToolDescription(
1919
return baseDescription
2020
}
2121

22-
return baseDescription
23-
? `${baseDescription} ${HOSTED_API_KEY_NOTE}`
24-
: HOSTED_API_KEY_NOTE
22+
return baseDescription ? `${baseDescription} ${HOSTED_API_KEY_NOTE}` : HOSTED_API_KEY_NOTE
2523
}

apps/sim/lib/copilot/vfs/serializers.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { isHosted } from '@/lib/core/config/feature-flags'
21
import { getCopilotToolDescription } from '@/lib/copilot/tool-descriptions'
2+
import { isHosted } from '@/lib/core/config/feature-flags'
33
import { isSubBlockHiddenByHostedKey } from '@/lib/workflows/subblocks/visibility'
44
import type { BlockConfig, SubBlockConfig } from '@/blocks/types'
55
import { PROVIDER_DEFINITIONS } from '@/providers/models'

0 commit comments

Comments
 (0)