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

update to 060 #18

Merged
merged 1 commit into from
Apr 9, 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 package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@shinkai_protocol/shinkai-typescript-lib",
"version": "0.5.1",
"version": "0.6.0",
"description": "Typescript library to build and handle Shinkai Messages",
"type": "commonjs",
"main": "./dist/index.js",
Expand Down
31 changes: 31 additions & 0 deletions src/schemas/schema_types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ export enum MessageSchemaType {
VecFsMoveItem = "VecFsMoveItem",
VecFsCopyItem = "VecFsCopyItem",
ConvertFilesAndSaveToFolder = "ConvertFilesAndSaveToFolder",
CreateShareableFolder = "CreateShareableFolder",
AvailableSharedItems = "AvailableSharedItems",
SubscribeToSharedFolder = "SubscribeToSharedFolder",
UnsubscribeToSharedFolder = "UnsubscribeToSharedFolder",
MySubscriptions = "MySubscriptions",
}

export interface JobScope {
Expand Down Expand Up @@ -87,12 +92,16 @@ export interface SerializedAgent {
}
export interface AgentAPIModel {
OpenAI?: OpenAI;
ClaudeAI?: ClaudeAI;
GenericAPI?: GenericAPI;
Ollama?: Ollama;
ShinkaiBackend?: ShinkaiBackend;
LocalLLM?: LocalLLM;
}

export interface ClaudeAI {
model_type: string;
}
export interface OpenAI {
model_type: string;
}
Expand Down Expand Up @@ -201,3 +210,25 @@ export enum WSTopic {
Inbox = "inbox",
SmartInboxes = "smart_inboxes",
}

export interface APICreateShareableFolder {
path: string;
subscription_req: FolderSubscription;
}

export interface FolderSubscription {
minimum_token_delegation?: number;
minimum_time_delegated_hours?: number;
monthly_payment?: PaymentOption;
is_free: boolean;
}

export type PaymentOption =
| { type: 'USD', amount: number }
| { type: 'KAITokens', amount: number };

export enum SubscriptionPayment {
Free = "Free",
DirectDelegation = "DirectDelegation",
Payment = "Payment",
}
137 changes: 137 additions & 0 deletions src/shinkai_message_builder/shinkai_message_builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@ import {
} from "../cryptography/shinkai_signing";
import { InboxName } from "../schemas/inbox_name";
import {
APICreateShareableFolder,
JobScope,
MessageSchemaType,
SerializedAgent,
SubscriptionPayment,
TSEncryptionMethod,
} from "../schemas/schema_types";
import { ShinkaiBody } from "../shinkai_message/shinkai_body";
Expand Down Expand Up @@ -1193,4 +1195,139 @@ export class ShinkaiMessageBuilder {
MessageSchemaType.VecFsRetrieveVectorSearchSimplifiedJson
);
}

public static async subscriptionsCreateShareFolder(
payload: APICreateShareableFolder,
my_encryption_secret_key: EncryptionStaticKey,
my_signature_secret_key: SignatureStaticKey,
receiver_public_key: EncryptionPublicKey,
sender: ProfileName,
sender_subidentity: string,
node_receiver: ProfileName,
node_receiver_subidentity: string
): Promise<ShinkaiMessage> {
return this.createCustomShinkaiMessageToNode(
my_encryption_secret_key,
my_signature_secret_key,
receiver_public_key,
payload,
sender_subidentity,
sender,
node_receiver,
MessageSchemaType.CreateShareableFolder
);
}

public static async subscriptionAvailableSharedItems(
path: string | null,
streamer_node_name: string,
streamer_profile_name: string,
my_encryption_secret_key: EncryptionStaticKey,
my_signature_secret_key: SignatureStaticKey,
receiver_public_key: EncryptionPublicKey,
sender: ProfileName,
sender_subidentity: string,
node_receiver: ProfileName,
node_receiver_subidentity: string
): Promise<ShinkaiMessage> {
const payload = {
path: path || "/",
streamer_node_name,
streamer_profile_name,
};

return this.createCustomShinkaiMessageToNode(
my_encryption_secret_key,
my_signature_secret_key,
receiver_public_key,
payload,
sender_subidentity,
sender,
node_receiver,
MessageSchemaType.AvailableSharedItems
);
}

public static async vecfsSubscribeToSharedFolder(
shared_folder: string,
requirements: SubscriptionPayment,
streamer_node: string,
streamer_profile: string,
my_encryption_secret_key: EncryptionStaticKey,
my_signature_secret_key: SignatureStaticKey,
receiver_public_key: EncryptionPublicKey,
sender: ProfileName,
sender_subidentity: string,
node_receiver: ProfileName,
node_receiver_subidentity: string
): Promise<ShinkaiMessage> {
const payload = {
path: shared_folder,
streamer_node_name: streamer_node,
streamer_profile_name: streamer_profile,
payment: requirements,
};

return this.createCustomShinkaiMessageToNode(
my_encryption_secret_key,
my_signature_secret_key,
receiver_public_key,
payload,
sender_subidentity,
sender,
node_receiver,
MessageSchemaType.SubscribeToSharedFolder
);
}

public static async vecfsUnsubscribeToSharedFolder(
shared_folder: string,
streamer_node: string,
streamer_profile: string,
my_encryption_secret_key: EncryptionStaticKey,
my_signature_secret_key: SignatureStaticKey,
receiver_public_key: EncryptionPublicKey,
sender: ProfileName,
sender_subidentity: string,
node_receiver: ProfileName,
node_receiver_subidentity: string
): Promise<ShinkaiMessage> {
const payload = {
path: shared_folder,
streamer_node_name: streamer_node,
streamer_profile_name: streamer_profile,
};

return this.createCustomShinkaiMessageToNode(
my_encryption_secret_key,
my_signature_secret_key,
receiver_public_key,
payload,
sender_subidentity,
sender,
node_receiver,
MessageSchemaType.UnsubscribeToSharedFolder
);
}

public static async mySubscriptions(
my_encryption_secret_key: EncryptionStaticKey,
my_signature_secret_key: SignatureStaticKey,
receiver_public_key: EncryptionPublicKey,
sender: ProfileName,
sender_subidentity: string,
node_receiver: ProfileName,
node_receiver_subidentity: string
): Promise<ShinkaiMessage> {
return this.createCustomShinkaiMessageToNode(
my_encryption_secret_key,
my_signature_secret_key,
receiver_public_key,
"", // Empty payload as per Rust code comment
sender_subidentity,
sender,
node_receiver,
MessageSchemaType.MySubscriptions
);
}
}
Loading