@cat-factory/integrations 0.146.0 → 0.148.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 (90) hide show
  1. package/dist/index.d.ts +6 -2
  2. package/dist/index.d.ts.map +1 -1
  3. package/dist/index.js +7 -1
  4. package/dist/index.js.map +1 -1
  5. package/dist/modules/accountSettings/AccountSettingsService.d.ts.map +1 -1
  6. package/dist/modules/accountSettings/AccountSettingsService.js +4 -2
  7. package/dist/modules/accountSettings/AccountSettingsService.js.map +1 -1
  8. package/dist/modules/documents/ConfluenceProvider.d.ts +3 -0
  9. package/dist/modules/documents/ConfluenceProvider.d.ts.map +1 -1
  10. package/dist/modules/documents/DocumentConnectionService.d.ts +86 -5
  11. package/dist/modules/documents/DocumentConnectionService.d.ts.map +1 -1
  12. package/dist/modules/documents/DocumentConnectionService.js +103 -14
  13. package/dist/modules/documents/DocumentConnectionService.js.map +1 -1
  14. package/dist/modules/documents/DocumentLinkService.d.ts +28 -1
  15. package/dist/modules/documents/DocumentLinkService.d.ts.map +1 -1
  16. package/dist/modules/documents/DocumentLinkService.js +78 -10
  17. package/dist/modules/documents/DocumentLinkService.js.map +1 -1
  18. package/dist/modules/documents/DocumentPlannerService.d.ts +11 -2
  19. package/dist/modules/documents/DocumentPlannerService.d.ts.map +1 -1
  20. package/dist/modules/documents/DocumentPlannerService.js +95 -12
  21. package/dist/modules/documents/DocumentPlannerService.js.map +1 -1
  22. package/dist/modules/documents/DocumentSourceOAuthService.d.ts +88 -0
  23. package/dist/modules/documents/DocumentSourceOAuthService.d.ts.map +1 -0
  24. package/dist/modules/documents/DocumentSourceOAuthService.js +197 -0
  25. package/dist/modules/documents/DocumentSourceOAuthService.js.map +1 -0
  26. package/dist/modules/documents/FigmaProvider.d.ts +10 -0
  27. package/dist/modules/documents/FigmaProvider.d.ts.map +1 -1
  28. package/dist/modules/documents/FigmaProvider.js +17 -6
  29. package/dist/modules/documents/FigmaProvider.js.map +1 -1
  30. package/dist/modules/documents/GitHubDocsProvider.d.ts +3 -0
  31. package/dist/modules/documents/GitHubDocsProvider.d.ts.map +1 -1
  32. package/dist/modules/documents/LinearDocumentProvider.d.ts +3 -0
  33. package/dist/modules/documents/LinearDocumentProvider.d.ts.map +1 -1
  34. package/dist/modules/documents/LinkedDocumentRefreshService.d.ts +14 -5
  35. package/dist/modules/documents/LinkedDocumentRefreshService.d.ts.map +1 -1
  36. package/dist/modules/documents/LinkedDocumentRefreshService.js +39 -22
  37. package/dist/modules/documents/LinkedDocumentRefreshService.js.map +1 -1
  38. package/dist/modules/documents/NotionProvider.d.ts +3 -0
  39. package/dist/modules/documents/NotionProvider.d.ts.map +1 -1
  40. package/dist/modules/documents/ZeplinProvider.d.ts +3 -0
  41. package/dist/modules/documents/ZeplinProvider.d.ts.map +1 -1
  42. package/dist/modules/documents/documentConnectionStore.d.ts +19 -0
  43. package/dist/modules/documents/documentConnectionStore.d.ts.map +1 -0
  44. package/dist/modules/documents/documentConnectionStore.js +17 -0
  45. package/dist/modules/documents/documentConnectionStore.js.map +1 -0
  46. package/dist/modules/documents/documents.logic.d.ts +44 -3
  47. package/dist/modules/documents/documents.logic.d.ts.map +1 -1
  48. package/dist/modules/documents/documents.logic.js +90 -5
  49. package/dist/modules/documents/documents.logic.js.map +1 -1
  50. package/dist/modules/documents/figma.logic.d.ts +10 -2
  51. package/dist/modules/documents/figma.logic.d.ts.map +1 -1
  52. package/dist/modules/documents/figma.logic.js +30 -2
  53. package/dist/modules/documents/figma.logic.js.map +1 -1
  54. package/dist/modules/github/GitHubInstallationService.d.ts +8 -1
  55. package/dist/modules/github/GitHubInstallationService.d.ts.map +1 -1
  56. package/dist/modules/github/GitHubInstallationService.js +4 -3
  57. package/dist/modules/github/GitHubInstallationService.js.map +1 -1
  58. package/dist/modules/shared/sealedConnectionStore.d.ts +100 -0
  59. package/dist/modules/shared/sealedConnectionStore.d.ts.map +1 -0
  60. package/dist/modules/shared/sealedConnectionStore.js +118 -0
  61. package/dist/modules/shared/sealedConnectionStore.js.map +1 -0
  62. package/dist/modules/tasks/BugHuntService.d.ts +2 -2
  63. package/dist/modules/tasks/BugHuntService.d.ts.map +1 -1
  64. package/dist/modules/tasks/BugHuntService.js +1 -1
  65. package/dist/modules/tasks/BugHuntService.js.map +1 -1
  66. package/dist/modules/tasks/BugIntakeService.d.ts +2 -2
  67. package/dist/modules/tasks/BugIntakeService.d.ts.map +1 -1
  68. package/dist/modules/tasks/BugIntakeService.js +1 -1
  69. package/dist/modules/tasks/BugIntakeService.js.map +1 -1
  70. package/dist/modules/tasks/TaskConnectionService.d.ts +43 -4
  71. package/dist/modules/tasks/TaskConnectionService.d.ts.map +1 -1
  72. package/dist/modules/tasks/TaskConnectionService.js +122 -22
  73. package/dist/modules/tasks/TaskConnectionService.js.map +1 -1
  74. package/dist/modules/tasks/TrackerWebhookService.d.ts +2 -2
  75. package/dist/modules/tasks/TrackerWebhookService.d.ts.map +1 -1
  76. package/dist/modules/tasks/TrackerWebhookService.js +1 -1
  77. package/dist/modules/tasks/TrackerWebhookService.js.map +1 -1
  78. package/dist/modules/tasks/taskConnectionStore.d.ts +18 -0
  79. package/dist/modules/tasks/taskConnectionStore.d.ts.map +1 -0
  80. package/dist/modules/tasks/taskConnectionStore.js +17 -0
  81. package/dist/modules/tasks/taskConnectionStore.js.map +1 -0
  82. package/dist/modules/vcs/VcsPatConnectionService.d.ts +9 -1
  83. package/dist/modules/vcs/VcsPatConnectionService.d.ts.map +1 -1
  84. package/dist/modules/vcs/VcsPatConnectionService.js +4 -3
  85. package/dist/modules/vcs/VcsPatConnectionService.js.map +1 -1
  86. package/dist/modules/writeback/IssueWritebackService.d.ts +7 -2
  87. package/dist/modules/writeback/IssueWritebackService.d.ts.map +1 -1
  88. package/dist/modules/writeback/IssueWritebackService.js +31 -11
  89. package/dist/modules/writeback/IssueWritebackService.js.map +1 -1
  90. package/package.json +4 -4
