terse-types 0.0.73 → 0.0.75

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Collapses a single Attio value entry (or nested structure) toward primitives /
3
+ * simple objects, matching the shape produced for generated Attio tool outputs.
4
+ */
5
+ export declare function flattenAttioLeafValue(value: unknown): unknown;
6
+ /**
7
+ * Flattens one attribute’s raw value (often an array of interaction rows from the REST API).
8
+ * @param preferArray When true, keep all entries as an array; when false, use the first entry only.
9
+ */
10
+ export declare function flattenAttioAttributeValue(rawValue: unknown, preferArray: boolean): unknown;
11
+ /**
12
+ * Flattens `record.values` from Attio’s GET record / webhook enrichment payload.
13
+ */
14
+ export declare function flattenAttioRecordValues(values: Record<string, unknown>, isMultiValueAttribute: (attributeSlug: string) => boolean): Record<string, unknown>;
15
+ /**
16
+ * Slug-only heuristic when object attribute metadata is unavailable (e.g. Attio webhook triggers).
17
+ * Prefer {@link flattenAttioRecordValues} with object-aware multi-value info from codegen when possible.
18
+ */
19
+ export declare function isProbablyAttioMultiValueAttributeSlug(attributeSlug: string): boolean;
@@ -0,0 +1,71 @@
1
+ /** Keys Attio nests on attribute timeline entries (not the semantic payload). */
2
+ const ATTIO_VALUE_METADATA_KEYS = new Set([
3
+ "active_from",
4
+ "active_until",
5
+ "attribute_type",
6
+ "created_by_actor"
7
+ ]);
8
+ /**
9
+ * Collapses a single Attio value entry (or nested structure) toward primitives /
10
+ * simple objects, matching the shape produced for generated Attio tool outputs.
11
+ */
12
+ export function flattenAttioLeafValue(value) {
13
+ if (value === null || value === undefined)
14
+ return value;
15
+ if (Array.isArray(value))
16
+ return value.map(entry => flattenAttioLeafValue(entry));
17
+ if (typeof value !== "object")
18
+ return value;
19
+ const rawObject = value;
20
+ if (typeof rawObject.full_name === "string")
21
+ return rawObject.full_name;
22
+ if (typeof rawObject.email_address === "string")
23
+ return rawObject.email_address;
24
+ if (typeof rawObject.domain === "string")
25
+ return rawObject.domain;
26
+ if (typeof rawObject.phone_number === "string")
27
+ return rawObject.phone_number;
28
+ if ("value" in rawObject)
29
+ return flattenAttioLeafValue(rawObject.value);
30
+ const dataEntries = Object.entries(rawObject).filter(([key]) => !ATTIO_VALUE_METADATA_KEYS.has(key));
31
+ if (dataEntries.length === 0)
32
+ return rawObject;
33
+ if (dataEntries.length === 1)
34
+ return flattenAttioLeafValue(dataEntries[0][1]);
35
+ return Object.fromEntries(dataEntries.map(([key, entryValue]) => [key, flattenAttioLeafValue(entryValue)]));
36
+ }
37
+ /**
38
+ * Flattens one attribute’s raw value (often an array of interaction rows from the REST API).
39
+ * @param preferArray When true, keep all entries as an array; when false, use the first entry only.
40
+ */
41
+ export function flattenAttioAttributeValue(rawValue, preferArray) {
42
+ if (!Array.isArray(rawValue))
43
+ return flattenAttioLeafValue(rawValue);
44
+ const flattened = rawValue.map(entry => flattenAttioLeafValue(entry)).filter(entry => entry !== undefined);
45
+ return preferArray ? flattened : flattened[0];
46
+ }
47
+ /**
48
+ * Flattens `record.values` from Attio’s GET record / webhook enrichment payload.
49
+ */
50
+ export function flattenAttioRecordValues(values, isMultiValueAttribute) {
51
+ const flattenedValues = {};
52
+ for (const [attributeSlug, rawValue] of Object.entries(values)) {
53
+ flattenedValues[attributeSlug] = flattenAttioAttributeValue(rawValue, isMultiValueAttribute(attributeSlug));
54
+ }
55
+ return flattenedValues;
56
+ }
57
+ /**
58
+ * Slug-only heuristic when object attribute metadata is unavailable (e.g. Attio webhook triggers).
59
+ * Prefer {@link flattenAttioRecordValues} with object-aware multi-value info from codegen when possible.
60
+ */
61
+ export function isProbablyAttioMultiValueAttributeSlug(attributeSlug) {
62
+ const slug = attributeSlug.toLowerCase();
63
+ return (slug === "email_addresses" ||
64
+ slug === "domains" ||
65
+ slug === "phone_numbers" ||
66
+ slug === "social_profiles" ||
67
+ slug === "links" ||
68
+ slug === "tags" ||
69
+ slug.endsWith("_addresses") ||
70
+ slug.endsWith("_ids"));
71
+ }
@@ -0,0 +1,6 @@
1
+ import { z } from "zod";
2
+ export declare const organizationMetadataSchema: z.ZodObject<{
3
+ stripeCustomerId: z.ZodString;
4
+ runExecutionBlocked: z.ZodPipe<z.ZodOptional<z.ZodUnion<readonly [z.ZodBoolean, z.ZodString]>>, z.ZodTransform<boolean, string | boolean | undefined>>;
5
+ }, z.core.$strip>;
6
+ export type OrganizationMetadata = z.infer<typeof organizationMetadataSchema>;
@@ -0,0 +1,10 @@
1
+ import { z } from "zod";
2
+ // Can be serialized a string, supports deserialization
3
+ const booleanMetadataSchema = z
4
+ .union([z.boolean(), z.string()])
5
+ .optional()
6
+ .transform(value => value === true || value === "true");
7
+ export const organizationMetadataSchema = z.object({
8
+ stripeCustomerId: z.string(),
9
+ runExecutionBlocked: booleanMetadataSchema
10
+ });
@@ -66,13 +66,13 @@ function attioActionLabel(params, noun, done, count) {
66
66
  return `${verb} ${count} ${noun}${count !== 1 ? "s" : ""}`;
67
67
  return `${verb} ${noun}${plural ? "s" : ""}`;
68
68
  }
