Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@copilot-extensions/preview-sdk

Package Overview
Dependencies
Maintainers
0
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@copilot-extensions/preview-sdk - npm Package Compare versions

Comparing version 3.0.0 to 4.0.0

83

index.d.ts

@@ -36,7 +36,6 @@ import { request } from "@octokit/request";

export interface CreateAckEventInterface {
(): ResponseEvent<"ack">;
(): string;
}
export interface CreateTextEventInterface {
(message: string): ResponseEvent<"text">;
(message: string): string;
}

@@ -54,84 +53,14 @@

options: CreateConfirmationEventOptions,
): ResponseEvent<"copilot_confirmation">;
): string;
}
export interface CreateReferencesEventInterface {
(references: CopilotReference[]): ResponseEvent<"copilot_references">;
(references: CopilotReference[]): string;
}
export interface CreateErrorsEventInterface {
(errors: CopilotError[]): ResponseEvent<"copilot_errors">;
(errors: CopilotError[]): string;
}
export interface CreateDoneEventInterface {
(): ResponseEvent<"done">;
(): string;
}
type ResponseEventType =
| "ack"
| "done"
| "text"
| "copilot_references"
| "copilot_confirmation"
| "copilot_errors";
type EventsWithoutEventKey = "ack" | "done" | "text";
type ResponseEvent<T extends ResponseEventType = "text"> =
T extends EventsWithoutEventKey
? {
data: T extends "ack"
? CopilotAckResponseEventData
: T extends "done"
? CopilotDoneResponseEventData
: T extends "text"
? CopilotTextResponseEventData
: never;
toString: () => string;
}
: {
event: T;
data: T extends "copilot_references"
? CopilotReferenceResponseEventData
: T extends "copilot_confirmation"
? CopilotConfirmationResponseEventData
: T extends "copilot_errors"
? CopilotErrorsResponseEventData
: never;
toString: () => string;
};
type CopilotAckResponseEventData = {
choices: [
{
delta: InteropMessage<"assistant">;
},
];
};
type CopilotDoneResponseEventData = {
choices: [
{
finish_reason: "stop";
delta: {
content: null;
};
},
];
};
type CopilotTextResponseEventData = {
choices: [
{
delta: InteropMessage<"assistant">;
},
];
};
type CopilotConfirmationResponseEventData = {
type: "action";
title: string;
message: string;
confirmation?: {
id: string;
[key: string]: any;
};
};
type CopilotErrorsResponseEventData = CopilotError[];
type CopilotReferenceResponseEventData = CopilotReference[];
type CopilotError = {

@@ -138,0 +67,0 @@ type: "reference" | "function" | "agent";

@@ -90,15 +90,3 @@ import { expectType } from "tsd";

const event = createAckEvent();
expectType<() => string>(event.toString);
expectType<string>(event.toString());
expectType<{
choices: [
{
delta: InteropMessage<"assistant">;
},
];
}>(event.data);
// @ts-expect-error - .event is required
event.event;
expectType<string>(event);
}

@@ -108,15 +96,3 @@

const event = createTextEvent("test");
expectType<() => string>(event.toString);
expectType<string>(event.toString());
expectType<{
choices: [
{
delta: InteropMessage<"assistant">;
},
];
}>(event.data);
// @ts-expect-error - .event is required
event.event;
expectType<string>(event);
}

@@ -130,27 +106,3 @@

});
// optional metadata
createConfirmationEvent({
id: "test",
title: "test",
message: "test",
metadata: {
someOtherId: "test",
},
});
expectType<() => string>(event.toString);
expectType<string>(event.toString());
expectType<{
type: "action";
title: string;
message: string;
confirmation?: {
id: string;
[key: string]: any;
};
}>(event.data);
expectType<"copilot_confirmation">(event.event);
expectType<string>(event);
}

@@ -178,22 +130,3 @@

]);
expectType<() => string>(event.toString);
expectType<string>(event.toString());
expectType<
{
type: string;
id: string;
data?: {
[key: string]: unknown;
};
is_implicit?: boolean;
metadata?: {
display_name: string;
display_icon?: string;
display_url?: string;
};
}[]
>(event.data);
expectType<"copilot_references">(event.event);
expectType<string>(event);
}

@@ -222,15 +155,3 @@

]);
expectType<() => string>(event.toString);
expectType<string>(event.toString());
expectType<
{
type: "reference" | "function" | "agent";
code: string;
message: string;
identifier: string;
}[]
>(event.data);
expectType<"copilot_errors">(event.event);
expectType<string>(event);
}

@@ -240,18 +161,3 @@

const event = createDoneEvent();
expectType<() => string>(event.toString);
expectType<string>(event.toString());
expectType<{
choices: [
{
finish_reason: "stop";
delta: {
content: null;
};
},
];
}>(event.data);
// @ts-expect-error - .event is required
event.event;
expectType<string>(event);
}

@@ -321,3 +227,3 @@

request: {
fetch: () => {},
fetch: () => { },
},

@@ -324,0 +230,0 @@ });

94

lib/response.js

@@ -5,14 +5,10 @@ // @ts-check