@@ -1 +1 @@
1
- {"version":3,"file":"DocumentConnectionService.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IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,EAAE;YAChC,SAAS,EAAE,IAAI;SAChB,CAAA;IACH,CAAC;IAED,oDAAoD;IACpD,KAAK,CAAC,UAAU,CAAC,WAAmB,EAAE,MAA0B;QAC9D,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,IAAI,CAAC,4BAA4B,CAAC,cAAc,CAAC,WAAW,EAAE,MAAM,CAAC,CAAA;QAC/F,IAAI,CAAC,MAAM;YAAE,OAAM;QACnB,MAAM,IAAI,CAAC,IAAI,CAAC,4BAA4B,CAAC,UAAU,CACrD,WAAW,EACX,MAAM,EACN,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,EAAE,CACtB,CAAA;QACD,0FAA0F;QAC1F,yFAAyF;QACzF,8DAA8D;QAC9D,MAAM,IAAI,CAAC,IAAI,CAAC,YAAY,EAAE,eAAe,CAAC,WAAW,CAAC,CAAA;IAC5D,CAAC;CACF"}
1
+ {"version":3,"file":"DocumentConnectionService.js","sourceRoot":"","sources":["../../../src/modules/documents/DocumentConnectionService.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAA;AAS/D,OAAO,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAA;AACpE,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAA;AAqEtD,qEAAqE;AACrE,SAAS,YAAY,CAAC,MAIrB;IACC,OAAO;QACL,MAAM,EAAE,MAAM,CAAC,MAAM;QACrB,KAAK,EAAE,MAAM,CAAC,KAAK;QACnB,WAAW,EAAE,MAAM,CAAC,SAAS;KAC9B,CAAA;AACH,CAAC;AAED,MAAM,OAAO,yBAAyB;IAGP,IAAI;IAFhB,GAAG,CAAQ;IAE5B,YAA6B,IAA2C;oBAA3C,IAAI;QAC/B,IAAI,CAAC,GAAG,GAAG,IAAI,CAAC,MAAM,IAAI,UAAU,CAAA;IACtC,CAAC;IAED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;CACF"}
@@ -3,6 +3,7 @@ import type { BlockEditAuthority } from '@cat-factory/contracts';
3
3
  import type { BlockRepository } from '@cat-factory/kernel';
4
4
  import type { DocumentRepository } from '@cat-factory/kernel';
5
5
  import type { BoardWritePort } from '@cat-factory/kernel';
6
+ import type { PlanTarget } from './documents.logic.js';
6
7
  export interface DocumentLinkServiceDependencies {
7
8
  boardService: BoardWritePort;
8
9
  blockRepository: BlockRepository;
@@ -13,10 +14,29 @@ export interface SpawnResult {
13
14
  frames: number;
14
15
  modules: number;
15
16
  tasks: number;
17
+ /**
18
+ * Planned modules whose tasks went into a module the frame ALREADY had, rather than into a new
19
+ * one (see {@link DocumentLinkService.spawnInto}).
20
+ *
21
+ * Reported rather than folded into `modules`, because the two answer different questions and
22
+ * only one of them is about what changed. Without it a spawn that reused every module reports
23
+ * "0 modules · 12 tasks" against a preview that showed three, which reads as three modules
24
+ * having failed; and counting a reuse as a creation would claim a write that never happened.
25
+ */
26
+ reusedModules: number;
16
27
  }
17
28
  export declare class DocumentLinkService {
18
29
  private readonly deps;
19
30
  constructor(deps: DocumentLinkServiceDependencies);
31
+ /**
32
+ * Describe an existing service frame as a {@link PlanTarget}, so a plan can be authored FOR it.
33
+ *
34
+ * It lives here rather than in the planner because it is a fact about the BOARD: the planner is
35
+ * a pure document→structure translator and must not learn to query blocks for a prompt detail.
36
+ * It refuses exactly what {@link spawn} refuses, one step earlier, so a preview cannot be
37
+ * rendered against a target the write would then reject.
38
+ */
39
+ resolvePlanTarget(workspaceId: string, frameId: string): Promise<PlanTarget>;
20
40
  /**
21
41
  * Apply a board plan to a workspace. Without `frameId` each planned frame
22
42
  * becomes a new top-level frame; with it, the plan's modules and tasks are
@@ -27,7 +47,14 @@ export declare class DocumentLinkService {
27
47
  * comes from the caller rather than being decided here (see {@link BlockEditAuthority}).
28
48
  */
29
49
  spawn(workspaceId: string, plan: DocumentBoardPlan, editor: BlockEditAuthority, frameId?: string): Promise<SpawnResult>;
30
- /** Add a planned frame's modules and tasks inside an existing frame. */
50
+ /**
51
+ * Add a planned frame's modules and tasks inside an existing frame.
52
+ *
53
+ * `modulesByName` is the frame's modules indexed by {@link moduleKey}, and it is both the input
54
+ * and the running record: a module created here is registered in it, so two planned modules that
55
+ * name the same thing converge on one block exactly as a planned name matching a pre-existing
56
+ * module does. A freshly created frame passes an empty map and every module is new.
57
+ */
31
58
  private spawnInto;
32
59
  private addTask;
33
60
  /** Attach an imported (or uploaded) document to a board block as extra agent context. */
@@ -1 +1 @@
1
- {"version":3,"file":"DocumentLinkService.d.ts","sourceRoot":"","sources":["../../../src/modules/documents/DocumentLinkService.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAEV,OAAO,EACP,iBAAiB,EACjB,gBAAgB,EAEhB,WAAW,EACX,cAAc,EACd,cAAc,EAEf,MAAM,qBAAqB,CAAA;AAC5B,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAA;AAEhE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAA;AAC1D,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAA;AAC7D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAA;AAczD,MAAM,WAAW,+BAA+B;IAC9C,YAAY,EAAE,cAAc,CAAA;IAC5B,eAAe,EAAE,eAAe,CAAA;IAChC,kBAAkB,EAAE,kBAAkB,CAAA;CACvC;AAED,iEAAiE;AACjE,MAAM,WAAW,WAAW;IAC1B,MAAM,EAAE,MAAM,CAAA;IACd,OAAO,EAAE,MAAM,CAAA;IACf,KAAK,EAAE,MAAM,CAAA;CACd;AAED,qBAAa,mBAAmB;IAClB,OAAO,CAAC,QAAQ,CAAC,IAAI;IAAjC,YAA6B,IAAI,EAAE,+BAA+B,EAAI;IAEtE;;;;;;;;OAQG;IACG,KAAK,CACT,WAAW,EAAE,MAAM,EACnB,IAAI,EAAE,iBAAiB,EACvB,MAAM,EAAE,kBAAkB,EAC1B,OAAO,CAAC,EAAE,MAAM,GACf,OAAO,CAAC,WAAW,CAAC,CAmCtB;IAED,wEAAwE;YAC1D,SAAS;YAqBT,OAAO;IA4BrB,yFAAyF;IACnF,WAAW,CACf,WAAW,EAAE,MAAM,EACnB,OAAO,EAAE,MAAM,EACf,MAAM,EAAE,cAAc,EACtB,UAAU,EAAE,MAAM,GACjB,OAAO,CAAC,cAAc,CAAC,CAGzB;IAED;;;;;;;;OAQG;IACG,eAAe,CACnB,WAAW,EAAE,MAAM,EACnB,OAAO,EAAE,MAAM,EACf,IAAI,EAAE,SAAS,WAAW,EAAE,GAC3B,OAAO,CAAC,cAAc,EAAE,CAAC,CAqB3B;IAED;;;;;;;;;;;;OAYG;IACG,WAAW,CAAC,WAAW,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAErE;IAED;;;;;;;;;;;;OAYG;YACW,sBAAsB;IA0BpC;;;;;;OAMG;IACG,WAAW,CACf,WAAW,EAAE,MAAM,EACnB,MAAM,EAAE,cAAc,EACtB,UAAU,EAAE,MAAM,EAClB,IAAI,EAAE,gBAAgB,EACtB,OAAO,EAAE,OAAO,GACf,OAAO,CAAC,cAAc,CAAC,CAWzB;IAED,oGAAoG;IAC9F,aAAa,CACjB,WAAW,EAAE,MAAM,EACnB,MAAM,EAAE,cAAc,EACtB,UAAU,EAAE,MAAM,GACjB,OAAO,CAAC,IAAI,CAAC,CAEf;IAED,gGAAgG;IAC1F,aAAa,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,EAAE,CAAC,CAGlE;CACF"}
1
+ {"version":3,"file":"DocumentLinkService.d.ts","sourceRoot":"","sources":["../../../src/modules/documents/DocumentLinkService.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAEV,OAAO,EACP,iBAAiB,EACjB,gBAAgB,EAEhB,WAAW,EACX,cAAc,EACd,cAAc,EAEf,MAAM,qBAAqB,CAAA;AAC5B,OAAO,KAAK,E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M,EACnB,OAAO,EAAE,MAAM,EACf,IAAI,EAAE,SAAS,WAAW,EAAE,GAC3B,OAAO,CAAC,cAAc,EAAE,CAAC,CAqB3B;IAED;;;;;;;;;;;;OAYG;IACG,WAAW,CAAC,WAAW,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAErE;IAED;;;;;;;;;;;;OAYG;YACW,sBAAsB;IA0BpC;;;;;;OAMG;IACG,WAAW,CACf,WAAW,EAAE,MAAM,EACnB,MAAM,EAAE,cAAc,EACtB,UAAU,EAAE,MAAM,EAClB,IAAI,EAAE,gBAAgB,EACtB,OAAO,EAAE,OAAO,GACf,OAAO,CAAC,cAAc,CAAC,CAWzB;IAED,oGAAoG;IAC9F,aAAa,CACjB,WAAW,EAAE,MAAM,EACnB,MAAM,EAAE,cAAc,EACtB,UAAU,EAAE,MAAM,GACjB,OAAO,CAAC,IAAI,CAAC,CAEf;IAED,gGAAgG;IAC1F,aAAa,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,EAAE,CAAC,CAGlE;CACF"}
@@ -4,11 +4,49 @@ import { toSourceDocument } from './DocumentImportService.js';
4
4
  function refKey(ref) {
5
5
  return `${ref.source}:${ref.externalId}`;
6
6
  }
7
+ /**
8
+ * The key a planned module name is matched against an existing one by.
9
+ *
10
+ * Case- and whitespace-insensitive on purpose: the planner is TOLD to reuse the names it was
11
+ * shown, but the thing being asked is a language model, and "Checkout" against "checkout" is a
12
+ * duplicate module on the board either way. Matching exactly would make the reuse work in testing
13
+ * and fail on the drift it exists to absorb.
14
+ */
15
+ function moduleKey(name) {
16
+ return name.trim().toLowerCase();
17
+ }
7
18
  export class DocumentLinkService {
8
19
  deps;
9
20
  constructor(deps) {
10
21
  this.deps = deps;
11
22
  }
23
+ /**
24
+ * Describe an existing service frame as a {@link PlanTarget}, so a plan can be authored FOR it.
25
+ *
26
+ * It lives here rather than in the planner because it is a fact about the BOARD: the planner is
27
+ * a pure document→structure translator and must not learn to query blocks for a prompt detail.
28
+ * It refuses exactly what {@link spawn} refuses, one step earlier, so a preview cannot be
29
+ * rendered against a target the write would then reject.
30
+ */
31
+ async resolvePlanTarget(workspaceId, frameId) {
32
+ const frame = assertFound(await this.deps.blockRepository.get(workspaceId, frameId), 'Block', frameId);
33
+ if (frame.level !== 'frame') {
34
+ throw new ValidationError('Document structure can only be planned into a service frame', {
35
+ reason: 'plan_target_not_a_frame',
36
+ });
37
+ }
38
+ const blocks = await this.deps.blockRepository.listByWorkspace(workspaceId);
39
+ return {
40
+ frameId,
41
+ title: frame.title,
42
+ type: frame.type,
43
+ // The names the frame ALREADY holds, so the plan adds beside them instead of proposing a
44
+ // second module meaning the same thing. One board read rather than a per-module lookup.
45
+ existingModules: blocks
46
+ .filter((b) => b.parentId === frameId && b.level === 'module')
47
+ .map((b) => b.title),
48
+ };
49
+ }
12
50
  /**
13
51
  * Apply a board plan to a workspace. Without `frameId` each planned frame
14
52
  * becomes a new top-level frame; with it, the plan's modules and tasks are
@@ -19,14 +57,22 @@ export class DocumentLinkService {
19
57
  * comes from the caller rather than being decided here (see {@link BlockEditAuthority}).
20
58
  */
21
59
  async spawn(workspaceId, plan, editor, frameId) {
22
- const result = { frames: 0, modules: 0, tasks: 0 };
60
+ const result = { frames: 0, modules: 0, tasks: 0, reusedModules: 0 };
23
61
  if (frameId) {
24
62
  const target = assertFound(await this.deps.blockRepository.get(workspaceId, frameId), 'Block', frameId);
25
63
  if (target.level !== 'frame') {
26
64
  throw new ValidationError('Document structure can only be spawned into a service frame');
27
65
  }
66
+ // The frame's existing modules, read ONCE for the whole spawn and indexed by name. This is
67
+ // the write half of what `resolvePlanTarget` showed the planner: the prompt asks the model to
68
+ // reuse the names it was given, and until this existed nothing acted on the answer, so a plan
69
+ // that obeyed produced a second "Checkout" beside the first. A model's cooperation is not an
70
+ // implementation — the platform has to COMPUTE the reuse.
71
+ const existing = new Map((await this.deps.blockRepository.listByWorkspace(workspaceId))
72
+ .filter((block) => block.parentId === frameId && block.level === 'module')
73
+ .map((block) => [moduleKey(block.title), block.id]));
28
74
  for (const frame of plan.frames) {
29
- await this.spawnInto(workspaceId, target.id, frame, result, editor);
75
+ await this.spawnInto(workspaceId, target.id, frame, result, editor, existing);
30
76
  }
31
77
  return result;
32
78
  }
@@ -39,22 +85,44 @@ export class DocumentLinkService {
39
85
  column += 1;
40
86
  result.frames += 1;
41
87
  await this.deps.boardService.updateBlock(workspaceId, created.id, { title: frame.title, ...(frame.description ? { description: frame.description } : {}) }, editor);
42
- await this.spawnInto(workspaceId, created.id, frame, result, editor);
88
+ // A frame created a line ago holds nothing, so its index starts empty; it still travels,
89
+ // because two planned modules within ONE frame can name the same thing.
90
+ await this.spawnInto(workspaceId, created.id, frame, result, editor, new Map());
43
91
  }
44
92
  return result;
45
93
  }
46
- /** Add a planned frame's modules and tasks inside an existing frame. */
47
- async spawnInto(workspaceId, frameId, frame, result, editor) {
94
+ /**
95
+ * Add a planned frame's modules and tasks inside an existing frame.
96
+ *
97
+ * `modulesByName` is the frame's modules indexed by {@link moduleKey}, and it is both the input
98
+ * and the running record: a module created here is registered in it, so two planned modules that
99
+ * name the same thing converge on one block exactly as a planned name matching a pre-existing
100
+ * module does. A freshly created frame passes an empty map and every module is new.
101
+ */
102
+ async spawnInto(workspaceId, frameId, frame, result, editor, modulesByName) {
48
103
  for (const task of frame.tasks) {
49
104
  await this.addTask(workspaceId, frameId, task, result, editor);
50
105
  }
51
106
  for (const planModule of frame.modules) {
52
- const module = await this.deps.boardService.addModule(workspaceId, frameId, {
53
- name: planModule.name,
54
- });
55
- result.modules += 1;
107
+ const key = moduleKey(planModule.name);
108
+ // A module with nothing but whitespace for a name is not a module to reuse OR to key on: it
109
+ // would collapse every such module onto one block. Treated as its own new module each time.
110
+ const reused = key ? modulesByName.get(key) : undefined;
111
+ let moduleId = reused;
112
+ if (moduleId === undefined) {
113
+ const created = await this.deps.boardService.addModule(workspaceId, frameId, {
114
+ name: planModule.name,
115
+ });
116
+ moduleId = created.id;
117
+ result.modules += 1;
118
+ if (key)
119
+ modulesByName.set(key, moduleId);
120
+ }
121
+ else {
122
+ result.reusedModules += 1;
123
+ }
56
124
  for (const task of planModule.tasks) {
57
- await this.addTask(workspaceId, module.id, task, result, editor);
125
+ await this.addTask(workspaceId, moduleId, task, result, editor);
58
126
  }
59
127
  }
60
128
  }
@@ -1 +1 @@
1
- {"version":3,"file":"DocumentLinkService.js","sourceRoot":"","sources":["../../../src/modules/documents/DocumentLinkService.ts"],"names":[],"mappings":"AAYA,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAA;AAIjF,OAAO,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAA;AAE7D,mGAAmG;AACnG,SAAS,MAAM,CAAC,GAAgB;IAC9B,OAAO,GAAG,GAAG,CAAC,MAAM,IAAI,GAAG,CAAC,UAAU,EAAE,CAAA;AAC1C,CAAC;AAqBD,MAAM,OAAO,mBAAmB;IACD,IAAI;IAAjC,YAA6B,IAAqC;oBAArC,IAAI;IAAoC,CAAC;IAEtE;;;;;;;;OAQG;IACH,KAAK,CAAC,KAAK,CACT,WAAmB,EACnB,IAAuB,EACvB,MAA0B,EAC1B,OAAgB;QAEhB,MAAM,MAAM,GAAgB,EAAE,MAAM,EAAE,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,CAAA;QAE/D,IAAI,OAAO,EAAE,CAAC;YACZ,MAAM,MAAM,GAAG,WAAW,CACxB,MAAM,IAAI,CAAC,IAAI,CAAC,eAAe,CAAC,GAAG,CAAC,WAAW,EAAE,OAAO,CAAC,EACzD,OAAO,EACP,OAAO,CACR,CAAA;YACD,IAAI,MAAM,CAAC,KAAK,KAAK,OAAO,EAAE,CAAC;gBAC7B,MAAM,IAAI,eAAe,CAAC,6DAA6D,CAAC,CAAA;YAC1F,CAAC;YACD,KAAK,MAAM,KAAK,IAAI,IAAI,CAA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CAAA;IACzD,CAAC;IAED,oGAAoG;IACpG,KAAK,CAAC,aAAa,CACjB,WAAmB,EACnB,MAAsB,EACtB,UAAkB;QAElB,MAAM,IAAI,CAAC,IAAI,CAAC,kBAAkB,CAAC,SAAS,CAAC,WAAW,EAAE,MAAM,EAAE,UAAU,CAAC,CAAA;IAC/E,CAAC;IAED,gGAAgG;IAChG,KAAK,CAAC,aAAa,CAAC,WAAmB;QACrC,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,IAAI,CAAC,kBAAkB,CAAC,wBAAwB,CAAC,WAAW,CAAC,CAAA;QACrF,OAAO,IAAI,CAAC,GAAG,CAAC,gBAAgB,CAAC,CAAA;IACnC,CAAC;CACF"}
@@ -1,6 +1,7 @@
1
1
  import type { ModelProvider, ModelProviderResolver, ModelRef } from '@cat-factory/kernel';
2
2
  import type { DocumentRecord } from '@cat-factory/kernel';
3
3
  import type { DocumentBoardPlan } from '@cat-factory/kernel';
4
+ import { type PlanTarget } from './documents.logic.js';
4
5
  export interface DocumentPlannerServiceDependencies {
5
6
  /**
6
7
  * Resolve a {@link ModelProvider} for a workspace's credential scope (DB-backed key
@@ -17,7 +18,15 @@ export declare class DocumentPlannerService {
17
18
  constructor(deps: DocumentPlannerServiceDependencies);
18
19
  /** Whether LLM planning is available (a model provider/resolver + ref are configured). */
19
20
  get llmEnabled(): boolean;
20
- /** Propose a board structure for an imported document. */
21
- plan(record: DocumentRecord): Promise<DocumentBoardPlan>;
21
+ /**
22
+ * Propose a board structure for an imported document, either at the board root or inside an
23
+ * existing service frame.
24
+ *
25
+ * The fallback is always the same SHAPE as the request: a targeted plan that could not be
26
+ * produced degrades to the targeted heading parser, never to a board-wide plan, because the
27
+ * caller is about to spawn into one frame and a whole architecture flattened into it is the
28
+ * discarding the target-aware path exists to prevent.
29
+ */
30
+ plan(record: DocumentRecord, target?: PlanTarget): Promise<DocumentBoardPlan>;
22
31
  }
23
32
  //# sourceMappingURL=DocumentPlannerService.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"DocumentPlannerService.d.ts","sourceRoot":"","sources":["../../../src/modules/documents/DocumentPlannerService.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,qBAAqB,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAA;AACzF,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAA;AACzD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAA;AAc5D,MAAM,WAAW,kCAAkC;IACjD;;;OAGG;IACH,qBAAqB,CAAC,EAAE,qBAAqB,CAAA;IAC7C,0FAA0F;IAC1F,aAAa,CAAC,EAAE,aAAa,CAAA;IAC7B,uEAAuE;IACvE,QAAQ,CAAC,EAAE,QAAQ,CAAA;CACpB;AAgCD,qBAAa,sBAAsB;IACrB,OAAO,CAAC,QAAQ,CAAC,IAAI;IAAjC,YAA6B,IAAI,EAAE,kCAAkC,EAAI;IAEzE,0FAA0F;IAC1F,IAAI,UAAU,IAAI,OAAO,CAExB;IAED,0DAA0D;IACpD,IAAI,CAAC,MAAM,EAAE,cAAc,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAiC7D;CACF"}
1
+ {"version":3,"file":"DocumentPlannerService.d.ts","sourceRoot":"","sources":["../../../src/modules/documents/DocumentPlannerService.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,qBAAqB,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAA;AACzF,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAA;AACzD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAA;AAG5D,OAAO,EAKL,KAAK,UAAU,EAChB,MAAM,sBAAsB,CAAA;AAuB7B,MAAM,WAAW,kCAAkC;IACjD;;;OAGG;IACH,qBAAqB,CAAC,EAAE,qBAAqB,CAAA;IAC7C,0FAA0F;IAC1F,aAAa,CAAC,EAAE,aAAa,CAAA;IAC7B,uEAAuE;IACvE,QAAQ,CAAC,EAAE,QAAQ,CAAA;CACpB;AA+FD,qBAAa,sBAAsB;IACrB,OAAO,CAAC,QAAQ,CAAC,IAAI;IAAjC,YAA6B,IAAI,EAAE,kCAAkC,EAAI;IAEzE,0FAA0F;IAC1F,IAAI,UAAU,IAAI,OAAO,CAExB;IAED;;;;;;;;OAQG;IACG,IAAI,CAAC,MAAM,EAAE,cAAc,EAAE,MAAM,CAAC,EAAE,UAAU,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAsClF;CACF"}
@@ -1,6 +1,7 @@
1
1
  import { generateText } from 'ai';
2
2
  import { catFactoryObservability, extractJson } from '@cat-factory/kernel';
3
- import { coercePlan, markdownToText, planFromHeadings } from './documents.logic.js';
3
+ import { isDesignSource } from '@cat-factory/contracts';
4
+ import { coercePlan, coerceTargetedPlan, markdownToText, planFromHeadings, } from './documents.logic.js';
4
5
  // DocumentPlannerService: turns an imported document into a proposed board
5
6
  // structure (frames → modules → tasks). When a model is configured it asks an
6
7
  // LLM, via the provider-agnostic ModelProvider port, to extract the structure;
@@ -8,17 +9,56 @@ import { coercePlan, markdownToText, planFromHeadings } from './documents.logic.
8
9
  // deterministic heading parser. The LLM is therefore optional: import, link and
9
10
  // spawn all work without it. Source-agnostic, because providers normalize bodies
10
11
  // to Markdown before they reach here.
12
+ //
13
+ // Two axes decide which prompt runs, and they are independent:
14
+ //
15
+ // - TARGET. Without a {@link PlanTarget} the question is "what architecture does this document
16
+ // describe"; with one it is "what work does it imply inside this service that already exists".
17
+ // They are different prompts rather than one prompt with a hint, because the answers have
18
+ // different shapes: the first proposes frames, the second may not propose any.
19
+ // - ORIGIN. A design document describes screens, not an architecture, so asking the
20
+ // architecture question of one produces a service per Figma page. `isDesignSource` decides,
21
+ // read from CONTRACTS rather than from a provider, for the same reason the design-guidance
22
+ // fragment reads it there: this path holds a stored row and no provider.
11
23
  const MAX_BODY_CHARS = 6000;
12
24
  const SYSTEM_PROMPT = 'You are a software architect. You convert a product/requirements/RFC document into a ' +
13
25
  'concrete software-architecture board: top-level frames (services), modules within them, ' +
14
26
  'and tasks (units of work). Respond with ONLY a JSON object, no prose, no code fences.';
15
- function buildUserPrompt(title, body) {
16
- const text = markdownToText(body).slice(0, MAX_BODY_CHARS);
27
+ /**
28
+ * The targeted system prompt. It states the ONE thing the board-wide prompt must not be allowed
29
+ * to carry over: the service exists, so proposing services is out of scope. Without that said
30
+ * outright, a model handed a document and a frame name routinely answers with an architecture
31
+ * whose first frame happens to be the target.
32
+ */
33
+ const TARGETED_SYSTEM_PROMPT = 'You are a technical lead planning work inside a service that ALREADY EXISTS. You never ' +
34
+ 'propose new services or repositories; you propose modules (groupings) and tasks (units of ' +
35
+ 'work) to add to the service you are given. Respond with ONLY a JSON object, no prose, no ' +
36
+ 'code fences.';
37
+ /**
38
+ * What a DESIGN document is, said to the model in the terms it must plan in.
39
+ *
40
+ * Folded into both prompts rather than replacing them, because the change a design origin makes
41
+ * is to the SUBJECT, not to the shape of the answer: the document describes screens and flows,
42
+ * and one task per screen/flow is the decomposition an implementer can act on. The alternative,
43
+ * a whole third prompt pair, would duplicate the JSON contract in four places.
44
+ */
45
+ const DESIGN_GUIDANCE = [
46
+ 'This document is a DESIGN (frames, components and tokens exported from a design tool), not a',
47
+ 'written specification. Plan the work it implies to BUILD it: one task per screen, state or',
48
+ 'flow it shows, named after the frame it comes from so an implementer can find it in the file.',
49
+ 'Do not propose tasks for design work itself, and do not invent backend services the design',
50
+ 'does not evidence — a design describes an interface, and what sits behind it is not in it.',
51
+ ].join(' ');
52
+ function documentText(record) {
53
+ return markdownToText(record.body).slice(0, MAX_BODY_CHARS);
54
+ }
55
+ function buildUserPrompt(record) {
17
56
  return [
18
- `Document title: ${title}`,
57
+ `Document title: ${record.title}`,
58
+ ...(isDesignSource(record.source) ? ['', DESIGN_GUIDANCE] : []),
19
59
  '',
20
60
  'Document content:',
21
- text,
61
+ documentText(record),
22
62
  '',
23
63
  'Produce a JSON object of this exact shape:',
24
64
  '{',
@@ -36,6 +76,36 @@ function buildUserPrompt(title, body) {
36
76
  'Group related work into modules; keep titles short and imperative. Output JSON only.',
37
77
  ].join('\n');
38
78
  }
79
+ /**
80
+ * The target-aware prompt.
81
+ *
82
+ * It names the modules the frame already holds so the plan ADDS to them: a model that cannot see
83
+ * the board proposes "Checkout" beside the "Checkout" that is already there, and the spawn
84
+ * happily creates the duplicate.
85
+ */
86
+ function buildTargetedUserPrompt(record, target) {
87
+ return [
88
+ `Existing service: ${target.title} (type: ${target.type})`,
89
+ target.existingModules.length > 0
90
+ ? `Modules it already has: ${target.existingModules.join(', ')}. Reuse these names for work that belongs in them rather than proposing a second module with the same meaning.`
91
+ : 'It has no modules yet.',
92
+ '',
93
+ `Document title: ${record.title}`,
94
+ ...(isDesignSource(record.source) ? ['', DESIGN_GUIDANCE] : []),
95
+ '',
96
+ 'Document content:',
97
+ documentText(record),
98
+ '',
99
+ 'Produce a JSON object of this exact shape:',
100
+ '{',
101
+ ' "modules": [ { "name": "string", "tasks": [ { "title": "string", "description": "string (optional)" } ] } ],',
102
+ ' "tasks": [ { "title": "string", "description": "string (optional)" } ]',
103
+ '}',
104
+ '',
105
+ 'Modules group related tasks; `tasks` holds work that belongs to no module. Keep titles',
106
+ 'short and imperative. Output JSON only.',
107
+ ].join('\n');
108
+ }
39
109
  export class DocumentPlannerService {
40
110
  deps;
41
111
  constructor(deps) {
@@ -45,9 +115,17 @@ export class DocumentPlannerService {
45
115
  get llmEnabled() {
46
116
  return (!!this.deps.modelProviderResolver || !!this.deps.modelProvider) && !!this.deps.modelRef;
47
117
  }
48
- /** Propose a board structure for an imported document. */
49
- async plan(record) {
50
- const fallback = () => planFromHeadings(record.source, record.externalId, record.title, record.body);
118
+ /**
119
+ * Propose a board structure for an imported document, either at the board root or inside an
120
+ * existing service frame.
121
+ *
122
+ * The fallback is always the same SHAPE as the request: a targeted plan that could not be
123
+ * produced degrades to the targeted heading parser, never to a board-wide plan, because the
124
+ * caller is about to spawn into one frame and a whole architecture flattened into it is the
125
+ * discarding the target-aware path exists to prevent.
126
+ */
127
+ async plan(record, target) {
128
+ const fallback = () => planFromHeadings(record.source, record.externalId, record.title, record.body, target);
51
129
  if (!this.deps.modelRef || (!this.deps.modelProviderResolver && !this.deps.modelProvider)) {
52
130
  return fallback();
53
131
  }
@@ -58,8 +136,8 @@ export class DocumentPlannerService {
58
136
  const model = provider.resolve(this.deps.modelRef);
59
137
  const { text } = await generateText({
60
138
  model,
61
- system: SYSTEM_PROMPT,
62
- prompt: buildUserPrompt(record.title, record.body),
139
+ system: target ? TARGETED_SYSTEM_PROMPT : SYSTEM_PROMPT,
140
+ prompt: target ? buildTargetedUserPrompt(record, target) : buildUserPrompt(record),
63
141
  temperature: 0.2,
64
142
  // Headroom for a reasoning model's `<think>` before the JSON plan — a
65
143
  // tight cap truncates the plan mid-output (finish_reason: length).
@@ -71,11 +149,16 @@ export class DocumentPlannerService {
71
149
  workspaceId: record.workspaceId,
72
150
  }),
73
151
  });
74
- const plan = coercePlan(record.source, record.externalId, extractJson(text));
152
+ const parsed = extractJson(text);
153
+ const plan = target
154
+ ? coerceTargetedPlan(record.source, record.externalId, parsed, target)
155
+ : coercePlan(record.source, record.externalId, parsed);
75
156
  return plan ?? fallback();
76
157
  }
77
158
  catch {
78
- // Any provider/parse failure degrades gracefully to the deterministic plan.
159
+ // silent-catch-ok: any provider/parse failure degrades to the deterministic plan, which is
160
+ // the whole reason the heading parser is kept; the plan is a PREVIEW the user approves, so
161
+ // a degraded one is visible to them before anything is written.
79
162
  return fallback();
80
163
  }
81
164
  }
@@ -1 +1 @@
1
- {"version":3,"file":"DocumentPlannerService.js","sourceRoot":"","sources":["../../../src/modules/documents/DocumentPlannerService.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,IAAI,CAAA;AAIjC,OAAO,EAAE,uBAAuB,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAA;AAC1E,OAAO,EAAE,UAAU,EA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AAC;IACH,CAAC;CACF"}
1
+ {"version":3,"file":"DocumentPlannerService.js","sourceRoot":"","sources":["../../../src/modules/documents/DocumentPlannerService.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,IAAI,CAAA;AAIjC,OAAO,EAAE,uBAAuB,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAA;AAC1E,OAAO,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAA;AACvD,OAAO,EACL,UAAU,EACV,kBAAkB,EAClB,cAAc,EACd,gBAAgB,GAEjB,MAAM,sBAAsB,CAAA;AAE7B,2EAA2E;AAC3E,8EAA8E;AAC9E,+EAA+E;AAC/E,4EAA4E;AAC5E,gFAAgF;AAChF,iFAAiF;AACjF,sCAAsC;AACtC,EAAE;AACF,+DAA+D;AAC/D,EAAE;AACF,gGAAgG;AAChG,kGAAkG;AAClG,6FAA6F;AAC7F,kFAAkF;AAClF,qFAAqF;AACrF,+FAA+F;AAC/F,8FAA8F;AAC9F,4EAA4E;AAE5E,MAAM,cAAc,GAAG,IAAI,CAAA;AAc3B,MAAM,aAAa,GACjB,uFAAuF;IACvF,0FAA0F;IAC1F,uFAAuF,CAAA;AAEzF;;;;;GAKG;AACH,MAAM,sBAAsB,GAC1B,yFAAyF;IACzF,4FAA4F;IAC5F,2FAA2F;IAC3F,cAAc,CAAA;AAEhB;;;;;;;GAOG;AACH,MAAM,eAAe,GAAG;IACtB,8FAA8F;IAC9F,4FAA4F;IAC5F,+FAA+F;IAC/F,4FAA4F;IAC5F,4FAA4F;CAC7F,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;AAEX,SAAS,YAAY,CAAC,MAAsB;IAC1C,OAAO,cAAc,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,cAAc,CAAC,CAAA;AAC7D,CAAC;AAED,SAAS,eAAe,CAAC,MAAsB;IAC7C,OAAO;QACL,mBAAmB,MAAM,CAAC,KAAK,EAAE;QACjC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AAC,CAAC,CAAC,eAAe,CAAC,MAAM,CAAC;gBAClF,WAAW,EAAE,GAAG;gBAChB,sEAAsE;gBACtE,mEAAmE;gBACnE,eAAe,EAAE,IAAI;gBACrB,2EAA2E;gBAC3E,yEAAyE;gBACzE,eAAe,EAAE,uBAAuB,CAAC;oBACvC,SAAS,EAAE,kBAAkB;oBAC7B,WAAW,EAAE,MAAM,CAAC,WAAW;iBAChC,CAAC;aACH,CAAC,CAAA;YACF,MAAM,MAAM,GAAG,WAAW,CAAC,IAAI,CAAC,CAAA;YAChC,MAAM,IAAI,GAAG,MAAM;gBACjB,CAAC,CAAC,kBAAkB,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,UAAU,EAAE,MAAM,EAAE,MAAM,CAAC;gBACtE,CAAC,CAAC,UAAU,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,UAAU,EAAE,MAAM,CAAC,CAAA;YACxD,OAAO,IAAI,IAAI,QAAQ,EAAE,CAAA;QAC3B,CAAC;QAAC,MAAM,CAAC;YACP,2FAA2F;YAC3F,2FAA2F;YAC3F,gEAAgE;YAChE,OAAO,QAAQ,EAAE,CAAA;QACnB,CAAC;IACH,CAAC;CACF"}
@@ -0,0 +1,88 @@
1
+ import type { DocumentCredentials, DocumentSourceKind, DocumentSourceRegistry, Clock, Logger } from '@cat-factory/kernel';
2
+ import type { DocumentConnectionRecord } from '@cat-factory/kernel';
3
+ /** The deployment's registered OAuth app for one source. */
4
+ export interface DocumentOAuthClient {
5
+ clientId: string;
6
+ clientSecret: string;
7
+ /** The redirect the app is registered with; reused verbatim on the exchange. */
8
+ redirectUrl: string;
9
+ }
10
+ export interface DocumentSourceOAuthServiceDependencies {
11
+ registry: DocumentSourceRegistry;
12
+ /**
13
+ * The deployment's registered app for a source, resolved per workspace (the account key its
14
+ * workspace belongs to, so an org registers ONE app shared by its boards). `undefined` ⇒ this
15
+ * deployment cannot run the flow for that source, which is a different fact from the source
16
+ * having no OAuth half at all.
17
+ */
18
+ resolveClient(workspaceId: string, source: DocumentSourceKind): Promise<DocumentOAuthClient | undefined>;
19
+ clock: Clock;
20
+ /** Injected for tests; production passes nothing and the global `fetch` is used. */
21
+ fetchImpl?: typeof fetch;
22
+ logger?: Logger;
23
+ }
24
+ export declare class DocumentSourceOAuthService {
25
+ private readonly deps;
26
+ private readonly log;
27
+ constructor(deps: DocumentSourceOAuthServiceDependencies);
28
+ private get http();
29
+ /**
30
+ * The sources this deployment can connect by OAuth for this workspace: an `oauth` declaration
31
+ * AND a registered client.
32
+ *
33
+ * BOTH halves, because the surface reading it renders a button. A source declaring the half
34
+ * with no client registered would offer a "Connect with Figma" that can only 503, which is the
35
+ * misattribution the separate wire field exists to prevent.
36
+ */
37
+ availableSources(workspaceId: string): Promise<DocumentSourceKind[]>;
38
+ /**
39
+ * The vendor URL to send the operator's browser to, carrying the caller's signed `state`.
40
+ *
41
+ * Throws rather than answering a status: every failure here is a refusal an operator asked for
42
+ * by pressing a button (a source with no OAuth half, a deployment with no registered app), and
43
+ * a button press deserves a reason rather than a dead link.
44
+ */
45
+ authorizeUrl(input: {
46
+ workspaceId: string;
47
+ source: DocumentSourceKind;
48
+ state: string;
49
+ }): Promise<string>;
50
+ /**
51
+ * Exchange a callback `code` for the credential bag the workspace's connection will hold.
52
+ *
53
+ * It RETURNS the bag rather than storing it, which is what keeps this service free of the
54
+ * connection store: persistence flows one way (the connection service renews through this one),
55
+ * and having the exchange write back would close that into a cycle broken only by a setter.
56
+ * The caller stores it through `DocumentConnectionService.connectWithOAuth`.
57
+ */
58
+ exchangeCode(input: {
59
+ workspaceId: string;
60
+ source: DocumentSourceKind;
61
+ code: string;
62
+ }): Promise<DocumentCredentials>;
63
+ /**
64
+ * Renew a stored grant that is at or past its expiry skew, answering the NEW credential bag, or
65
+ * null when there was nothing to do or the renewal could not be made.
66
+ *
67
+ * Null rather than a throw on every failure path, because this sits on the credential-resolution
68
+ * path of every read: a grant that cannot be renewed right now must cost the reader a failed
69
+ * fetch it can report as a source outage, never the read itself. Three states are deliberately
70
+ * distinguished in what it logs, since each needs a different fix: a grant with no refresh
71
+ * token, a source whose spec declares no refresh endpoint (the grant was never renewable, so
72
+ * reconnecting is the only remedy), and a refresh that was attempted and failed.
73
+ *
74
+ * Unguarded against a lost race ON PURPOSE. The endpoints supported here return a new access
75
+ * token against an unchanged refresh token, so two concurrent renewals converge: the loser
76
+ * overwrites an equivalent value rather than replacing a live grant with a dead one, which is
77
+ * the failure a rotating authorization server would make a `compareAndSwap` mandatory for. A
78
+ * source whose refresh ROTATES cannot be added without revisiting this.
79
+ */
80
+ renewIfExpiring(record: DocumentConnectionRecord): Promise<DocumentCredentials | null>;
81
+ /** The platform-owned credential bag for a token response. */
82
+ private bagFrom;
83
+ /** One token-endpoint call, authenticated as the confidential client. */
84
+ private post;
85
+ /** Resolve the source's OAuth declaration + this deployment's registered app, or refuse. */
86
+ private require;
87
+ }
88
+ //# sourceMappingURL=DocumentSourceOAuthService.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DocumentSourceOAuthService.d.ts","sourceRoot":"","sources":["../../../src/modules/documents/DocumentSourceOAuthService.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,mBAAmB,EACnB,kBAAkB,EAElB,sBAAsB,EACtB,KAAK,EACL,MAAM,EACP,MAAM,qBAAqB,CAAA;AAQ5B,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,qBAAqB,CAAA;AAiBnE,4DAA4D;AAC5D,MAAM,WAAW,mBAAmB;IAClC,QAAQ,EAAE,MAAM,CAAA;IAChB,YAAY,EAAE,MAAM,CAAA;IACpB,gFAAgF;IAChF,WAAW,EAAE,MAAM,CAAA;CACpB;AAqBD,MAAM,WAAW,sCAAsC;IACrD,QAAQ,EAAE,sBAAsB,CAAA;IAChC;;;;;OAKG;IACH,aAAa,CACX,WAAW,EAAE,MAAM,EACnB,MAAM,EAAE,kBAAkB,GACzB,OAAO,CAAC,mBAAmB,GAAG,SAAS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