terse-cli 0.2.14 → 0.2.16

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.
Files changed (38) hide show
  1. package/dist/cliHelpers.d.ts +1 -0
  2. package/dist/cliHelpers.d.ts.map +1 -1
  3. package/dist/cliHelpers.js +8 -5
  4. package/dist/cliHelpers.js.map +1 -1
  5. package/dist/commands/deploy.d.ts.map +1 -1
  6. package/dist/commands/deploy.js +4 -3
  7. package/dist/commands/deploy.js.map +1 -1
  8. package/dist/commands/generate.d.ts.map +1 -1
  9. package/dist/commands/generate.js +49 -2
  10. package/dist/commands/generate.js.map +1 -1
  11. package/dist/commands/integrate.d.ts +3 -0
  12. package/dist/commands/integrate.d.ts.map +1 -1
  13. package/dist/commands/integrate.js +50 -17
  14. package/dist/commands/integrate.js.map +1 -1
  15. package/dist/commands/integrateUse.d.ts +13 -0
  16. package/dist/commands/integrateUse.d.ts.map +1 -0
  17. package/dist/commands/integrateUse.js +99 -0
  18. package/dist/commands/integrateUse.js.map +1 -0
  19. package/dist/commands/toolRun.d.ts +7 -0
  20. package/dist/commands/toolRun.d.ts.map +1 -0
  21. package/dist/commands/toolRun.js +135 -0
  22. package/dist/commands/toolRun.js.map +1 -0
  23. package/dist/index.js +61 -2
  24. package/dist/index.js.map +1 -1
  25. package/dist/integrationApi.d.ts +2 -1
  26. package/dist/integrationApi.d.ts.map +1 -1
  27. package/dist/integrationApi.js +24 -2
  28. package/dist/integrationApi.js.map +1 -1
  29. package/dist/providers/codegenTypes.d.ts +6 -1
  30. package/dist/providers/codegenTypes.d.ts.map +1 -1
  31. package/dist/providers/typescript/prepareCodegenData.d.ts +14 -0
  32. package/dist/providers/typescript/prepareCodegenData.d.ts.map +1 -1
  33. package/dist/providers/typescript/prepareCodegenData.js +134 -76
  34. package/dist/providers/typescript/prepareCodegenData.js.map +1 -1
  35. package/package.json +3 -3
  36. package/templates/typescript/codegen/generated.hbs +1 -0
  37. package/templates/typescript/codegen/partials/resend-section.hbs +34 -0
  38. package/templates/typescript/codegen/partials/skills-section.hbs +6 -0
@@ -1,4 +1,4 @@
1
- import { ToolDefinitions, toolsWithIntegrationId } from "terse-types";
1
+ import { IntegrationType, ToolDefinitions, toolsWithIntegrationId } from "terse-types";
2
2
  import { z } from "zod";
