Skip to content

Commit 3b98253

Browse files
waleedlatif1aadamgoughAdam Goughicecrasher321Vikhyath Mondreti
authored
v0.2.5: feat, improvement, fix (#595) (#603)
* feat(function): added more granular error logs for function execution for easier debugging (#593) * added more granular error logs for function execution * added tests * fixed syntax error reporting * feat(models): added temp controls for gpt-4.1 family of models (#594) * improvement(knowledge-upload): create and upload document to KB (#579) * improvement: added knowledge upload * improvement: added greptile comments (#579) * improvement: changed to text to doc (#579) * improvement: removed comment (#579) * added input validation, tested persistence of KB selector * update docs --------- Co-authored-by: Adam Gough <[email protected]> Co-authored-by: Waleed Latif <[email protected]> * fix(remove workflow.state usage): no more usage of deprecated state column in any routes (#586) * fix(remove workflow.state usage): no more usage of deprecated state col in routes * fix lint * fix chat route to only use deployed state * fix lint * better typing * remove useless logs * fix lint * restore workflow handler file * removed all other usages of deprecated 'state' column from workflows table, updated tests --------- Co-authored-by: Vikhyath Mondreti <[email protected]> Co-authored-by: Waleed Latif <[email protected]> * fix(doc-selector-kb): enable doc selector when kb is selected (#596) Co-authored-by: Vikhyath Mondreti <[email protected]> * fix(unload): remove beforeunload warning since we communicate via wss (#597) * fix(executor): fix dependency resolution, allow blocks with multiple inputs to execute (#598) * feat(billing): added migrations for usage-based billing (#601) * feat(billing): added migrations for usage-based billing * lint * lint * feat(logging): add new schemas + types for new logging system (#599) * feat(logging): add new schemas + types for logging * fix lint * update migration * fix lint * Remove migration 48 to avoid conflict with staging * fixed merge conflict * fix lint --------- Co-authored-by: Vikhyath Mondreti <[email protected]> --------- Co-authored-by: Adam Gough <[email protected]> Co-authored-by: Adam Gough <[email protected]> Co-authored-by: Vikhyath Mondreti <[email protected]> Co-authored-by: Vikhyath Mondreti <[email protected]> Co-authored-by: Vikhyath Mondreti <[email protected]> Co-authored-by: Vikhyath Mondreti <[email protected]>
1 parent 1604ce4 commit 3b98253

File tree

13 files changed

+9355
-102
lines changed

13 files changed

+9355
-102
lines changed

apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/workflow-block/components/sub-block/components/document-selector/document-selector.tsx

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use client'
22

3-
import { useCallback, useEffect, useMemo, useState } from 'react'
3+
import { useCallback, useEffect, useState } from 'react'
44
import { Check, ChevronDown, FileText } from 'lucide-react'
55
import { Button } from '@/components/ui/button'
66
import {
@@ -13,7 +13,6 @@ import {
1313
} from '@/components/ui/command'
1414
import { Popover, PopoverContent, PopoverTrigger } from '@/components/ui/popover'
1515
import type { SubBlockConfig } from '@/blocks/types'
16-
import { useSubBlockStore } from '@/stores/workflows/subblock/store'
1716
import { useSubBlockValue } from '../../hooks/use-sub-block-value'
1817

1918
interface DocumentData {
@@ -51,19 +50,16 @@ export function DocumentSelector({
5150
isPreview = false,
5251
previewValue,
5352
}: DocumentSelectorProps) {
54-
const { getValue } = useSubBlockStore()
55-
5653
const [documents, setDocuments] = useState<DocumentData[]>([])
5754
const [error, setError] = useState<string | null>(null)
5855
const [open, setOpen] = useState(false)
5956
const [selectedDocument, setSelectedDocument] = useState<DocumentData | null>(null)
60-
const [initialFetchDone, setInitialFetchDone] = useState(false)
6157

6258
// Use the proper hook to get the current value and setter
6359
const [storeValue, setStoreValue] = useSubBlockValue(blockId, subBlock.id)
6460

65-
// Get the knowledge base ID from the same block's knowledgeBaseId subblock - memoize to prevent re-renders
66-
const knowledgeBaseId = useMemo(() => getValue(blockId, 'knowledgeBaseId'), [getValue, blockId])
61+
// Get the knowledge base ID from the same block's knowledgeBaseId subblock
62+
const [knowledgeBaseId] = useSubBlockValue(blockId, 'knowledgeBaseId')
6763

6864
// Use preview value when in preview mode, otherwise use store value
6965
const value = isPreview ? previewValue : storeValue
@@ -73,7 +69,6 @@ export function DocumentSelector({
7369
if (!knowledgeBaseId) {
7470
setDocuments([])
7571
setError('No knowledge base selected')
76-
setInitialFetchDone(true)
7772
return
7873
}
7974

@@ -94,7 +89,6 @@ export function DocumentSelector({
9489

9590
const fetchedDocuments = result.data || []
9691
setDocuments(fetchedDocuments)
97-
setInitialFetchDone(true)
9892
} catch (err) {
9993
if ((err as Error).name === 'AbortError') return
10094
setError((err as Error).message)
@@ -138,16 +132,15 @@ export function DocumentSelector({
138132
useEffect(() => {
139133
setDocuments([])
140134
setSelectedDocument(null)
141-
setInitialFetchDone(false)
142135
setError(null)
143136
}, [knowledgeBaseId])
144137

145-
// Fetch documents when knowledge base is available and we haven't fetched yet
138+
// Fetch documents when knowledge base is available
146139
useEffect(() => {
147-
if (knowledgeBaseId && !initialFetchDone && !isPreview) {
140+
if (knowledgeBaseId && !isPreview) {
148141
fetchDocuments()
149142
}
150-
}, [knowledgeBaseId, initialFetchDone, isPreview, fetchDocuments])
143+
}, [knowledgeBaseId, isPreview, fetchDocuments])
151144

152145
const formatDocumentName = (document: DocumentData) => {
153146
return document.filename
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
ALTER TABLE "user_stats" ADD COLUMN "current_usage_limit" numeric DEFAULT '5' NOT NULL;--> statement-breakpoint
2+
ALTER TABLE "user_stats" ADD COLUMN "usage_limit_set_by" text;--> statement-breakpoint
3+
ALTER TABLE "user_stats" ADD COLUMN "usage_limit_updated_at" timestamp DEFAULT now();--> statement-breakpoint
4+
ALTER TABLE "user_stats" ADD COLUMN "current_period_cost" numeric DEFAULT '0' NOT NULL;--> statement-breakpoint
5+
ALTER TABLE "user_stats" ADD COLUMN "billing_period_start" timestamp DEFAULT now();--> statement-breakpoint
6+
ALTER TABLE "user_stats" ADD COLUMN "billing_period_end" timestamp;--> statement-breakpoint
7+
ALTER TABLE "user_stats" ADD COLUMN "last_period_cost" numeric DEFAULT '0';--> statement-breakpoint
8+
CREATE INDEX "subscription_reference_status_idx" ON "subscription" USING btree ("reference_id","status");--> statement-breakpoint
9+
ALTER TABLE "subscription" ADD CONSTRAINT "check_enterprise_metadata" CHECK (plan != 'enterprise' OR (metadata IS NOT NULL AND (metadata->>'perSeatAllowance' IS NOT NULL OR metadata->>'totalAllowance' IS NOT NULL)));
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
CREATE TABLE "workflow_execution_blocks" (
2+
"id" text PRIMARY KEY NOT NULL,
3+
"execution_id" text NOT NULL,
4+
"workflow_id" text NOT NULL,
5+
"block_id" text NOT NULL,
6+
"block_name" text,
7+
"block_type" text NOT NULL,
8+
"started_at" timestamp NOT NULL,
9+
"ended_at" timestamp,
10+
"duration_ms" integer,
11+
"status" text NOT NULL,
12+
"error_message" text,
13+
"error_stack_trace" text,
14+
"input_data" jsonb,
15+
"output_data" jsonb,
16+
"cost_input" numeric(10, 6),
17+
"cost_output" numeric(10, 6),
18+
"cost_total" numeric(10, 6),
19+
"tokens_prompt" integer,
20+
"tokens_completion" integer,
21+
"tokens_total" integer,
22+
"model_used" text,
23+
"metadata" jsonb,
24+
"created_at" timestamp DEFAULT now() NOT NULL
25+
);
26+
--> statement-breakpoint
27+
CREATE TABLE "workflow_execution_logs" (
28+
"id" text PRIMARY KEY NOT NULL,
29+
"workflow_id" text NOT NULL,
30+
"execution_id" text NOT NULL,
31+
"state_snapshot_id" text NOT NULL,
32+
"level" text NOT NULL,
33+
"message" text NOT NULL,
34+
"trigger" text NOT NULL,
35+
"started_at" timestamp NOT NULL,
36+
"ended_at" timestamp,
37+
"total_duration_ms" integer,
38+
"block_count" integer DEFAULT 0 NOT NULL,
39+
"success_count" integer DEFAULT 0 NOT NULL,
40+
"error_count" integer DEFAULT 0 NOT NULL,
41+
"skipped_count" integer DEFAULT 0 NOT NULL,
42+
"total_cost" numeric(10, 6),
43+
"total_input_cost" numeric(10, 6),
44+
"total_output_cost" numeric(10, 6),
45+
"total_tokens" integer,
46+
"metadata" jsonb DEFAULT '{}' NOT NULL,
47+
"created_at" timestamp DEFAULT now() NOT NULL
48+
);
49+
--> statement-breakpoint
50+
CREATE TABLE "workflow_execution_snapshots" (
51+
"id" text PRIMARY KEY NOT NULL,
52+
"workflow_id" text NOT NULL,
53+
"state_hash" text NOT NULL,
54+
"state_data" jsonb NOT NULL,
55+
"created_at" timestamp DEFAULT now() NOT NULL
56+
);
57+
--> statement-breakpoint
58+
ALTER TABLE "workflow_execution_blocks" ADD CONSTRAINT "workflow_execution_blocks_workflow_id_workflow_id_fk" FOREIGN KEY ("workflow_id") REFERENCES "public"."workflow"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
59+
ALTER TABLE "workflow_execution_logs" ADD CONSTRAINT "workflow_execution_logs_workflow_id_workflow_id_fk" FOREIGN KEY ("workflow_id") REFERENCES "public"."workflow"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
60+
ALTER TABLE "workflow_execution_logs" ADD CONSTRAINT "workflow_execution_logs_state_snapshot_id_workflow_execution_snapshots_id_fk" FOREIGN KEY ("state_snapshot_id") REFERENCES "public"."workflow_execution_snapshots"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
61+
ALTER TABLE "workflow_execution_snapshots" ADD CONSTRAINT "workflow_execution_snapshots_workflow_id_workflow_id_fk" FOREIGN KEY ("workflow_id") REFERENCES "public"."workflow"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
62+
CREATE INDEX "execution_blocks_execution_id_idx" ON "workflow_execution_blocks" USING btree ("execution_id");--> statement-breakpoint
63+
CREATE INDEX "execution_blocks_workflow_id_idx" ON "workflow_execution_blocks" USING btree ("workflow_id");--> statement-breakpoint
64+
CREATE INDEX "execution_blocks_block_id_idx" ON "workflow_execution_blocks" USING btree ("block_id");--> statement-breakpoint
65+
CREATE INDEX "execution_blocks_status_idx" ON "workflow_execution_blocks" USING btree ("status");--> statement-breakpoint
66+
CREATE INDEX "execution_blocks_duration_idx" ON "workflow_execution_blocks" USING btree ("duration_ms");--> statement-breakpoint
67+
CREATE INDEX "execution_blocks_cost_idx" ON "workflow_execution_blocks" USING btree ("cost_total");--> statement-breakpoint
68+
CREATE INDEX "execution_blocks_workflow_execution_idx" ON "workflow_execution_blocks" USING btree ("workflow_id","execution_id");--> statement-breakpoint
69+
CREATE INDEX "execution_blocks_execution_status_idx" ON "workflow_execution_blocks" USING btree ("execution_id","status");--> statement-breakpoint
70+
CREATE INDEX "execution_blocks_started_at_idx" ON "workflow_execution_blocks" USING btree ("started_at");--> statement-breakpoint
71+
CREATE INDEX "workflow_execution_logs_workflow_id_idx" ON "workflow_execution_logs" USING btree ("workflow_id");--> statement-breakpoint
72+
CREATE INDEX "workflow_execution_logs_execution_id_idx" ON "workflow_execution_logs" USING btree ("execution_id");--> statement-breakpoint
73+
CREATE INDEX "workflow_execution_logs_trigger_idx" ON "workflow_execution_logs" USING btree ("trigger");--> statement-breakpoint
74+
CREATE INDEX "workflow_execution_logs_level_idx" ON "workflow_execution_logs" USING btree ("level");--> statement-breakpoint
75+
CREATE INDEX "workflow_execution_logs_started_at_idx" ON "workflow_execution_logs" USING btree ("started_at");--> statement-breakpoint
76+
CREATE INDEX "workflow_execution_logs_cost_idx" ON "workflow_execution_logs" USING btree ("total_cost");--> statement-breakpoint
77+
CREATE INDEX "workflow_execution_logs_duration_idx" ON "workflow_execution_logs" USING btree ("total_duration_ms");--> statement-breakpoint
78+
CREATE UNIQUE INDEX "workflow_execution_logs_execution_id_unique" ON "workflow_execution_logs" USING btree ("execution_id");--> statement-breakpoint
79+
CREATE INDEX "workflow_snapshots_workflow_id_idx" ON "workflow_execution_snapshots" USING btree ("workflow_id");--> statement-breakpoint
80+
CREATE INDEX "workflow_snapshots_hash_idx" ON "workflow_execution_snapshots" USING btree ("state_hash");--> statement-breakpoint
81+
CREATE UNIQUE INDEX "workflow_snapshots_workflow_hash_idx" ON "workflow_execution_snapshots" USING btree ("workflow_id","state_hash");--> statement-breakpoint
82+
CREATE INDEX "workflow_snapshots_created_at_idx" ON "workflow_execution_snapshots" USING btree ("created_at");

0 commit comments

Comments
 (0)