@mastra/factory 0.2.0 → 0.2.1-alpha.0

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 (47) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/dist/capabilities/intake.d.ts +45 -0
  3. package/dist/capabilities/intake.d.ts.map +1 -1
  4. package/dist/factory.js +920 -549
  5. package/dist/factory.js.map +1 -1
  6. package/dist/index.js +920 -549
  7. package/dist/index.js.map +1 -1
  8. package/dist/integrations/github/integration.d.ts.map +1 -1
  9. package/dist/integrations/github/integration.js +126 -11
  10. package/dist/integrations/github/integration.js.map +1 -1
  11. package/dist/integrations/github/project-lock.d.ts +24 -2
  12. package/dist/integrations/github/project-lock.d.ts.map +1 -1
  13. package/dist/integrations/github/project-lock.js +43 -10
  14. package/dist/integrations/github/project-lock.js.map +1 -1
  15. package/dist/integrations/github/routes.js +41 -10
  16. package/dist/integrations/github/routes.js.map +1 -1
  17. package/dist/integrations/linear/agent-tools.js.map +1 -1
  18. package/dist/integrations/linear/integration.d.ts.map +1 -1
  19. package/dist/integrations/linear/integration.js +60 -1
  20. package/dist/integrations/linear/integration.js.map +1 -1
  21. package/dist/integrations/linear/routes.js.map +1 -1
  22. package/dist/integrations/platform/github/event-worker.d.ts.map +1 -1
  23. package/dist/integrations/platform/github/event-worker.js +7 -1
  24. package/dist/integrations/platform/github/event-worker.js.map +1 -1
  25. package/dist/integrations/platform/github/integration.d.ts.map +1 -1
  26. package/dist/integrations/platform/github/integration.js +104 -12
  27. package/dist/integrations/platform/github/integration.js.map +1 -1
  28. package/dist/integrations/platform/linear/integration.d.ts.map +1 -1
  29. package/dist/integrations/platform/linear/integration.js +91 -0
  30. package/dist/integrations/platform/linear/integration.js.map +1 -1
  31. package/dist/routes/fs.d.ts +16 -0
  32. package/dist/routes/fs.d.ts.map +1 -1
  33. package/dist/routes/fs.js +103 -3
  34. package/dist/routes/fs.js.map +1 -1
  35. package/dist/routes/oauth.js +564 -478
  36. package/dist/routes/oauth.js.map +1 -1
  37. package/dist/routes/projects.d.ts.map +1 -1
  38. package/dist/routes/projects.js +1 -0
  39. package/dist/routes/projects.js.map +1 -1
  40. package/dist/routes/surface.d.ts.map +1 -1
  41. package/dist/routes/surface.js +717 -526
  42. package/dist/routes/surface.js.map +1 -1
  43. package/dist/storage/domains/source-control/base.d.ts +0 -1
  44. package/dist/storage/domains/source-control/base.d.ts.map +1 -1
  45. package/dist/storage/domains/source-control/base.js +6 -7
  46. package/dist/storage/domains/source-control/base.js.map +1 -1
  47. package/package.json +4 -4
