Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .changeset/witty-dots-bathe.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
"@plotday/tool-outlook-calendar": patch
"@plotday/tool-google-calendar": patch
"@plotday/tool-google-contacts": patch
"@plotday/sdk": patch
---

Fixed: Several references to call() renamed to callCallback()
7 changes: 5 additions & 2 deletions sdk/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ await this.plot.createActivity({
Activities are grouped within nested contexts called Priorities (e.g. Work, Project X).

**Type References:**

- [ActivityType enum](https://github.com/plotday/plot/blob/main/sdk/src/plot.ts#L35-L42) - Note, Task, Event
- [ActivityLinkType enum](https://github.com/plotday/plot/blob/main/sdk/src/plot.ts#L65-L74) - external, auth, hidden, callback
- [Activity type](https://github.com/plotday/plot/blob/main/sdk/src/plot.ts#L216-L288) - Full activity structure
Expand Down Expand Up @@ -254,6 +255,7 @@ async onAuthComplete(authorization: Authorization, context: any) {
```

**Type References:**

- [AuthProvider enum](https://github.com/plotday/plot/blob/main/sdk/src/tools/auth.ts#L78-L83) - Google, Microsoft
- [AuthLevel enum](https://github.com/plotday/plot/blob/main/sdk/src/tools/auth.ts#L90-L95) - Priority, User

Expand Down Expand Up @@ -300,12 +302,12 @@ Create persistent function references for webhooks and auth flows. Callback meth

```typescript
// Create callback (no import needed - available directly)
const token = await this.callback("handleEvent", {
const callback = await this.callback("handleEvent", {
eventType: "calendar_sync",
});

// Execute callback
const result = await this.call(token, {
const result = await this.callCallback(callback, {
data: eventData,
});

Expand Down Expand Up @@ -398,6 +400,7 @@ response.output.email; // string | undefined
**Model Selection:**

Use `ModelPreferences` to specify your requirements based on speed and cost tiers:

- **Speed**: `"fast"`, `"balanced"`, or `"capable"`
- **Cost**: `"low"`, `"medium"`, or `"high"`

Expand Down
6 changes: 3 additions & 3 deletions tools/google-calendar/src/google-calendar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ export class GoogleCalendar extends Tool implements CalendarTool {
source: activityData.source || null,
};

await this.call(callbackToken, activity);
await this.callCallback(callbackToken, activity);
}
}
} catch (error) {
Expand Down Expand Up @@ -423,7 +423,7 @@ export class GoogleCalendar extends Tool implements CalendarTool {
source: activityData.source || null,
};

await this.call(callbackToken, activity);
await this.callCallback(callbackToken, activity);
}
}

Expand Down Expand Up @@ -502,7 +502,7 @@ export class GoogleCalendar extends Tool implements CalendarTool {
const authSuccessResult: CalendarAuth = {
authToken: context.authToken,
};
await this.call(context.callbackToken, authSuccessResult);
await this.callCallback(context.callbackToken, authSuccessResult);

// Clean up the callback token
await this.clear(`auth_callback_token:${context.authToken}`);
Expand Down
74 changes: 36 additions & 38 deletions tools/google-contacts/src/google-contacts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
type AuthToken,
} from "@plotday/sdk/tools/auth";
import { type Callback } from "@plotday/sdk/tools/callback";

import type { Contact, ContactAuth, GoogleContacts } from "./types";

type ContactTokens = {
Expand Down Expand Up @@ -59,7 +60,7 @@ class GoogleApi {
method: string,
url: string,
params?: { [key: string]: any },
body?: { [key: string]: any },
body?: { [key: string]: any }
) {
const query = params ? `?${new URLSearchParams(params)}` : "";
const headers = {
Expand Down Expand Up @@ -95,15 +96,15 @@ function parseContact(contact: GoogleContact) {
const name = contact.names?.[0]?.displayName;
const avatar = contact.photos?.filter(
(p: NonNullable<GoogleContact["photos"]>[number]) =>
!p.default && p.metadata?.primary,
!p.default && p.metadata?.primary
)?.[0]?.url;
return { name, avatar };
}

async function getGoogleContacts(
api: GoogleApi,
scopes: string[],
state: ContactSyncState,
state: ContactSyncState
): Promise<{
contacts: Contact[];
state: ContactSyncState;
Expand All @@ -115,8 +116,7 @@ async function getGoogleContacts(
if (!state.more || tokens.connections?.nextPageToken) {
if (
scopes?.some?.(
(scope) =>
scope === "https://www.googleapis.com/auth/contacts.readonly",
(scope) => scope === "https://www.googleapis.com/auth/contacts.readonly"
)
) {
let response: ListResponse | undefined;
Expand All @@ -131,12 +131,12 @@ async function getGoogleContacts(
pageToken: tokens.connections?.nextPageToken,
}
: tokens.connections?.nextSyncToken
? {
syncToken: tokens.connections?.nextSyncToken,
}
: {}),
? {
syncToken: tokens.connections?.nextSyncToken,
}
: {}),
personFields: "names,emailAddresses,photos",
},
}
)) as ListResponse;
if (response !== null) break;
if (!tokens.connections) break;
Expand Down Expand Up @@ -176,7 +176,7 @@ async function getGoogleContacts(
if (
scopes?.some?.(
(scope) =>
scope === "https://www.googleapis.com/auth/contacts.other.readonly",
scope === "https://www.googleapis.com/auth/contacts.other.readonly"
)
) {
let response: ListOtherResponse | undefined;
Expand All @@ -191,12 +191,12 @@ async function getGoogleContacts(
pageToken: tokens.other?.nextPageToken,
}
: tokens.other?.nextSyncToken
? {
syncToken: tokens.other?.nextSyncToken,
}
: {}),
? {
syncToken: tokens.other?.nextSyncToken,
}
: {}),
readMask: "names,emailAddresses,photos",
},
}
)) as ListOtherResponse;
if (response !== null) break;
if (!tokens.other) break;
Expand Down Expand Up @@ -255,7 +255,7 @@ export default class extends Tool implements GoogleContacts {

async requestAuth(
callbackFunctionName: string,
callbackContext?: any,
callbackContext?: any
): Promise<any> {
const contactsScopes = [
"https://www.googleapis.com/auth/contacts.readonly",
Expand All @@ -268,7 +268,7 @@ export default class extends Tool implements GoogleContacts {
// Register the callback for auth completion with opaque token
const callbackToken = await this.callback(
callbackFunctionName,
callbackContext,
callbackContext
);
await this.set(`auth_callback_token:${opaqueToken}`, callbackToken);

Expand All @@ -285,17 +285,17 @@ export default class extends Tool implements GoogleContacts {
level: AuthLevel.User,
scopes: contactsScopes,
},
authCallback,
authCallback
);
}

async getContacts(authToken: string): Promise<Contact[]> {
const storedAuthToken = await this.get<AuthToken>(
`auth_token:${authToken}`,
`auth_token:${authToken}`
);
if (!storedAuthToken) {
throw new Error(
"No Google authentication token available for the provided authToken",
"No Google authentication token available for the provided authToken"
);
}

Expand All @@ -312,21 +312,21 @@ export default class extends Tool implements GoogleContacts {
callbackFunctionName: string,
options?: {
context?: any;
},
}
): Promise<void> {
const storedAuthToken = await this.get<AuthToken>(
`auth_token:${authToken}`,
`auth_token:${authToken}`
);
if (!storedAuthToken) {
throw new Error(
"No Google authentication token available for the provided authToken",
"No Google authentication token available for the provided authToken"
);
}

// Register the callback
const callbackToken = await this.callback(
callbackFunctionName,
options?.context,
options?.context
);
await this.set(`contacts_callback_token:${authToken}`, callbackToken);

Expand Down Expand Up @@ -360,17 +360,15 @@ export default class extends Tool implements GoogleContacts {

try {
const storedAuthToken = await this.get<AuthToken>(
`auth_token:${authToken}`,
`auth_token:${authToken}`
);
if (!storedAuthToken) {
throw new Error(
"No authentication token available for the provided authToken",
"No authentication token available for the provided authToken"
);
}

const state = await this.get<ContactSyncState>(
`sync_state:${authToken}`,
);
const state = await this.get<ContactSyncState>(`sync_state:${authToken}`);
if (!state) {
throw new Error("No sync state found");
}
Expand All @@ -379,13 +377,13 @@ export default class extends Tool implements GoogleContacts {
const result = await getGoogleContacts(
api,
storedAuthToken.scopes,
state,
state
);

if (result.contacts.length > 0) {
await this.processContacts(result.contacts, authToken);
console.log(
`Synced ${result.contacts.length} contacts in batch ${batchNumber}`,
`Synced ${result.contacts.length} contacts in batch ${batchNumber}`
);
}

Expand All @@ -399,7 +397,7 @@ export default class extends Tool implements GoogleContacts {
await this.run(callback);
} else {
console.log(
`Google Contacts sync completed after ${batchNumber} batches`,
`Google Contacts sync completed after ${batchNumber} batches`
);
await this.clear(`sync_state:${authToken}`);
}
Expand All @@ -412,13 +410,13 @@ export default class extends Tool implements GoogleContacts {

private async processContacts(
contacts: Contact[],
authToken: string,
authToken: string
): Promise<void> {
const callbackToken = await this.get<Callback>(
`contacts_callback_token:${authToken}`,
`contacts_callback_token:${authToken}`
);
if (callbackToken) {
await this.call(callbackToken, contacts);
await this.callCallback(callbackToken, contacts);
}
}

Expand All @@ -437,14 +435,14 @@ export default class extends Tool implements GoogleContacts {

// Retrieve and call the stored callback
const callbackToken = await this.get<Callback>(
`auth_callback_token:${opaqueToken}`,
`auth_callback_token:${opaqueToken}`
);
if (callbackToken) {
const authSuccessResult: ContactAuth = {
authToken: opaqueToken,
};

await this.call(callbackToken, authSuccessResult);
await this.callCallback(callbackToken, authSuccessResult);

// Clean up the callback token
await this.clear(`auth_callback_token:${opaqueToken}`);
Expand Down
4 changes: 2 additions & 2 deletions tools/outlook-calendar/src/outlook-calendar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -564,7 +564,7 @@ export class OutlookCalendar extends Tool implements CalendarTool {
// Call the event callback
const callbackToken = await this.get<Callback>("event_callback_token");
if (callbackToken) {
await this.call(callbackToken, activity);
await this.callCallback(callbackToken, activity);
}
}

Expand Down Expand Up @@ -653,7 +653,7 @@ export class OutlookCalendar extends Tool implements CalendarTool {
authToken: context.token,
};

await this.call(callbackToken, authSuccessResult);
await this.callCallback(callbackToken, authSuccessResult);

// Clean up the callback token
await this.clear(`auth_callback_token:${context.token}`);
Expand Down