@loopstack/oauth-examples 0.1.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 +111 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +24 -0
- package/dist/index.js.map +1 -0
- package/dist/oauth-examples.module.d.ts +3 -0
- package/dist/oauth-examples.module.d.ts.map +1 -0
- package/dist/oauth-examples.module.js +42 -0
- package/dist/oauth-examples.module.js.map +1 -0
- package/dist/shared/github/authenticate-github-task.tool.d.ts +26 -0
- package/dist/shared/github/authenticate-github-task.tool.d.ts.map +1 -0
- package/dist/shared/github/authenticate-github-task.tool.js +67 -0
- package/dist/shared/github/authenticate-github-task.tool.js.map +1 -0
- package/dist/shared/github/index.d.ts +2 -0
- package/dist/shared/github/index.d.ts.map +1 -0
- package/dist/shared/github/index.js +18 -0
- package/dist/shared/github/index.js.map +1 -0
- package/dist/shared/google/authenticate-google-task.tool.d.ts +26 -0
- package/dist/shared/google/authenticate-google-task.tool.d.ts.map +1 -0
- package/dist/shared/google/authenticate-google-task.tool.js +69 -0
- package/dist/shared/google/authenticate-google-task.tool.js.map +1 -0
- package/dist/shared/google/google-calendar-fetch-events.tool.d.ts +28 -0
- package/dist/shared/google/google-calendar-fetch-events.tool.d.ts.map +1 -0
- package/dist/shared/google/google-calendar-fetch-events.tool.js +96 -0
- package/dist/shared/google/google-calendar-fetch-events.tool.js.map +1 -0
- package/dist/shared/google/index.d.ts +3 -0
- package/dist/shared/google/index.d.ts.map +1 -0
- package/dist/shared/google/index.js +19 -0
- package/dist/shared/google/index.js.map +1 -0
- package/dist/workflows/github-agent/github-agent-example.ui.yaml +6 -0
- package/dist/workflows/github-agent/github-agent-example.workflow.d.ts +55 -0
- package/dist/workflows/github-agent/github-agent-example.workflow.d.ts.map +1 -0
- package/dist/workflows/github-agent/github-agent-example.workflow.js +243 -0
- package/dist/workflows/github-agent/github-agent-example.workflow.js.map +1 -0
- package/dist/workflows/github-agent/templates/systemMessage.md +23 -0
- package/dist/workflows/github-agent/templates/welcomeMessage.md +10 -0
- package/dist/workflows/github-overview/github-overview-example.workflow.d.ts +96 -0
- package/dist/workflows/github-overview/github-overview-example.workflow.d.ts.map +1 -0
- package/dist/workflows/github-overview/github-overview-example.workflow.js +216 -0
- package/dist/workflows/github-overview/github-overview-example.workflow.js.map +1 -0
- package/dist/workflows/github-overview/templates/repoOverview.md +81 -0
- package/dist/workflows/google-calendar-summary/google-calendar-summary-example.workflow.d.ts +32 -0
- package/dist/workflows/google-calendar-summary/google-calendar-summary-example.workflow.d.ts.map +1 -0
- package/dist/workflows/google-calendar-summary/google-calendar-summary-example.workflow.js +113 -0
- package/dist/workflows/google-calendar-summary/google-calendar-summary-example.workflow.js.map +1 -0
- package/dist/workflows/google-calendar-summary/templates/calendarSummary.md +10 -0
- package/dist/workflows/google-workspace-agent/google-workspace-agent-example.ui.yaml +6 -0
- package/dist/workflows/google-workspace-agent/google-workspace-agent-example.workflow.d.ts +41 -0
- package/dist/workflows/google-workspace-agent/google-workspace-agent-example.workflow.d.ts.map +1 -0
- package/dist/workflows/google-workspace-agent/google-workspace-agent-example.workflow.js +187 -0
- package/dist/workflows/google-workspace-agent/google-workspace-agent-example.workflow.js.map +1 -0
- package/dist/workflows/google-workspace-agent/templates/calendarSummary.md +10 -0
- package/dist/workflows/google-workspace-agent/templates/systemMessage.md +24 -0
- package/dist/workflows/google-workspace-agent/templates/welcomeMessage.md +7 -0
- package/package.json +52 -0
- package/src/index.ts +7 -0
- package/src/oauth-examples.module.ts +30 -0
- package/src/shared/github/authenticate-github-task.tool.ts +70 -0
- package/src/shared/github/index.ts +1 -0
- package/src/shared/google/authenticate-google-task.tool.ts +72 -0
- package/src/shared/google/google-calendar-fetch-events.tool.ts +117 -0
- package/src/shared/google/index.ts +2 -0
- package/src/workflows/github-agent/github-agent-example.ui.yaml +6 -0
- package/src/workflows/github-agent/github-agent-example.workflow.ts +193 -0
- package/src/workflows/github-agent/templates/systemMessage.md +23 -0
- package/src/workflows/github-agent/templates/welcomeMessage.md +10 -0
- package/src/workflows/github-overview/github-overview-example.workflow.ts +223 -0
- package/src/workflows/github-overview/templates/repoOverview.md +81 -0
- package/src/workflows/google-calendar-summary/google-calendar-summary-example.workflow.ts +102 -0
- package/src/workflows/google-calendar-summary/templates/calendarSummary.md +10 -0
- package/src/workflows/google-workspace-agent/google-workspace-agent-example.ui.yaml +6 -0
- package/src/workflows/google-workspace-agent/google-workspace-agent-example.workflow.ts +147 -0
- package/src/workflows/google-workspace-agent/templates/calendarSummary.md +10 -0
- package/src/workflows/google-workspace-agent/templates/systemMessage.md +24 -0
- package/src/workflows/google-workspace-agent/templates/welcomeMessage.md +7 -0
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
import { join } from 'node:path';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import { BaseWorkflow, Guard, Transition, Workflow } from '@loopstack/common';
|
|
4
|
+
import type { TransitionInput } from '@loopstack/common';
|
|
5
|
+
import {
|
|
6
|
+
GmailGetMessageTool,
|
|
7
|
+
GmailReplyToMessageTool,
|
|
8
|
+
GmailSearchMessagesTool,
|
|
9
|
+
GmailSendMessageTool,
|
|
10
|
+
GoogleCalendarCreateEventTool,
|
|
11
|
+
GoogleCalendarFetchEventsTool,
|
|
12
|
+
GoogleCalendarListCalendarsTool,
|
|
13
|
+
GoogleDriveDownloadFileTool,
|
|
14
|
+
GoogleDriveGetFileMetadataTool,
|
|
15
|
+
GoogleDriveListFilesTool,
|
|
16
|
+
GoogleDriveUploadFileTool,
|
|
17
|
+
} from '@loopstack/google-workspace-module';
|
|
18
|
+
import type { LlmDelegateResult, LlmGenerateTextResult } from '@loopstack/llm-provider-module';
|
|
19
|
+
import {
|
|
20
|
+
LlmContextDocument,
|
|
21
|
+
LlmDelegateToolCallsTool,
|
|
22
|
+
LlmGenerateTextTool,
|
|
23
|
+
LlmMessageDocument,
|
|
24
|
+
LlmUpdateToolResultTool,
|
|
25
|
+
} from '@loopstack/llm-provider-module';
|
|
26
|
+
import { OAuthWorkflow } from '@loopstack/oauth-module';
|
|
27
|
+
import { AuthenticateGoogleTask } from '../../shared/google/authenticate-google-task.tool';
|
|
28
|
+
|
|
29
|
+
interface GoogleWorkspaceAgentState {
|
|
30
|
+
llmResult?: LlmGenerateTextResult;
|
|
31
|
+
delegateResult?: LlmDelegateResult;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
@Workflow({
|
|
35
|
+
title: 'OAuth - Google Workspace Agent Example',
|
|
36
|
+
description:
|
|
37
|
+
'An interactive chat agent with access to Google Calendar, Gmail, and Google Drive. Handles OAuth automatically — the agent detects unauthorized errors and launches authentication on its own.',
|
|
38
|
+
name: 'google_workspace_agent_example',
|
|
39
|
+
widget: './google-workspace-agent-example.ui.yaml',
|
|
40
|
+
})
|
|
41
|
+
export class GoogleWorkspaceAgentExampleWorkflow extends BaseWorkflow {
|
|
42
|
+
constructor(
|
|
43
|
+
private readonly llmGenerateText: LlmGenerateTextTool,
|
|
44
|
+
private readonly llmDelegateToolCalls: LlmDelegateToolCallsTool,
|
|
45
|
+
private readonly llmUpdateToolResult: LlmUpdateToolResultTool,
|
|
46
|
+
private readonly authenticateGoogle: AuthenticateGoogleTask,
|
|
47
|
+
// Google Calendar tools
|
|
48
|
+
private readonly googleCalendarListCalendars: GoogleCalendarListCalendarsTool,
|
|
49
|
+
private readonly googleCalendarFetchEvents: GoogleCalendarFetchEventsTool,
|
|
50
|
+
private readonly googleCalendarCreateEvent: GoogleCalendarCreateEventTool,
|
|
51
|
+
// Gmail tools
|
|
52
|
+
private readonly gmailSearchMessages: GmailSearchMessagesTool,
|
|
53
|
+
private readonly gmailGetMessage: GmailGetMessageTool,
|
|
54
|
+
private readonly gmailSendMessage: GmailSendMessageTool,
|
|
55
|
+
private readonly gmailReplyToMessage: GmailReplyToMessageTool,
|
|
56
|
+
// Google Drive tools
|
|
57
|
+
private readonly googleDriveListFiles: GoogleDriveListFilesTool,
|
|
58
|
+
private readonly googleDriveGetFileMetadata: GoogleDriveGetFileMetadataTool,
|
|
59
|
+
private readonly googleDriveDownloadFile: GoogleDriveDownloadFileTool,
|
|
60
|
+
private readonly googleDriveUploadFile: GoogleDriveUploadFileTool,
|
|
61
|
+
private readonly oAuth: OAuthWorkflow,
|
|
62
|
+
) {
|
|
63
|
+
super();
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
@Transition({ to: 'waiting_for_user' })
|
|
67
|
+
async setup(_state: GoogleWorkspaceAgentState) {
|
|
68
|
+
await this.documentStore.save(LlmContextDocument, {
|
|
69
|
+
role: 'user',
|
|
70
|
+
text: this.render(join(__dirname, 'templates', 'systemMessage.md')),
|
|
71
|
+
});
|
|
72
|
+
await this.documentStore.save(LlmMessageDocument, {
|
|
73
|
+
role: 'assistant',
|
|
74
|
+
text: this.render(join(__dirname, 'templates', 'welcomeMessage.md')),
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
@Transition({ from: 'waiting_for_user', to: 'ready', wait: true, schema: z.string() })
|
|
79
|
+
async userMessage(_state: GoogleWorkspaceAgentState, input: TransitionInput<string>) {
|
|
80
|
+
await this.documentStore.save(LlmMessageDocument, { role: 'user', text: input.data });
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
@Transition({ from: 'ready', to: 'prompt_executed' })
|
|
84
|
+
async llmTurn(_state: GoogleWorkspaceAgentState) {
|
|
85
|
+
const result = await this.llmGenerateText.call(
|
|
86
|
+
{},
|
|
87
|
+
{
|
|
88
|
+
config: {
|
|
89
|
+
provider: 'claude',
|
|
90
|
+
model: 'claude-sonnet-4-6',
|
|
91
|
+
system: `You are a helpful Google Workspace assistant with access to Calendar, Gmail, and Drive tools.
|
|
92
|
+
When a tool returns an unauthorized error, use authenticateGoogle to let the user sign in,
|
|
93
|
+
then retry. Be concise and format results using markdown.`,
|
|
94
|
+
tools: [
|
|
95
|
+
'google_calendar_list_calendars',
|
|
96
|
+
'google_calendar_fetch_events',
|
|
97
|
+
'google_calendar_create_event',
|
|
98
|
+
'gmail_search_messages',
|
|
99
|
+
'gmail_get_message',
|
|
100
|
+
'gmail_send_message',
|
|
101
|
+
'gmail_reply_to_message',
|
|
102
|
+
'google_drive_list_files',
|
|
103
|
+
'google_drive_get_file_metadata',
|
|
104
|
+
'google_drive_download_file',
|
|
105
|
+
'google_drive_upload_file',
|
|
106
|
+
'authenticate_google',
|
|
107
|
+
],
|
|
108
|
+
},
|
|
109
|
+
},
|
|
110
|
+
);
|
|
111
|
+
this.assignState({ llmResult: result.data });
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
@Transition({ from: 'prompt_executed', to: 'awaiting_tools', priority: 10 })
|
|
115
|
+
@Guard('hasToolCalls')
|
|
116
|
+
async executeToolCalls(state: GoogleWorkspaceAgentState) {
|
|
117
|
+
const result = await this.llmDelegateToolCalls.call({
|
|
118
|
+
message: state.llmResult!.message,
|
|
119
|
+
callback: { transition: 'toolResultReceived' },
|
|
120
|
+
});
|
|
121
|
+
this.assignState({ delegateResult: result.data });
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
hasToolCalls(state: GoogleWorkspaceAgentState): boolean {
|
|
125
|
+
return state.llmResult?.message.stopReason === 'tool_use';
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
@Transition({ from: 'awaiting_tools', to: 'awaiting_tools', wait: true, schema: z.record(z.string(), z.unknown()) })
|
|
129
|
+
async toolResultReceived(state: GoogleWorkspaceAgentState, input: TransitionInput<Record<string, unknown>>) {
|
|
130
|
+
const result = await this.llmUpdateToolResult.call({
|
|
131
|
+
delegateResult: state.delegateResult!,
|
|
132
|
+
completedTool: input,
|
|
133
|
+
});
|
|
134
|
+
this.assignState({ delegateResult: result.data });
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
@Transition({ from: 'awaiting_tools', to: 'ready' })
|
|
138
|
+
@Guard('allToolsComplete')
|
|
139
|
+
allToolsCompleteTransition(_state: GoogleWorkspaceAgentState) {}
|
|
140
|
+
|
|
141
|
+
allToolsComplete(state: GoogleWorkspaceAgentState): boolean {
|
|
142
|
+
return state.delegateResult?.allCompleted ?? false;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
@Transition({ from: 'prompt_executed', to: 'waiting_for_user' })
|
|
146
|
+
respond(_state: GoogleWorkspaceAgentState) {}
|
|
147
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
You are a helpful Google Workspace assistant. You have access to the user's
|
|
2
|
+
Google Calendar, Gmail, and Google Drive through the tools provided to you.
|
|
3
|
+
|
|
4
|
+
You can help with:
|
|
5
|
+
|
|
6
|
+
- **Calendar**: List calendars, fetch events, create new events
|
|
7
|
+
- **Gmail**: Search messages, read full emails, send new emails, reply to threads
|
|
8
|
+
- **Drive**: Search files, get file details, download/export files, upload files
|
|
9
|
+
|
|
10
|
+
When using date/time parameters, always use ISO 8601 format.
|
|
11
|
+
|
|
12
|
+
When a tool returns `{ error: "unauthorized" }` or `{ error: "401" }`, call the
|
|
13
|
+
`authenticateGoogle` tool with the required OAuth scopes to let the user sign in.
|
|
14
|
+
After authentication completes, retry the original request.
|
|
15
|
+
|
|
16
|
+
Common scopes:
|
|
17
|
+
|
|
18
|
+
- Calendar: https://www.googleapis.com/auth/calendar.events
|
|
19
|
+
- Gmail: https://www.googleapis.com/auth/gmail.modify
|
|
20
|
+
- Drive: https://www.googleapis.com/auth/drive
|
|
21
|
+
|
|
22
|
+
IMPORTANT: When using authenticateGoogle, it must be the ONLY tool call in your response.
|
|
23
|
+
|
|
24
|
+
Be concise and helpful. Format results clearly using markdown.
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
Hi! I'm your Google Workspace assistant. I can help you with:
|
|
2
|
+
|
|
3
|
+
- **Calendar** — list calendars, fetch events, create new events
|
|
4
|
+
- **Gmail** — search messages, read details, send and reply to emails
|
|
5
|
+
- **Drive** — browse files, view metadata, download and upload files
|
|
6
|
+
|
|
7
|
+
I'll handle Google sign-in automatically when needed. What would you like to do?
|