Skip to content

Commit ca6cfc3

Browse files
committed
chore(people): renumber the directory fields migration to 0480 after staging; pass search_people filters through the workflow block
1 parent 702b415 commit ca6cfc3

10 files changed

Lines changed: 34478 additions & 9 deletions

File tree

‎apps/sim/blocks/blocks/organization.ts‎

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,54 @@ export const OrganizationBlock: BlockConfig = {
179179
condition: { field: 'operation', value: 'read_document' },
180180
mode: 'advanced',
181181
},
182+
{
183+
id: 'name',
184+
title: 'Name',
185+
type: 'short-input',
186+
placeholder: 'Part of a name',
187+
condition: { field: 'operation', value: 'search_people' },
188+
mode: 'advanced',
189+
},
190+
{
191+
id: 'email',
192+
title: 'Email',
193+
type: 'short-input',
194+
placeholder: 'An exact email address',
195+
condition: { field: 'operation', value: 'search_people' },
196+
mode: 'advanced',
197+
},
198+
{
199+
id: 'title',
200+
title: 'Title',
201+
type: 'short-input',
202+
placeholder: 'Part of a job title',
203+
condition: { field: 'operation', value: 'search_people' },
204+
mode: 'advanced',
205+
},
206+
{
207+
id: 'department',
208+
title: 'Department',
209+
type: 'short-input',
210+
placeholder: 'Part of a department',
211+
condition: { field: 'operation', value: 'search_people' },
212+
mode: 'advanced',
213+
},
214+
{
215+
id: 'location',
216+
title: 'Location',
217+
type: 'short-input',
218+
placeholder: 'Part of a location',
219+
condition: { field: 'operation', value: 'search_people' },
220+
mode: 'advanced',
221+
},
222+
{
223+
id: 'managerPersonId',
224+
title: 'Manager Person ID',
225+
type: 'short-input',
226+
placeholder: 'A personId, to list their direct reports',
227+
condition: { field: 'operation', value: 'search_people' },
228+
mode: 'advanced',
229+
},
182230
{
183231
id: 'personId',
184232
title: 'Person ID',
@@ -248,6 +296,12 @@ export const OrganizationBlock: BlockConfig = {
248296
documentIds: { type: 'string', description: 'Documents to read together' },
249297
startChunkIndex: { type: 'number', description: 'Chunk to continue reading from' },
250298
startOffset: { type: 'number', description: 'Where to continue reading' },
299+
name: { type: 'string', description: 'Search People: part of a name' },
300+
email: { type: 'string', description: 'Search People: an exact email address' },
301+
title: { type: 'string', description: 'Search People: part of a job title' },
302+
department: { type: 'string', description: 'Search People: part of a department' },
303+
location: { type: 'string', description: 'Search People: part of a location' },
304+
managerPersonId: { type: 'string', description: 'Search People: list this person’s reports' },
251305
personId: { type: 'string', description: 'Person to show with their reporting line' },
252306
cursor: { type: 'string', description: 'Next page of a people search' },
253307
},

‎apps/sim/lib/internal/organization-search/execute-tool.integration.ts‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,15 @@ describe('Organization Search tools in a workflow run', () => {
156156
})
157157
})
158158

