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

@contential/chat

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@contential/chat - npm Package Compare versions

Comparing version 0.0.2-test to 0.0.3

CHANGELOG.md

38

dist/index.d.ts

@@ -1,3 +0,37 @@

declare const chat: () => void;
type ChatClientOptions = {
apiUrl?: string;
key?: string;
};
type ChatConfig = {
key: string;
};
interface ChatOptions {
text: string;
onUpdate: ChatOnUpdate;
}
type ChatOnUpdate = (data: ChatOptionsData) => void;
interface ChatOptionsData {
messages: Message[];
}
interface Message {
id: string;
created: string;
userId: string;
projectId: string;
chatSessionId: string;
environment: string;
type: MessageType;
messageUserId: string;
messageUserName?: string;
text: string;
metadata?: any;
}
declare const MESSAGE_TYPES: readonly ["ASSISTANT", "SYSTEM", "USER"];
type MessageType = (typeof MESSAGE_TYPES)[number];
export { chat, chat as default };
declare const getClient: (options?: ChatClientOptions) => {
chat: (options: ChatOptions) => Promise<{} | undefined>;
};
declare const testApi = "testApi";
export { ChatClientOptions, ChatConfig, ChatOnUpdate, ChatOptions, ChatOptionsData, MESSAGE_TYPES, Message, MessageType, getClient, testApi };

@@ -0,1 +1,2 @@

"use strict";
var __defProp = Object.defineProperty;

@@ -18,2 +19,22 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;

var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var __async = (__this, __arguments, generator) => {
return new Promise((resolve, reject) => {
var fulfilled = (value) => {
try {
step(generator.next(value));
} catch (e) {
reject(e);
}
};
var rejected = (value) => {
try {
step(generator.throw(value));
} catch (e) {
reject(e);
}
};
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
step((generator = generator.apply(__this, __arguments)).next());
});
};

@@ -23,13 +44,149 @@ // src/index.ts

__export(src_exports, {
chat: () => chat,
default: () => src_default
MESSAGE_TYPES: () => MESSAGE_TYPES,
getClient: () => getClient2,
testApi: () => testApi
});
module.exports = __toCommonJS(src_exports);
var chat = () => {
console.log("@contential/chat");
// ../../node_modules/.pnpm/@contential+api@0.0.1/node_modules/@contential/api/dist/index.mjs
var __async2 = (__this, __arguments, generator) => {
return new Promise((resolve, reject) => {
var fulfilled = (value) => {
try {
step(generator.next(value));
} catch (e) {
reject(e);
}
};
var rejected = (value) => {
try {
step(generator.throw(value));
} catch (e) {
reject(e);
}
};
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
step((generator = generator.apply(__this, __arguments)).next());
});
};
var src_default = chat;
var isServer = () => {
return !(typeof window != "undefined" && window.document);
};
var isClient = () => {
return !isServer();
};
var isSecretKey = (key) => {
return key.startsWith("sk_");
};
var getApiUrl = (url) => {
if (url)
return url;
return process.env.CONTENTIAL_API_URL || process.env.NEXT_PUBLIC_CONTENTIAL_API_URL || process.env.VITE_CONTENTIAL_API_URL || process.env.REACT_APP_CONTENTIAL_API_URL || process.env.GATSBY_CONTENTIAL_API_URL || "https://api.contential.ai";
};
var getKey = (key) => {
if (key)
return key;
return process.env.CONTENTIAL_SECRET_KEY || process.env.CONTENTIAL_PUBLISHABLE_KEY || process.env.NEXT_PUBLIC_CONTENTIAL_PUBLISHABLE_KEY || process.env.VITE_CONTENTIAL_PUBLISHABLE_KEY || process.env.REACT_APP_CONTENTIAL_PUBLISHABLE_KEY || process.env.GATSBY_CONTENTIAL_PUBLISHABLE_KEY || "";
};
var ContentialApi = class {
constructor(options) {
this.url = getApiUrl(options == null ? void 0 : options.url);
this.key = getKey(options == null ? void 0 : options.key);
if (!this.key) {
throw new Error("Missing: key");
}
if (isClient() && isSecretKey(this.key)) {
throw new Error(
"Using secret key on client is not allowed. Please use publishable key instead (pk_...)."
);
}
}
stream(_0) {
return __async2(this, arguments, function* ({
path,
data,
onUpdate
}) {
try {
const url = `${this.url}${path}`;
const response = yield fetch(url, {
method: "POST",
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${this.key}`
},
body: JSON.stringify(data)
});
if (!response.ok) {
throw new Error(response.statusText);
}
const body = response.body;
if (!body) {
return;
}
const start = Date.now();
const reader = body.getReader();
const decoder = new TextDecoder();
let isDone = false;
while (!isDone) {
try {
const { value, done } = yield reader.read();
const chunkValue = decoder.decode(value);
const dataString = chunkValue.split("data: ")[1] || chunkValue;
try {
const data2 = JSON.parse(dataString);
onUpdate(data2);
} catch (error) {
}
if (chunkValue.includes("[DONE]")) {
const end = Date.now();
const totalTime = end - start;
}
isDone = done;
} catch (error) {
isDone = true;
console.log(error);
}
}
return {};
} catch (error) {
console.log(error);
}
});
}
};
var getClient = (options) => {
return new ContentialApi(options);
};
// src/chat.ts
var getClient2 = (options) => {
const apiClient = getClient({
url: options == null ? void 0 : options.apiUrl,
key: options == null ? void 0 : options.key
});
return {
chat: (options2) => __async(void 0, null, function* () {
const result = yield apiClient.stream({
path: "/chat",
data: {
chatSessionId: "chat_5f91a6469d83c5158645cf86b2acfbda92382dce",
messageUserId: "user_123",
text: options2.text
},
onUpdate: options2.onUpdate
});
return result;
})
};
};
var testApi = "testApi";
// src/types.ts
var MESSAGE_TYPES = ["ASSISTANT", "SYSTEM", "USER"];
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
chat
MESSAGE_TYPES,
getClient,
testApi
});

12

package.json
{
"name": "@contential/chat",
"version": "0.0.2-test",
"version": "0.0.3",
"license": "MIT",

@@ -9,4 +9,7 @@ "main": "dist/index.js",

"private": false,
"devDependencies": {
"@contential/api": "^0.0.1"
},
"scripts": {
"dev": "tsup src/index.ts --dts --watch",
"dev": "tsup src/index.ts --format cjs,esm --dts --watch",
"clean": "rimraf dist",

@@ -17,4 +20,3 @@ "build": "npm-run-all clean build:main",

"publish:prod": "changeset version && changeset publish"
},
"devDependencies": {}
}
}
}

Sorry, the diff of this file is not supported yet

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