export function createAckEvent() {
return {
data: {
choices: [
{
delta: { content: ``, role: "assistant" },
},
],
},
toString() {
return `data: ${JSON.stringify(this.data)}\n\n`;
},
const data = {
choices: [
{
delta: { content: ``, role: "assistant" },
},
],
};
return `data: ${JSON.stringify(data)}\n\n`;
}

@@ -22,14 +18,10 @@

export function createTextEvent(message) {
return {
data: {
choices: [
{
delta: { content: message, role: "assistant" },
},
],
},
toString() {
return `data: ${JSON.stringify(this.data)}\n\n`;
},
const data = {
choices: [
{
delta: { content: message, role: "assistant" },
},
],
};
return `data: ${JSON.stringify(data)}\n\n`;
}

@@ -39,14 +31,10 @@

export function createConfirmationEvent({ id, title, message, metadata }) {
return {
event: "copilot_confirmation",
data: {
type: "action",
title,
message,
confirmation: { id, ...metadata },
},
toString() {
return `event: ${this.event}\ndata: ${JSON.stringify(this.data)}\n\n`;
},
const event = "copilot_confirmation";
const data = {
type: "action",
title,
message,
confirmation: { id, ...metadata },
};
return `event: ${event}\ndata: ${JSON.stringify(data)}\n\n`;
}

@@ -56,9 +44,5 @@

export function createReferencesEvent(references) {
return {
event: "copilot_references",
data: references,
toString() {
return `event: ${this.event}\ndata: ${JSON.stringify(this.data)}\n\n`;
},
};
const event = "copilot_references";
const data = references;
return `event: ${event}\ndata: ${JSON.stringify(data)}\n\n`;
}

@@ -68,9 +52,5 @@

export function createErrorsEvent(errors) {
return {
event: "copilot_errors",
data: errors,
toString() {
return `event: ${this.event}\ndata: ${JSON.stringify(this.data)}\n\n`;
},
};
const event = "copilot_errors";
const data = errors;
return `event: ${event}\ndata: ${JSON.stringify(data)}\n\n`;
}

@@ -80,15 +60,11 @@

export function createDoneEvent() {
return {
data: {
choices: [
{
finish_reason: "stop",
delta: { content: null },
},
],
},
toString() {
return `data: ${JSON.stringify(this.data)}\n\ndata: [DONE]\n\n`;
},
const data = {
choices: [
{
finish_reason: "stop",
delta: { content: null },
},
],
};
return `data: ${JSON.stringify(data)}\n\ndata: [DONE]\n\n`;
}

@@ -8,3 +8,3 @@ {

"type": "module",
"version": "3.0.0",
"version": "4.0.0",
"keywords": [

@@ -11,0 +11,0 @@ "ai",

@@ -49,5 +49,5 @@ # `@copilot-extensions/preview-sdk`

response.write(ackEvent.toString());
response.write(textEvent.toString());
response.end(doneEvent.toString());
response.write(ackEvent);
response.write(textEvent);
response.end(doneEvent);
}

@@ -135,3 +135,3 @@ ```

All `create*Event()` methods return an object with a `.toString()` method, which is called automatically when a string is expected. Unfortunately that's not the case for `response.write()`, you need to call `.toString()` explicitly.
All `create*Event()` methods return a string that can directly be written to the response stream.

@@ -146,3 +146,3 @@ #### `createAckEvent()`

response.write(createAckEvent().toString());
response.write(createAckEvent());
```

@@ -157,4 +157,4 @@

response.write(createTextEvent("Hello, world!").toString());
response.write(createTextEvent("Hello, again!").toString());
response.write(createTextEvent("Hello, world!"));
response.write(createTextEvent("Hello, again!"));
```

@@ -178,3 +178,3 @@

message: "This will do something.",
}).toString(),
}),
);

@@ -217,3 +217,3 @@ ```

},
]).toString()
])
);

@@ -240,3 +240,3 @@ ```

response.write(createDoneEvent().toString());
response.write(createDoneEvent());
```

@@ -243,0 +243,0 @@

@@ -19,5 +19,3 @@ import { test, suite } from "node:test";

const event = createAckEvent();
t.assert.equal(undefined, event.event);
t.assert.snapshot(event.data);
t.assert.snapshot(event.toString());
t.assert.snapshot(event);
});

@@ -27,5 +25,3 @@

const event = createDoneEvent();
t.assert.equal(undefined, event.event);
t.assert.snapshot(event.data);
t.assert.snapshot(event.toString());
t.assert.snapshot(event);
});

@@ -35,5 +31,3 @@

const event = createTextEvent("test");
t.assert.equal(undefined, event.event);
t.assert.snapshot(event.data);
t.assert.snapshot(event.toString());
t.assert.snapshot(event);
});

@@ -48,5 +42,3 @@

});
t.assert.equal("copilot_confirmation", event.event);
t.assert.snapshot(event.data);
t.assert.snapshot(event.toString());
t.assert.snapshot(event);
});

@@ -78,5 +70,3 @@

]);
t.assert.equal("copilot_errors", event.event);
t.assert.snapshot(event.data);
t.assert.snapshot(event.toString());
t.assert.snapshot(event);
});

@@ -104,7 +94,4 @@

]);
t.assert.equal("copilot_references", event.event);
t.assert.snapshot(event.data);
t.assert.snapshot(event.toString());
t.assert.snapshot(event);
});
});

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc