@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.
- package/README.md +116 -20
- package/dist/tools/authenticate-github-task.tool.d.ts +9 -8
- package/dist/tools/authenticate-github-task.tool.d.ts.map +1 -1
- package/dist/tools/authenticate-github-task.tool.js +30 -62
- package/dist/tools/authenticate-github-task.tool.js.map +1 -1
- package/dist/workflows/github-agent.ui.yaml +16 -0
- package/dist/workflows/github-agent.workflow.d.ts +14 -13
- package/dist/workflows/github-agent.workflow.d.ts.map +1 -1
- package/dist/workflows/github-agent.workflow.js +155 -71
- package/dist/workflows/github-agent.workflow.js.map +1 -1
- package/dist/workflows/github-repos-overview.ui.yaml +17 -0
- package/dist/workflows/github-repos-overview.workflow.d.ts +77 -87
- package/dist/workflows/github-repos-overview.workflow.d.ts.map +1 -1
- package/dist/workflows/github-repos-overview.workflow.js +177 -228
- package/dist/workflows/github-repos-overview.workflow.js.map +1 -1
- package/dist/workflows/templates/repoOverview.md +81 -0
- package/dist/workflows/templates/systemMessage.md +23 -0
- package/package.json +7 -7
- package/src/tools/authenticate-github-task.tool.ts +34 -82
- package/src/workflows/__tests__/github-repos-overview-workflow.spec.ts +105 -249
- package/src/workflows/github-agent.ui.yaml +16 -0
- package/src/workflows/github-agent.workflow.ts +109 -27
- package/src/workflows/github-repos-overview.ui.yaml +17 -0
- package/src/workflows/github-repos-overview.workflow.ts +257 -215
- package/src/workflows/templates/repoOverview.md +81 -0
- package/src/workflows/templates/systemMessage.md +23 -0
- package/dist/workflows/github-agent.workflow.yaml +0 -154
- package/dist/workflows/github-repos-overview.workflow.yaml +0 -249
- package/src/workflows/github-agent.workflow.yaml +0 -154
- 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
|
-
|
|
5
|
-
|
|
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
|
-
|
|
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
|
|
32
|
+
export class AuthenticateGitHubTask extends BaseTool {
|
|
36
33
|
private readonly logger = new Logger(AuthenticateGitHubTask.name);
|
|
37
34
|
|
|
38
|
-
@
|
|
39
|
-
@InjectTool() private createDocument: CreateDocument;
|
|
40
|
-
@InjectDocument() private linkDocument: LinkDocument;
|
|
35
|
+
@InjectWorkflow() private oAuth: OAuthWorkflow;
|
|
41
36
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
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
|
-
|
|
58
|
-
|
|
59
|
-
const linkResult = await this.createDocument.execute(
|
|
43
|
+
await this.repository.save(
|
|
44
|
+
LinkDocument,
|
|
60
45
|
{
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
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
|
-
|
|
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:
|
|
85
|
-
effects,
|
|
56
|
+
data: { ...result, mode: 'async' },
|
|
86
57
|
};
|
|
87
58
|
}
|
|
88
59
|
|
|
89
|
-
async complete(
|
|
90
|
-
result
|
|
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
|
-
|
|
63
|
+
await this.repository.save(
|
|
64
|
+
LinkDocument,
|
|
100
65
|
{
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
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
|
-
|
|
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
|
}
|