forked from anomalyco/opencode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsample.ts
More file actions
53 lines (44 loc) · 1.52 KB
/
sample.ts
File metadata and controls
53 lines (44 loc) · 1.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import { create, tool, Session } from "../src/index"
import { env } from "bun"
const mini = create({ directory: process.cwd(), copilot: {}, logLevel: "ERROR" })
await mini.init()
mini.credentials.set("user-alice", {
providerID: "copilot",
token: env.GITHUB_TOKEN_ALICE ?? "",
})
mini.credentials.set("user-bob", {
providerID: "copilot",
token: env.GITHUB_TOKEN_BOB ?? "",
})
console.log("[!] Creating session...")
const session = await mini.session.create({ title: "Shared session" })
console.log("[!] Alice sends a message...")
let replyA1 = await mini.prompt({
sessionID: session.id,
parts: [{ type: "text", text: "Hello from Alice" }],
userId: "user-alice",
model: { providerID: "copilot", modelID: "claude-opus-4.6" },
})
console.log(replyA1)
console.log("[!] Bob sends a message...")
let replyB1 = await mini.prompt({
sessionID: session.id,
parts: [{ type: "text", text: "Hello from Bob" }],
userId: "user-bob",
model: { providerID: "copilot", modelID: "claude-opus-4.6" },
})
console.log(replyB1)
console.log("[!] Alice asks who's in the conversation...")
let replyA2 = await mini.prompt({
sessionID: session.id,
parts: [{ type: "text", text: "Who is part of this conversation?" }],
userId: "user-alice",
model: { providerID: "copilot", modelID: "claude-opus-4.6" },
})
console.log(replyA2)
// console.log("[!] Retrieving conversation history...")
// const messages = await mini.session.messages(session.id)
// for (const msg of messages) {
// console.log(`[${msg.info.role}]`, msg)
// }
await mini.dispose()