159+
it('applies the People field filters a workflow passes', async () => {
160+
const response = await call(
161+
runAs(memberUserId, organizationWorkflowId, organizationWorkspaceId),
162+
{ email: `${colleagueUserId}@organization-search.test` }
163+
)
164+
expect(response.status).toBe(200)
165+
expect((await response.json()).person).toMatchObject({ name: colleagueName })
166+
})
167+
159168
it('refuses a run in an organization without Search', async () => {
160169
searchAvailable.value = false
161170
try {

‎apps/sim/lib/internal/organization-search/search-people.ts‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@ import { findDirectoryPeople, readDirectoryPerson } from '@/lib/people/directory
88
export const searchOrganizationPeople: OrganizationSearchToolHandler = async (call) => {
99
const parsed = parseInternalOperationInput({ body: searchPeopleInputSchema }, call.input)
1010
if (!parsed.success) return parsed.response
11-
const { query, personId, cursor } = parsed.data.body
11+
const { personId, ...listing } = parsed.data.body
1212
const scope = {
1313
principal: call.principal,
1414
organizationId: call.principal.organizationId,
1515
request: { headers: call.operation.headers },
1616
}
17-
return respondWithResultProvenance(call, query, async () =>
17+
return respondWithResultProvenance(call, listing.query, async () =>
1818
personId
1919
? readDirectoryPerson({ ...scope, personId })
20-
: findDirectoryPeople({ ...scope, query, cursor })
20+
: findDirectoryPeople({ ...scope, ...listing })
2121
)
2222
}

‎apps/sim/tools/generated/tool-metadata.ts‎

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

‎apps/sim/tools/generated/tool-outputs.ts‎

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

‎apps/sim/tools/organization/search_people.ts‎

Lines changed: 50 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export const organizationSearchPeopleTool: InternalToolConfig<
1313
id: 'organization_search_people',
1414
name: 'Organization Search People',
1515
description:
16-
'Look up people in this organization’s directory by name, email, title, department, or location, as the person running the workflow. Returns each person’s title, department, location, email, and manager. When exactly one person matches, or with a personId, returns that person with managerChain (direct manager first) and directReports.',
16+
'Look up people in this organization’s directory by name, email, title, department, or location, as the person running the workflow, with query across all of them or a filter per field; managerPersonId lists someone’s direct reports. Returns each person’s title, department, location, email, start date, time zone, Slack user ID, manager, and direct report count. When exactly one person matches, or with a personId, returns that person with managerChain (direct manager first) and directReports.',
1717
version: '1.0.0',
1818
effect: 'read',
1919

@@ -25,6 +25,42 @@ export const organizationSearchPeopleTool: InternalToolConfig<
2525
description:
2626
'Up to 8 words from a name, email, title, department, or location; a person matches when every word appears in one of them.',
2727
},
28+
name: {
29+
type: 'string',
30+
required: false,
31+
visibility: 'user-or-llm',
32+
description: 'Only people whose name contains this text.',
33+
},
34+
email: {
35+
type: 'string',
36+
required: false,
37+
visibility: 'user-or-llm',
38+
description: 'Only the person with this exact email address.',
39+
},
40+
title: {
41+
type: 'string',
42+
required: false,
43+
visibility: 'user-or-llm',
44+
description: 'Only people whose title contains this text.',
45+
},
46+
department: {
47+
type: 'string',
48+
required: false,
49+
visibility: 'user-or-llm',
50+
description: 'Only people whose department contains this text.',
51+
},
52+
location: {
53+
type: 'string',
54+
required: false,
55+
visibility: 'user-or-llm',
56+
description: 'Only people whose location contains this text.',
57+
},
58+
managerPersonId: {
59+
type: 'string',
60+
required: false,
61+
visibility: 'user-or-llm',
62+
description: 'Only the direct reports of this personId.',
63+
},
2864
personId: {
2965
type: 'string',
3066
required: false,
@@ -44,15 +80,26 @@ export const organizationSearchPeopleTool: InternalToolConfig<
4480
modelInput: { mode: 'private-provenance', inputPaths: () => [['query']] },
4581
secretProvenance: { response: { incomplete: 'reject' } },
4682
input: (params) =>
47-
presentFields({ query: params.query, personId: params.personId, cursor: params.cursor }),
83+
presentFields({
84+
query: params.query,
85+
name: params.name,
86+
email: params.email,
87+
title: params.title,
88+
department: params.department,
89+
location: params.location,
90+
managerPersonId: params.managerPersonId,
91+
personId: params.personId,
92+
cursor: params.cursor,
93+
}),
4894
},
4995

5096
transformResponse: organizationToolOutput,
5197

5298
outputs: {
5399
people: {
54100
type: 'array',
55-
description: 'Matching people: personId, name, title, email, department, location, manager',
101+
description:
102+
'Matching people: personId, name, title, email, department, location, startDate, timezone, slackUserId, manager, managerPersonId, managerEmail, totalDirectReports',
56103
},
57104
person: {
58105
type: 'json',

‎apps/sim/tools/organization/types.ts‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,15 @@ export interface OrganizationReadDocumentParams {
2323
startOffset?: number
2424
}
2525

26-
/** `organization_search_people` input: a directory query or one personId. */
26+
/** `organization_search_people` input: a directory query and per-field filters, or one personId. */
2727
export interface OrganizationSearchPeopleParams {
2828
query?: string
29+
name?: string
30+
email?: string
31+
title?: string
32+
department?: string
33+
location?: string
34+
managerPersonId?: string
2935
personId?: string
3036
cursor?: string
3137
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
-- Start dates and time zones for directory people, and their Slack identities. Every statement is
2+
-- replay-safe: an earlier migration in the same run may end the batch transaction with an embedded
3+
-- COMMIT, after which a lock-timeout retry replays this file statement by statement.
4+
-- migration-safe: additive only; new nullable columns and new tables the deployed app never reads.
5+
CREATE TABLE IF NOT EXISTS "people_slack_identity" (
6+
"organization_id" text NOT NULL,
7+
"email" text NOT NULL,
8+
"slack_user_id" text NOT NULL,
9+
"timezone" text,
10+
CONSTRAINT "people_slack_identity_organization_id_email_pk" PRIMARY KEY("organization_id","email")
11+
);
12+
--> statement-breakpoint
13+
CREATE TABLE IF NOT EXISTS "people_slack_sync" (
14+
"organization_id" text PRIMARY KEY NOT NULL,
15+
"next_refresh_at" timestamp DEFAULT now() NOT NULL,
16+
"lease_token" text,
17+
"refreshed_at" timestamp,
18+
"last_error" text
19+
);
20+
--> statement-breakpoint
21+
ALTER TABLE "people_directory_entry" ADD COLUMN IF NOT EXISTS "start_date" date;--> statement-breakpoint
22+
ALTER TABLE "people_directory_entry" ADD COLUMN IF NOT EXISTS "timezone" text;--> statement-breakpoint
23+
ALTER TABLE "people_directory_stage" ADD COLUMN IF NOT EXISTS "start_date" date;--> statement-breakpoint
24+
ALTER TABLE "people_directory_stage" ADD COLUMN IF NOT EXISTS "timezone" text;--> statement-breakpoint
25+
DO $$ BEGIN
26+
IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname = 'people_slack_identity_organization_id_organization_id_fk' AND conrelid = 'people_slack_identity'::regclass) THEN
27+
ALTER TABLE "people_slack_identity" ADD CONSTRAINT "people_slack_identity_organization_id_organization_id_fk" FOREIGN KEY ("organization_id") REFERENCES "public"."organization"("id") ON DELETE cascade ON UPDATE no action;
28+
END IF;
29+
IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname = 'people_slack_sync_organization_id_organization_id_fk' AND conrelid = 'people_slack_sync'::regclass) THEN
30+
ALTER TABLE "people_slack_sync" ADD CONSTRAINT "people_slack_sync_organization_id_organization_id_fk" FOREIGN KEY ("organization_id") REFERENCES "public"."organization"("id") ON DELETE cascade ON UPDATE no action;
31+
END IF;
32+
END $$;--> statement-breakpoint
33+
CREATE INDEX IF NOT EXISTS "people_slack_sync_due_idx" ON "people_slack_sync" USING btree ("next_refresh_at");

0 commit comments

Comments
 (0)