3
3
  function toPascalCase(value) {
4
4
  return value
@@ -20,7 +20,7 @@ function toGeneratedIdentifier(raw, fallback) {
20
20
  name = `_${name}`;
21
21
  return name;
22
22
  }
23
- function toCamelCase(value) {
23
+ export function toCamelCase(value) {
24
24
  const pascal = toPascalCase(value);
25
25
  return pascal.charAt(0).toLowerCase() + pascal.slice(1);
26
26
  }
@@ -214,10 +214,9 @@ function buildSkillToolTypeForIntegration(tools, integrationType) {
214
214
  .sort();
215
215
  return renderStringLiteralUnion(toolNames);
216
216
  }
217
- function prepareGitHubSection(instances, tools) {
218
- if (instances.length === 0)
217
+ function prepareGitHubSection(inst, tools) {
218
+ if (!inst)
219
219
  return sectionData([]);
220
- const inst = instances[0];
221
220
  const imports = [
222
221
  "GitHubConfig",
223
222
  "GitHubEventType",
@@ -279,18 +278,17 @@ function prepareGitHubSection(instances, tools) {
279
278
  repoGroups
280
279
  });
281
280
  }
282
- function prepareGmailSection(instances, tools) {
283
- if (instances.length === 0)
281
+ function prepareGmailSection(inst, tools) {
282
+ if (!inst)
284
283
  return sectionData([]);
285
284
  return sectionData(["GmailConfig", "GmailOutputConfig", "GmailDraftOutputConfig", "TypedSkill", "TypedTrigger", "GmailEventType", "GmailTrigger"], {
286
- id: instances[0].id,
285
+ id: inst.id,
287
286
  skillToolType: buildSkillToolTypeForIntegration(tools, "gmail")
288
287
  });
289
288
  }
290
- function prepareSlackSection(instances, tools) {
291
- if (instances.length === 0)
289
+ function prepareSlackSection(inst, tools) {
290
+ if (!inst)
292
291
  return sectionData([]);
293
- const inst = instances[0];
294
292
  return sectionData(["SlackAppMentionTrigger", "SlackConfig", "SlackMessageTrigger", "SlackOutputConfig", "SlackReactionAddedTrigger", "TypedSkill", "SlackEventType", "TypedTrigger", "SlackTrigger"], {
295
293
  id: inst.id,
296
294
  skillToolType: buildSkillToolTypeForIntegration(tools, "slack"),
@@ -304,10 +302,9 @@ function prepareSlackSection(instances, tools) {
304
302
  ], "name", inst.users)
305
303
  });
306
304
  }
307
- function prepareLinearSection(instances, tools) {
308
- if (instances.length === 0)
305
+ function prepareLinearSection(inst, tools) {
306
+ if (!inst)
309
307
  return sectionData([]);
310
- const inst = instances[0];
311
308
  return sectionData([
312
309
  "LinearInputConfig",
313
310
  "LinearOutputConfig",
@@ -332,10 +329,9 @@ function prepareLinearSection(instances, tools) {
332
329
  ], "name", inst.projects)
333
330
  });
334
331
  }
335
- function prepareNotionSection(instances, tools) {
336
- if (instances.length === 0)
332
+ function prepareNotionSection(inst, tools) {
333
+ if (!inst)
337
334
  return sectionData([]);
338
- const inst = instances[0];
339
335
  return sectionData(["NotionConfig", "TypedSkill"], {
340
336
  id: inst.id,
341
337
  skillToolType: buildSkillToolTypeForIntegration(tools, "notion"),
@@ -349,10 +345,9 @@ function prepareNotionSection(instances, tools) {
349
345
  ], "title", inst.pages)
350
346
  });
351
347
  }
352
- function preparePosthogSection(instances, tools) {
353
- if (instances.length === 0)
348
+ function preparePosthogSection(inst, tools) {
349
+ if (!inst)
354
350
  return sectionData([]);
355
- const inst = instances[0];
356
351
  return sectionData(["PosthogConfig", "TypedSkill"], {
357
352
  id: inst.id,
358
353
  skillToolType: buildSkillToolTypeForIntegration(tools, "posthog"),
@@ -363,20 +358,18 @@ function preparePosthogSection(instances, tools) {
363
358
  eventNames: [...new Set(inst.projects.flatMap(project => project.events))]
364
359
  });
365
360
  }
366
- function prepareDatadogSection(instances, tools) {
367
- if (instances.length === 0)
361
+ function prepareDatadogSection(inst, tools) {
362
+ if (!inst)
368
363
  return sectionData([]);
369
- const inst = instances[0];
370
364
  return sectionData(["DatadogConfig", "TypedSkill"], {
371
365
  id: inst.id,
372
366
  skillToolType: buildSkillToolTypeForIntegration(tools, "datadog"),
373
367
  indexClass: buildResourceClassContext("DatadogIndex", [{ classField: "name", type: "string", sourceField: "name" }], "name", inst.indexes)
374
368
  });
375
369
  }
376
- function prepareLaunchDarklySection(instances, tools) {
377
- if (instances.length === 0)
370
+ function prepareLaunchDarklySection(inst, tools) {
371
+ if (!inst)
378
372
  return sectionData([]);
379
- const inst = instances[0];
380
373
  return sectionData(["LaunchDarklyConfig", "TypedSkill"], {
381
374
  id: inst.id,
382
375
  skillToolType: buildSkillToolTypeForIntegration(tools, "launchdarkly"),
@@ -386,8 +379,8 @@ function prepareLaunchDarklySection(instances, tools) {
386
379
  ], "name", inst.projects)
387
380
  });
388
381
  }
389
- function prepareWorkOSSection(instances, tools) {
390
- if (instances.length === 0)
382
+ function prepareWorkOSSection(inst, tools) {
383
+ if (!inst)
391
384
  return sectionData([]);
392
385
  return sectionData([
393
386
  "WorkOSInputConfig",
@@ -411,12 +404,12 @@ function prepareWorkOSSection(instances, tools) {
411
404
  "WorkOSInvitationTrigger",
412
405
  "WorkOSOrganizationTrigger"
413
406
  ], {
414
- id: instances[0].id,
407
+ id: inst.id,
415
408
  skillToolType: buildSkillToolTypeForIntegration(tools, "workos")
416
409
  });
417
410
  }
418
- function buildGeneratedAttioObjects(instances) {
419
- const objects = instances[0]?.objects ?? [];
411
+ function buildGeneratedAttioObjects(inst) {
412
+ const objects = inst?.objects ?? [];
420
413
  const usedNames = new Set();
421
414
  return objects.map(object => {
422
415
  let staticName = toGeneratedIdentifier(object.singular_noun || object.api_slug || "Object", "AttioObject");
@@ -436,8 +429,8 @@ function buildGeneratedAttioObjects(instances) {
436
429
  };
437
430
  });
438
431
  }
439
- function buildGeneratedAttioLists(instances) {
440
- const lists = instances[0]?.lists ?? [];
432
+ function buildGeneratedAttioLists(inst) {
433
+ const lists = inst?.lists ?? [];
441
434
  const usedNames = new Set();
442
435
  return lists.map(list => {
443
436
  let staticName = toGeneratedIdentifier(list.name || list.api_slug || "List", "AttioList");
@@ -612,11 +605,11 @@ function buildAttioRuntimeLines(objects, lists) {
612
605
  lines.push("})");
613
606
  return lines;
614
607
  }
615
- function prepareAttioSection(instances, tools) {
616
- if (instances.length === 0)
608
+ function prepareAttioSection(inst, tools) {
609
+ if (!inst)
617
610
  return sectionData([]);
618
- const objects = buildGeneratedAttioObjects(instances);
619
- const lists = buildGeneratedAttioLists(instances);
611
+ const objects = buildGeneratedAttioObjects(inst);
612
+ const lists = buildGeneratedAttioLists(inst);
620
613
  return sectionData([
621
614
  "registerEventTransform",
622
615
  "AttioOutputConfig",
@@ -653,7 +646,7 @@ function prepareAttioSection(instances, tools) {
653
646
  "AttioTaskDeletedTrigger",
654
647
  "AttioWorkspaceMemberCreatedTrigger"
655
648
  ], {
656
- id: instances[0].id,
649
+ id: inst.id,
657
650
  skillToolType: buildSkillToolTypeForIntegration(tools, "attio"),
658
651
  objects,
659
652
  lists,
@@ -661,18 +654,17 @@ function prepareAttioSection(instances, tools) {
661
654
  runtimeLines: buildAttioRuntimeLines(objects, lists)
662
655
  });
663
656
  }
664
- function prepareSnowflakeSection(instances, tools) {
665
- if (instances.length === 0)
657
+ function prepareSnowflakeSection(inst, tools) {
658
+ if (!inst)
666
659
  return sectionData([]);
667
660
  return sectionData(["SnowflakeOutputConfig", "TypedSkill"], {
668
- id: instances[0].id,
661
+ id: inst.id,
669
662
  skillToolType: buildSkillToolTypeForIntegration(tools, "snowflake")
670
663
  });
671
664
  }
672
- function prepareHeyReachSection(instances) {
673
- if (instances.length === 0)
665
+ function prepareHeyReachSection(inst) {
666
+ if (!inst)
674
667
  return sectionData([]);
675
- const inst = instances[0];
676
668
  return sectionData([
677
669
  "HeyReachInputConfig",
678
670
  "HeyReachEventType",
@@ -697,23 +689,56 @@ function prepareHeyReachSection(instances) {
697
689
  ], "name", inst.campaigns)
698
690
  });
699
691
  }
700
- function prepareToolsSection(tools, input) {
692
+ function prepareResendSection(instance, tools) {
693
+ if (!instance)
694
+ return sectionData([]);
695
+ const usedNames = new Set();
696
+ const templates = instance.templates.map(template => {
697
+ let staticName = toGeneratedIdentifier(template.alias || template.name || "Template", "Template");
698
+ while (usedNames.has(staticName))
699
+ staticName += "_";
700
+ usedNames.add(staticName);
701
+ const fields = template.variables.map(variable => {
702
+ const optional = variable.fallbackValue !== null ? "?" : "";
703
+ return `"${escapeString(variable.key)}"${optional}: ${variable.type}`;
704
+ });
705
+ const variablesType = fields.length > 0 ? `{ ${fields.join("; ")} }` : "Record<string, never>";
706
+ const variablesMetadata = template.variables
707
+ .map(variable => JSON.stringify({
708
+ key: variable.key,
709
+ type: variable.type,
710
+ required: variable.fallbackValue === null,
711
+ fallbackValue: variable.fallbackValue
712
+ }))
713
+ .join(", ");
714
+ return { staticName, id: template.id, alias: template.alias, name: template.name, variablesType, variablesMetadata };
715
+ });
716
+ const sectionImports = templates.length > 0 ? ["ResendOutputConfig", "TypedSkill", "ToolInputByName"] : ["ResendOutputConfig", "TypedSkill"];
717
+ return sectionData(sectionImports, {
718
+ id: instance.id,
719
+ skillToolType: buildSkillToolTypeForIntegration(tools, "resend"),
720
+ templates
721
+ });
722
+ }
723
+ function prepareToolsSection(tools, input, active) {
701
724
  if (tools.length === 0)
702
725
  return sectionData([]);
703
726
  const imports = new Set(["TerseAgent", "ToolInputByName", "ToolOutputByName"]);
704
727
  const attioPreludeLines = [];
705
- const instanceMap = new Map();
706
- instanceMap.set("slack", input.slack.map(inst => ({ id: inst.id, displayName: inst.displayName })));
707
- instanceMap.set("github", input.github.map(inst => ({ id: inst.integration.id, displayName: inst.integration.account_name || "" })));
708
- instanceMap.set("gmail", input.gmail.map(inst => ({ id: inst.id, displayName: inst.displayName })));
709
- instanceMap.set("linear", input.linear.map(inst => ({ id: inst.id, displayName: inst.displayName })));
710
- instanceMap.set("notion", input.notion.map(inst => ({ id: inst.id, displayName: inst.displayName })));
711
- instanceMap.set("posthog", input.posthog.map(inst => ({ id: inst.id, displayName: inst.displayName })));
712
- instanceMap.set("datadog", input.datadog.map(inst => ({ id: inst.id, displayName: inst.displayName })));
713
- instanceMap.set("launchdarkly", input.launchdarkly.map(inst => ({ id: inst.id, displayName: inst.displayName })));
714
- instanceMap.set("workos", input.workos.map(inst => ({ id: inst.id, displayName: inst.displayName })));
715
- instanceMap.set("attio", input.attio.map(inst => ({ id: inst.id, displayName: inst.displayName })));
716
- instanceMap.set("snowflake", input.snowflake.map(inst => ({ id: inst.id, displayName: inst.name })));
728
+ const activeIdByIntegration = new Map([
729
+ ["slack", active.slack?.id],
730
+ ["github", active.github?.integration.id],
731
+ ["gmail", active.gmail?.id],
732
+ ["linear", active.linear?.id],
733
+ ["notion", active.notion?.id],
734
+ ["posthog", active.posthog?.id],
735
+ ["datadog", active.datadog?.id],
736
+ ["launchdarkly", active.launchdarkly?.id],
737
+ ["workos", active.workos?.id],
738
+ ["attio", active.attio?.id],
739
+ ["snowflake", active.snowflake?.id],
740
+ ["resend", active.resend?.id]
741
+ ]);
717
742
  const byIntegration = new Map();
718
743
  for (const tool of tools) {
719
744
  const key = tool.integration.toLowerCase();
@@ -738,9 +763,9 @@ function prepareToolsSection(tools, input) {
738
763
  }
739
764
  };
740
765
  const isAttioTool = (tool) => tool.integration.toLowerCase() === "attio";
741
- const attioGeneratedObjects = buildGeneratedAttioObjects(input.attio);
766
+ const attioGeneratedObjects = buildGeneratedAttioObjects(active.attio);
742
767
  if (tools.some(isAttioTool)) {
743
- if (input.attio.length === 0) {
768
+ if (!active.attio) {
744
769
  attioPreludeLines.push(...attioValueTypeLines());
745
770
  attioPreludeLines.push("");
746
771
  }
@@ -872,10 +897,14 @@ function prepareToolsSection(tools, input) {
872
897
  attioPreludeLines.push("");
873
898
  }
874
899
  const hasPosthogEventNames = (input.posthog[0]?.projects ?? []).some(project => project.events.length > 0);
900
+ const hasResendTemplates = (active.resend?.templates.length ?? 0) > 0;
875
901
  const paramTypes = [];
876
902
  for (const tool of tools) {
877
903
  if (isAttioTool(tool))
878
904
  continue;
905
+ // Emitted by the Resend section as a per-template discriminated union
906
+ if (tool.name === "resend_send_template" && hasResendTemplates)
907
+ continue;
879
908
  const key = `"${escapeString(tool.name)}"`;
880
909
  let tsType = hasAutoFillId(tool) ? `Omit<ToolInputByName[${key}], "integrationId">` : `ToolInputByName[${key}]`;
881
910
  if (tool.name === "searchPosthogEvents" && hasPosthogEventNames) {
@@ -892,10 +921,10 @@ function prepareToolsSection(tools, input) {
892
921
  for (const [integration, integrationTools] of byIntegration.entries()) {
893
922
  const needsAutoFill = integrationTools.some(hasAutoFillId);
894
923
  if (needsAutoFill) {
895
- const instances = instanceMap.get(integration) || [];
896
- if (instances.length === 0)
924
+ const integrationId = activeIdByIntegration.get(integration);
925
+ if (!integrationId)
897
926
  continue;
898
- rawGroups.push({ key: integration, integration, tools: integrationTools, integrationId: instances[0].id });
927
+ rawGroups.push({ key: integration, integration, tools: integrationTools, integrationId });
899
928
  }
900
929
  else {
901
930
  rawGroups.push({ key: integration, integration, tools: integrationTools });
@@ -1331,21 +1360,23 @@ function prepareSystemSection() {
1331
1360
  }
1332
1361
  export function prepareTemplateContext(input) {
1333
1362
  const allImports = new Set();
1334
- const github = prepareGitHubSection(input.github, input.tools);
1335
- const gmail = prepareGmailSection(input.gmail, input.tools);
1336
- const slack = prepareSlackSection(input.slack, input.tools);
1337
- const linear = prepareLinearSection(input.linear, input.tools);
1338
- const notion = prepareNotionSection(input.notion, input.tools);
1339
- const posthog = preparePosthogSection(input.posthog, input.tools);
1340
- const datadog = prepareDatadogSection(input.datadog, input.tools);
1341
- const launchdarkly = prepareLaunchDarklySection(input.launchdarkly, input.tools);
1342
- const workos = prepareWorkOSSection(input.workos, input.tools);
1343
- const attio = prepareAttioSection(input.attio, input.tools);
1344
- const snowflake = prepareSnowflakeSection(input.snowflake, input.tools);
1345
- const heyreach = prepareHeyReachSection(input.heyreach);
1346
- const tools = prepareToolsSection(input.tools, input);
1363
+ const active = resolveActiveInstances(input);
1364
+ const github = prepareGitHubSection(active.github, input.tools);
1365
+ const gmail = prepareGmailSection(active.gmail, input.tools);
1366
+ const slack = prepareSlackSection(active.slack, input.tools);
1367
+ const linear = prepareLinearSection(active.linear, input.tools);
1368
+ const notion = prepareNotionSection(active.notion, input.tools);
1369
+ const posthog = preparePosthogSection(active.posthog, input.tools);
1370
+ const datadog = prepareDatadogSection(active.datadog, input.tools);
1371
+ const launchdarkly = prepareLaunchDarklySection(active.launchdarkly, input.tools);
1372
+ const workos = prepareWorkOSSection(active.workos, input.tools);
1373
+ const attio = prepareAttioSection(active.attio, input.tools);
1374
+ const snowflake = prepareSnowflakeSection(active.snowflake, input.tools);
1375
+ const heyreach = prepareHeyReachSection(active.heyreach);
1376
+ const resend = prepareResendSection(active.resend, input.tools);
1377
+ const tools = prepareToolsSection(input.tools, input, active);
1347
1378
  const system = prepareSystemSection();
1348
- const sections = [github, gmail, slack, linear, notion, posthog, datadog, launchdarkly, workos, attio, snowflake, heyreach, tools, system];
1379
+ const sections = [github, gmail, slack, linear, notion, posthog, datadog, launchdarkly, workos, attio, snowflake, heyreach, resend, tools, system];
1349
1380
  for (const section of sections) {
1350
1381
  section.imports.forEach(value => allImports.add(value));
1351
1382
  }
@@ -1366,8 +1397,35 @@ export function prepareTemplateContext(input) {
1366
1397
  attio: attio.data,
1367
1398
  snowflake: snowflake.data,
1368
1399
  heyreach: heyreach.data,
1400
+ resend: resend.data,
1369
1401
  tools: tools.data,
1370
1402
  system: system.data
1371
1403
  };
1372
1404
  }
1405
+ function resolveActiveInstances(input) {
1406
+ const pins = input.activeConnections;
1407
+ return {
1408
+ github: selectActiveInstance(input.github, pins[IntegrationType.GITHUB], data => data.integration.id),
1409
+ gmail: selectActiveInstance(input.gmail, pins[IntegrationType.GMAIL], data => data.id),
1410
+ slack: selectActiveInstance(input.slack, pins[IntegrationType.SLACK], data => data.id),
1411
+ linear: selectActiveInstance(input.linear, pins[IntegrationType.LINEAR], data => data.id),
1412
+ notion: selectActiveInstance(input.notion, pins[IntegrationType.NOTION], data => data.id),
1413
+ posthog: selectActiveInstance(input.posthog, pins[IntegrationType.POSTHOG], data => data.id),
1414
+ datadog: selectActiveInstance(input.datadog, pins[IntegrationType.DATADOG], data => data.id),
1415
+ launchdarkly: selectActiveInstance(input.launchdarkly, pins[IntegrationType.LAUNCHDARKLY], data => data.id),
1416
+ workos: selectActiveInstance(input.workos, pins[IntegrationType.WORKOS], data => data.id),
1417
+ attio: selectActiveInstance(input.attio, pins[IntegrationType.ATTIO], data => data.id),
1418
+ snowflake: selectActiveInstance(input.snowflake, pins[IntegrationType.SNOWFLAKE], data => data.id),
1419
+ heyreach: selectActiveInstance(input.heyreach, pins[IntegrationType.HEY_REACH], data => data.id),
1420
+ resend: selectActiveInstance(input.resend, pins[IntegrationType.RESEND], data => data.id)
1421
+ };
1422
+ }
1423
+ function selectActiveInstance(instances, activeConnectionId, idOf) {
1424
+ if (activeConnectionId) {
1425
+ const match = instances.find(instance => idOf(instance) === activeConnectionId);
1426
+ if (match)
1427
+ return match;
1428
+ }
1429
+ return instances[0];
1430
+ }
1373
1431
  //# sourceMappingURL=prepareCodegenData.js.map