@@ -1 +1 @@
1
- {"version":3,"file":"integration.d.ts","sourceRoot":"","sources":["../../../../src/integrations/platform/linear/integration.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AACnE,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAKpD,OAAO,KAAK,EAAE,MAAM,EAAkC,MAAM,iCAAiC,CAAC;AAC9F,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAC;AAC1D,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,2CAA2C,CAAC;AACxF,OAAO,KAAK,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAE9F,OAAO,KAAK,EAAE,qBAAqB,EAAqB,MAAM,6BAA6B,CAAC;AAE5F,OAAO,KAAK,EAAwB,mBAAmB,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAC;AA6C9G,KAAK,aAAa,GAAG;IACnB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,KAAK,CAAC;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,GAAG,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;CACzD,CAAC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CAAC;IAmBlE,mBAAmB,CAAC,WAAW,EAAE,mBAAmB,GAAG,OAAO,CAAC,MAAM,CAAC;IAyB5E,eAAe,CAAC,UAAU,EAAE,mBAAmB,GAAG,OAAO;IAKnD,eAAe,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,qBAAqB,CAAC;IASpE,MAAM,CAAC,GAAG,EAAE,kBAAkB,GAAG,QAAQ,EAAE;IAoCrC,UAAU,CAAC,EAAE,cAAc,EAAE,EAAE;QAAE,cAAc,EAAE,cAAc,CAAA;KAAE,GAAG,OAAO,CAAC,gBAAgB,CAAC;IAInG,WAAW,IAAI,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IAIhC,YAAY,IAAI,OAAO,CAAC,KAAK,CAAC,aAAa,GAAG;QAAE,WAAW,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;CAkK9E"}
@@ -461,6 +461,9 @@ function redact(message, accessToken) {
461
461
  function logPlatformInfo(message, fields) {
462
462
  writePlatformLog("info", message, fields);
463
463
  }
464
+ function logPlatformWarn(message, fields) {
465
+ writePlatformLog("warn", message, fields);
466
+ }
464
467
  function logPlatformError(message, fields) {
465
468
  writePlatformLog("error", message, fields);
466
469
  }
@@ -496,7 +499,14 @@ var PlatformLinearIntegration = class {
496
499
  #endpointHost;
497
500
  #projects;
498
501
  #auth;
502
+ /**
503
+ * Per-instance workflow-state cache keyed by `${workspaceId}:${teamId}`. Scoped to the process
504
+ * lifetime; not shared across requests intentionally to keep failure modes simple (stale states
505
+ * clear on process restart). Populated lazily on first `updateIssue` per team.
506
+ */
507
+ #workflowStatesByTeam = /* @__PURE__ */ new Map();
499
508
  intake = {
509
+ resolveIntakeDispatch: (input) => this.#resolveIntakeDispatch(input),
500
510
  listSources: async () => {
501
511
  const sources = await this.#listProjectSources();
502
512
  return sources.map(({ workspace, project }) => ({
@@ -567,6 +577,59 @@ var PlatformLinearIntegration = class {
567
577
  if (isNotFound(error)) return null;
568
578
  throw error;
569
579
  }
580
+ },
581
+ updateIssue: async (input) => {
582
+ requireLinearConnection(input.connection);
583
+ const located = await this.#findIssue(input.sourceId, input.issueId);
584
+ if (!located) return null;
585
+ const { workspaceId, issue } = located;
586
+ const target = input.state;
587
+ if (target.kind === "byType" && issue.state.type === target.stateType) {
588
+ return parseIssue(issue);
589
+ }
590
+ if (target.kind === "byName" && issue.state.name.toLowerCase() === target.name.toLowerCase()) {
591
+ return parseIssue(issue);
592
+ }
593
+ let states;
594
+ try {
595
+ states = await this.#listWorkflowStates(workspaceId, issue.team.id);
596
+ } catch (error) {
597
+ if (isNotFound(error)) {
598
+ logPlatformWarn("Platform Linear: workflow-states endpoint not available; skipping updateIssue.", {
599
+ workspaceId,
600
+ teamId: issue.team.id
601
+ });
602
+ return null;
603
+ }
604
+ throw error;
605
+ }
606
+ let matched;
607
+ if (target.kind === "byType") {
608
+ matched = states.slice().sort((a, b) => a.position - b.position).find((s) => s.type === target.stateType);
609
+ } else {
610
+ const wanted = target.name.toLowerCase();
611
+ matched = states.find((s) => s.name.toLowerCase() === wanted);
612
+ }
613
+ if (!matched) {
614
+ logPlatformWarn("Platform Linear: no workflow state matched target; skipping updateIssue.", {
615
+ workspaceId,
616
+ teamId: issue.team.id,
617
+ target
618
+ });
619
+ return null;
620
+ }
621
+ try {
622
+ await this.#client.request(
623
+ "PATCH",
624
+ `${API_PREFIX}/workspaces/${encodeURIComponent(workspaceId)}/issues/${encodeURIComponent(input.issueId)}`,
625
+ { stateId: matched.id }
626
+ );
627
+ } catch (error) {
628
+ if (isNotFound(error)) return null;
629
+ throw error;
630
+ }
631
+ const refreshed = await this.#findIssue(input.sourceId, input.issueId);
632
+ return refreshed ? parseIssue(refreshed.issue) : null;
570
633
  }
571
634
  };
572
635
  constructor() {
@@ -639,6 +702,23 @@ var PlatformLinearIntegration = class {
639
702
  async getFreshAccessToken(_connection) {
640
703
  return PLATFORM_MANAGED_CONNECTION_TOKEN;
641
704
  }
705
+ /**
706
+ * Background-dispatch context: platform-managed connection token when the
707
+ * org has a connected workspace. Linear work items store the issue UUID
708
+ * directly as `externalId`.
709
+ */
710
+ async #resolveIntakeDispatch({
711
+ orgId,
712
+ externalSource
713
+ }) {
714
+ if (externalSource.type !== "issue") return null;
715
+ const connection = await this.loadConnection(orgId);
716
+ if (!connection) return null;
717
+ return {
718
+ connection: { type: "oauth", accessToken: PLATFORM_MANAGED_CONNECTION_TOKEN },
719
+ issueId: externalSource.externalId
720
+ };
721
+ }
642
722
  canPostComments(connection) {
643
723
  const scopes = (connection.scope ?? "").split(/[\s,]+/).filter(Boolean);
644
724
  return scopes.some((scope) => scope === "comments:create" || scope === "write" || scope === "admin");
@@ -798,6 +878,17 @@ var PlatformLinearIntegration = class {
798
878
  }
799
879
  return null;
800
880
  }
881
+ async #listWorkflowStates(workspaceId, teamId) {
882
+ const cacheKey = `${workspaceId}:${teamId}`;
883
+ const cached = this.#workflowStatesByTeam.get(cacheKey);
884
+ if (cached) return cached;
885
+ const result = await this.#client.request(
886
+ "GET",
887
+ `${API_PREFIX}/workspaces/${encodeURIComponent(workspaceId)}/workflow-states?teamId=${encodeURIComponent(teamId)}&first=100`
888
+ );
889
+ this.#workflowStatesByTeam.set(cacheKey, result.workflowStates);
890
+ return result.workflowStates;
891
+ }
801
892
  async #candidateWorkspaceIds(sourceId) {
802
893
  if (sourceId) return [decodeSourceId(sourceId).workspaceId];
803
894
  return (await this.#listWorkspaces()).map((workspace) => workspace.linearWorkspaceId);