@loopstack/github-oauth-example 0.1.1 → 0.2.1

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 (30) hide show
  1. package/README.md +116 -20
  2. package/dist/tools/authenticate-github-task.tool.d.ts +9 -8
  3. package/dist/tools/authenticate-github-task.tool.d.ts.map +1 -1
  4. package/dist/tools/authenticate-github-task.tool.js +30 -62
  5. package/dist/tools/authenticate-github-task.tool.js.map +1 -1
  6. package/dist/workflows/github-agent.ui.yaml +16 -0
  7. package/dist/workflows/github-agent.workflow.d.ts +14 -13
  8. package/dist/workflows/github-agent.workflow.d.ts.map +1 -1
  9. package/dist/workflows/github-agent.workflow.js +155 -71
  10. package/dist/workflows/github-agent.workflow.js.map +1 -1
  11. package/dist/workflows/github-repos-overview.ui.yaml +17 -0
  12. package/dist/workflows/github-repos-overview.workflow.d.ts +77 -87
  13. package/dist/workflows/github-repos-overview.workflow.d.ts.map +1 -1
  14. package/dist/workflows/github-repos-overview.workflow.js +177 -228
  15. package/dist/workflows/github-repos-overview.workflow.js.map +1 -1
  16. package/dist/workflows/templates/repoOverview.md +81 -0
  17. package/dist/workflows/templates/systemMessage.md +23 -0
  18. package/package.json +7 -7
  19. package/src/tools/authenticate-github-task.tool.ts +34 -82
  20. package/src/workflows/__tests__/github-repos-overview-workflow.spec.ts +105 -249
  21. package/src/workflows/github-agent.ui.yaml +16 -0
  22. package/src/workflows/github-agent.workflow.ts +109 -27
  23. package/src/workflows/github-repos-overview.ui.yaml +17 -0
  24. package/src/workflows/github-repos-overview.workflow.ts +257 -215
  25. package/src/workflows/templates/repoOverview.md +81 -0
  26. package/src/workflows/templates/systemMessage.md +23 -0
  27. package/dist/workflows/github-agent.workflow.yaml +0 -154
  28. package/dist/workflows/github-repos-overview.workflow.yaml +0 -249
  29. package/src/workflows/github-agent.workflow.yaml +0 -154
  30. package/src/workflows/github-repos-overview.workflow.yaml +0 -249
@@ -1,22 +1,18 @@
1
1
  import { Injectable, Logger } from '@nestjs/common';
2
2
  import { z } from 'zod';
3
- import {
4
- InjectDocument,
5
- InjectTool,
6
- Input,
7
- RunContext,
8
- Tool,
9
- ToolInterface,
10
- ToolResult,
11
- ToolSideEffects,
12
- WorkflowInterface,
13
- WorkflowMetadataInterface,
14
- } from '@loopstack/common';
15
- import { CreateDocument, LinkDocument, Task } from '@loopstack/core';
3
+ import { BaseTool, InjectWorkflow, Tool, ToolResult } from '@loopstack/common';
4
+ import { LinkDocument } from '@loopstack/core';
5
+ import { OAuthWorkflow } from '@loopstack/oauth-module';
16
6
 
17
7
  const AuthenticateGitHubTaskInputSchema = z
18
8
  .object({
19
9
  scopes: z.array(z.string()).describe('The OAuth scopes to request (e.g. repo, user, workflow, read:org)'),
10
+ callback: z
11
+ .object({
12
+ transition: z.string(),
13
+ metadata: z.record(z.string(), z.unknown()).optional(),
14
+ })
15
+ .optional(),
20
16
  })
21
17
  .strict();
22
18
 
@@ -24,102 +20,58 @@ type AuthenticateGitHubTaskInput = z.infer<typeof AuthenticateGitHubTaskInputSch
24
20
 
25
21
  @Injectable()
