Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs(dreamcode): mention interop functionality and show code how requset parsing and the event API will work #35

Merged
merged 3 commits into from
Sep 1, 2024
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { verifyRequestByKeyId } from "@copilot-extensions/preview-sdk";
const payloadIsVerified = await verifyRequestByKeyId(
request.body,
signature,
key,
keyId,
{
token: process.env.GITHUB_TOKEN,
}
Expand Down
17 changes: 17 additions & 0 deletions dreamcode.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,30 @@ createServer(createNodeMiddleware(copilotExtension)).listen(3000);
copilotExtension.log.info("Listening on http://localhost:3000");
```

For other environments, these methods are available:

```js
// verify the payload and call handlers
await copilotExtension.verifyAndReceive({ payload, signature, keyId });
// same, but skip verification
await copilotExtension.receive({ payload });

// and if you don't want to use the event-based API
const { isValidRequest, payload } = await copilotExtension.verifyAndParse(
payload,
signature,
keyId
);
```

## Notes

Regarding the context passed to event handlers

- `message` / `confirmation` / etc are objects as received by the user
- `octokit` is a pre-authenticated octokit instance
- `prompt` is based on my work at https://github.com/github/gr2m-projects/blob/167/github-models/167-github-models/README.md. A simple API to interact with GitHub models. I assume we will default the prompt URL to `https://api.githubcopilot.com/chat/completions` and the model to `gpt-4o` (or whatever our CAPI name for that is?)
- The `prompt` API will automatically apply interop transformations if the request is sent to an endpoint other than Copilot's chat complitions endpoint.
- `respond` is an API to send different types of responses to the user
- `log` is the logger as we use it in Octokit. See https://github.com/octokit/core.js?tab=readme-ov-file#logging

Expand Down