69
- function attioRecordsRequest(params) {
69
+ function attioReadRecordsRequest(params) {
70
70
  const request = params?.request;
71
71
  return request && typeof request === "object" && "action" in request ? request : undefined;
72
72
  }
73
- function attioRecordsLabel(request, done, count) {
73
+ function attioReadRecordsLabel(request, done, count) {
74
74
  if (!request)
75
- return done ? "Updated records" : "Working with records";
75
+ return done ? "Loaded records" : "Loading records";
76
76
  const target = `${request.objectSlug} record`;
77
77
  switch (request.action) {
78
78
  case "query":
@@ -84,18 +84,15 @@ function attioRecordsLabel(request, done, count) {
84
84
  return (done ? "Loaded" : "Loading") + ` ${target}`;
85
85
  case "get_attribute_history":
86
86
  return (done ? "Loaded" : "Loading") + ` ${target} history`;
87
- case "create":
88
- return (done ? "Created" : "Creating") + ` ${target}`;
89
- case "update":
90
- return (done ? "Updated" : "Updating") + ` ${target}`;
91
- case "upsert":
92
- if (done && count !== undefined && count !== 1)
93
- return `Saved ${count} ${target}s`;
94
- return (done ? "Saved" : "Saving") + ` ${target}`;
95
- case "delete":
96
- return (done ? "Deleted" : "Deleting") + ` ${target}`;
97
87
  }
98
88
  }
89
+ function attioRecordTarget(params) {
90
+ const request = params?.request;
91
+ return request?.objectSlug ? `${request.objectSlug} record` : "record";
92
+ }
93
+ function attioWriteDisplay(gerund, past, approvalPrompt) {
94
+ return { preparing: gerund, executing: () => gerund, complete: () => past, approval: () => approvalPrompt };
95
+ }
99
96
  /**
100
97
  * Display configurations for all tools.
101
98
  * Each tool defines how it should be displayed in preparing, executing, and complete phases.
@@ -728,20 +725,44 @@ const TOOL_DISPLAY_CONFIG = {
728
725
  // ===================
729
726
  // Attio Tools
730
727
  // ===================
731
- attio_records: {
732
- preparing: "Getting records ready",
733
- executing: params => attioRecordsLabel(attioRecordsRequest(params), false),
728
+ attio_read_records: {
729
+ preparing: "Loading records",
730
+ executing: params => attioReadRecordsLabel(attioReadRecordsRequest(params), false),
734
731
  complete: (params, result) => {
735
732
  const parsed = safeParseResult(result);
736
733
  const count = parsed?.count;
737
- return attioRecordsLabel(attioRecordsRequest(params), true, count);
738
- },
739
- approval: params => {
740
- const request = attioRecordsRequest(params);
741
- const target = request ? `${request.objectSlug} record` : "record";
742
- return request?.action === "delete" ? `Delete this ${target}? This cannot be undone.` : `Save ${target}?`;
734
+ return attioReadRecordsLabel(attioReadRecordsRequest(params), true, count);
743
735
  }
744
736
  },
737
+ attio_create_record: {
738
+ preparing: "Getting record ready",
739
+ executing: params => `Creating ${attioRecordTarget(params)}`,
740
+ complete: params => `Created ${attioRecordTarget(params)}`,
741
+ approval: params => `Create ${attioRecordTarget(params)}?`
742
+ },
743
+ attio_update_record: {
744
+ preparing: "Getting record updates ready",
745
+ executing: params => `Updating ${attioRecordTarget(params)}`,
746
+ complete: params => `Updated ${attioRecordTarget(params)}`,
747
+ approval: params => `Update ${attioRecordTarget(params)}?`
748
+ },
749
+ attio_upsert_record: {
750
+ preparing: "Getting records ready",
751
+ executing: params => `Saving ${attioRecordTarget(params)}`,
752
+ complete: (params, result) => {
753
+ const count = safeParseCount(result);
754
+ if (count !== undefined && count !== 1)
755
+ return `Saved ${count} ${attioRecordTarget(params)}s`;
756
+ return `Saved ${attioRecordTarget(params)}`;
757
+ },
758
+ approval: params => `Save ${attioRecordTarget(params)}?`
759
+ },
760
+ attio_delete_record: {
761
+ preparing: "Getting record ready",
762
+ executing: params => `Deleting ${attioRecordTarget(params)}`,
763
+ complete: params => `Deleted ${attioRecordTarget(params)}`,
764
+ approval: params => `Delete this ${attioRecordTarget(params)}? This cannot be undone.`
765
+ },
745
766
  attio_workspace_members: {
746
767
  preparing: "Looking up workspace members",
747
768
  executing: params => {
@@ -757,41 +778,67 @@ const TOOL_DISPLAY_CONFIG = {
757
778
  return count !== undefined ? `Found ${count} workspace member${count !== 1 ? "s" : ""}` : "Workspace members loaded";
758
779
  }
759
780
  },
760
- attio_tasks: {
761
- preparing: "Working with tasks",
781
+ attio_read_tasks: {
782
+ preparing: "Loading tasks",
762
783
  executing: params => attioActionLabel(params, "task", false),
763
784
  complete: (params, result) => attioActionLabel(params, "task", true, safeParseCount(result))
764
785
  },
765
- attio_notes: {
766
- preparing: "Working with notes",
786
+ attio_create_task: attioWriteDisplay("Creating task", "Created task", "Create this task?"),
787
+ attio_update_task: attioWriteDisplay("Updating task", "Updated task", "Update this task?"),
788
+ attio_delete_task: attioWriteDisplay("Deleting task", "Deleted task", "Delete this task? This cannot be undone."),
789
+ attio_read_notes: {
790
+ preparing: "Loading notes",
767
791
  executing: params => attioActionLabel(params, "note", false),
768
792
  complete: (params, result) => attioActionLabel(params, "note", true, safeParseCount(result))
769
793
  },
770
- attio_comments: {
771
- preparing: "Working with comments",
794
+ attio_create_note: attioWriteDisplay("Creating note", "Created note", "Create this note?"),
795
+ attio_delete_note: attioWriteDisplay("Deleting note", "Deleted note", "Delete this note? This cannot be undone."),
796
+ attio_read_comments: {
797
+ preparing: "Loading comments",
772
798
  executing: params => attioActionLabel(params, "comment", false),
773
799
  complete: (params, result) => attioActionLabel(params, "comment", true, safeParseCount(result))
774
800
  },
775
- attio_lists: {
776
- preparing: "Working with lists",
801
+ attio_create_comment: attioWriteDisplay("Creating comment", "Created comment", "Create this comment?"),
802
+ attio_delete_comment: attioWriteDisplay("Deleting comment", "Deleted comment", "Delete this comment? This cannot be undone."),
803
+ attio_read_lists: {
804
+ preparing: "Loading lists",
805
+ executing: params => attioActionLabel(params, "list", false),
806
+ complete: (params, result) => attioActionLabel(params, "list", true, safeParseCount(result))
807
+ },
808
+ attio_create_list: attioWriteDisplay("Creating list", "Created list", "Create this list?"),
809
+ attio_update_list: attioWriteDisplay("Updating list", "Updated list", "Update this list?"),
810
+ attio_read_list_entries: {
811
+ preparing: "Loading list entries",
777
812
  executing: params => attioActionLabel(params, "list entry", false),
778
813
  complete: (params, result) => attioActionLabel(params, "list entry", true, safeParseCount(result))
779
814
  },
815
+ attio_add_list_entry: attioWriteDisplay("Adding list entry", "Added list entry", "Add this list entry?"),
816
+ attio_upsert_list_entry: attioWriteDisplay("Saving list entry", "Saved list entry", "Save this list entry?"),
817
+ attio_update_list_entry: attioWriteDisplay("Updating list entry", "Updated list entry", "Update this list entry?"),
818
+ attio_remove_list_entry: attioWriteDisplay("Removing list entry", "Removed list entry", "Remove this list entry?"),
780
819
  attio_meetings: {
781
820
  preparing: "Loading meetings",
782
821
  executing: params => attioActionLabel(params, "meeting", false),
783
822
  complete: (params, result) => attioActionLabel(params, "meeting", true, safeParseCount(result))
784
823
  },
785
- attio_files: {
786
- preparing: "Working with files",
824
+ attio_read_files: {
825
+ preparing: "Loading files",
787
826
  executing: params => attioActionLabel(params, "file", false),
788
827
  complete: (params, result) => attioActionLabel(params, "file", true, safeParseCount(result))
789
828
  },
790
- attio_schema: {
829
+ attio_upload_file: attioWriteDisplay("Uploading file", "Uploaded file", "Upload this file?"),
830
+ attio_delete_file: attioWriteDisplay("Deleting file", "Deleted file", "Delete this file? This cannot be undone."),
831
+ attio_read_schema: {
791
832
  preparing: "Loading workspace schema",
792
833
  executing: params => attioActionLabel(params, "schema item", false),
793
834
  complete: (params, result) => attioActionLabel(params, "schema item", true, safeParseCount(result))
794
835
  },
836
+ attio_modify_schema: {
837
+ preparing: "Updating workspace schema",
838
+ executing: params => attioActionLabel(params, "schema item", false),
839
+ complete: (params, result) => attioActionLabel(params, "schema item", true, safeParseCount(result)),
840
+ approval: () => "Change the workspace schema? This affects every user."
841
+ },
795
842
  // ===================
796
843
  // WorkOS Tools
797
844
  // ===================