26
22
  @Tool({
27
- config: {
23
+ uiConfig: {
28
24
  description:
29
25
  'Launches GitHub OAuth authentication. Shows the user a sign-in prompt to authorize access to GitHub. ' +
30
26
  'Use this when a GitHub tool returns an "unauthorized" error. ' +
31
27
  'Pass the required OAuth scopes for the GitHub APIs you need access to. ' +
32
28
  'IMPORTANT: When using this tool, it must be the ONLY tool call in your response. Do not combine it with other tool calls.',
33
29
  },
30
+ schema: AuthenticateGitHubTaskInputSchema,
34
31
  })
35
- export class AuthenticateGitHubTask implements ToolInterface<AuthenticateGitHubTaskInput> {
32
+ export class AuthenticateGitHubTask extends BaseTool {
36
33
  private readonly logger = new Logger(AuthenticateGitHubTask.name);
37
34
 
38
- @InjectTool() private task: Task;
39
- @InjectTool() private createDocument: CreateDocument;
40
- @InjectDocument() private linkDocument: LinkDocument;
35
+ @InjectWorkflow() private oAuth: OAuthWorkflow;
41
36
 
42
- @Input({ schema: AuthenticateGitHubTaskInputSchema })
43
- args: AuthenticateGitHubTaskInput;
44
-
45
- async execute(
46
- args: AuthenticateGitHubTaskInput,
47
- ctx: RunContext,
48
- parent: WorkflowInterface | ToolInterface,
49
- metadata: WorkflowMetadataInterface,
50
- ): Promise<ToolResult> {
51
- const taskResult = await this.task.execute(
52
- { workflow: 'oAuth', args: { provider: 'github', scopes: args.scopes } },
53
- ctx,
54
- parent,
37
+ async call(args: AuthenticateGitHubTaskInput): Promise<ToolResult> {
38
+ const result = await this.oAuth.run(
39
+ { provider: 'github', scopes: args.scopes },
40
+ { alias: 'oAuth', callback: args.callback },
55
41
  );
56
42
 
57
- const effects: ToolSideEffects[] = [];
58
-
59
- const linkResult = await this.createDocument.execute(
43
+ await this.repository.save(
44
+ LinkDocument,
60
45
  {
61
- document: 'linkDocument',
62
- id: 'github_auth_link',
63
- validate: 'skip' as const,
64
- update: {
65
- content: {
66
- icon: 'LockKeyhole',
67
- label: 'GitHub authentication required',
68
- caption: 'Complete sign-in to access GitHub',
69
- href: `/pipelines/${String((taskResult.data as Record<string, unknown>).pipelineId)}`,
70
- embed: true,
71
- expanded: true,
72
- },
73
- },
46
+ status: 'pending',
47
+ label: 'GitHub authentication required',
48
+ workflowId: result.workflowId,
49
+ embed: true,
50
+ expanded: true,
74
51
  },
75
- ctx,
76
- this,
77
- metadata,
52
+ { id: `link_${result.workflowId}` },
78
53
  );
79
- if (linkResult.effects) {
80
- effects.push(...linkResult.effects);
81
- }
82
54
 
83
55
  return {
84
- data: taskResult.data as Record<string, unknown>,
85
- effects,
56
+ data: { ...result, mode: 'async' },
86
57
  };
87
58
  }
88
59
 
89
- async complete(
90
- result: Record<string, unknown>,
91
- ctx: RunContext,
92
- parent: WorkflowInterface | ToolInterface,
93
- metadata: WorkflowMetadataInterface,
94
- ): Promise<ToolResult> {
95
- const data = result as { pipelineId?: string };
96
-
97
- const effects: ToolSideEffects[] = [];
60
+ async complete(result: Record<string, unknown>): Promise<ToolResult> {
61
+ const data = result as { workflowId?: string };
98
62
 
99
- const linkResult = await this.createDocument.execute(
63
+ await this.repository.save(
64
+ LinkDocument,
100
65
  {
101
- document: 'linkDocument',
102
- id: 'github_auth_link',
103
- validate: 'skip' as const,
104
- update: {
105
- content: {
106
- icon: 'ShieldCheck',
107
- label: 'GitHub authentication completed',
108
- href: `/pipelines/${data.pipelineId}`,
109
- },
110
- },
66
+ status: 'success',
67
+ label: 'GitHub authentication completed',
68
+ workflowId: data.workflowId,
111
69
  },
112
- ctx,
113
- this,
114
- metadata,
70
+ { id: `link_${data.workflowId}` },
115
71
  );
116
- if (linkResult.effects) {
117
- effects.push(...linkResult.effects);
118
- }
119
72
 
120
73
  return {
121
74
  data: 'GitHub authentication completed successfully. You can now use GitHub tools.',
122
- effects,
123
75
  };
124
76
  }
125
77
  }