runtime.ts 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. import type { PluginInput } from '@opencode-ai/plugin';
  2. import { createInternalAgentTextPart } from '../utils/internal-initiator';
  3. import type { InterviewMessage } from './types';
  4. export interface InterviewSessionRuntime {
  5. messages(sessionID: string): Promise<InterviewMessage[]>;
  6. notify(sessionID: string, text: string): Promise<void>;
  7. continue(
  8. sessionID: string,
  9. text: string,
  10. model?: { providerID: string; modelID: string },
  11. ): Promise<void>;
  12. rename(sessionID: string, title: string): Promise<void>;
  13. }
  14. /** The v1 implementation deliberately stays inside the interview boundary. */
  15. export function createV1InterviewSessionRuntime(
  16. ctx: PluginInput,
  17. ): InterviewSessionRuntime {
  18. const client = ctx.client;
  19. return {
  20. async messages(sessionID) {
  21. const result = await client.session.messages({
  22. path: { id: sessionID },
  23. });
  24. return result.data as InterviewMessage[];
  25. },
  26. async notify(sessionID, text) {
  27. await client.session.prompt({
  28. path: { id: sessionID },
  29. body: {
  30. noReply: true,
  31. parts: [{ type: 'text', text }],
  32. },
  33. });
  34. },
  35. async continue(sessionID, text, model) {
  36. await client.session.promptAsync({
  37. path: { id: sessionID },
  38. body: {
  39. agent: 'orchestrator',
  40. parts: [createInternalAgentTextPart(text)],
  41. ...(model ? { model } : {}),
  42. },
  43. });
  44. },
  45. async rename(sessionID, title) {
  46. await client.session.update({
  47. path: { id: sessionID },
  48. body: { title },
  49. });
  50. },
  51. };
  52. }
  53. export const createInterviewSessionRuntime = createV1InterviewSessionRuntime;