diff --git a/libs/shinkai-message-ts/src/pkg/package.json b/libs/shinkai-message-ts/src/pkg/package.json index f7afc6331..b82721638 100644 --- a/libs/shinkai-message-ts/src/pkg/package.json +++ b/libs/shinkai-message-ts/src/pkg/package.json @@ -3,7 +3,7 @@ "collaborators": [ "Nico Arqueros " ], - "version": "0.3.1", + "version": "0.3.2", "files": [ "shinkai_message_wasm_bg.wasm", "shinkai_message_wasm.js", diff --git a/libs/shinkai-message-ts/src/pkg/shinkai_message_wasm.d.ts b/libs/shinkai-message-ts/src/pkg/shinkai_message_wasm.d.ts index 1546ace51..59da55c69 100644 --- a/libs/shinkai-message-ts/src/pkg/shinkai_message_wasm.d.ts +++ b/libs/shinkai-message-ts/src/pkg/shinkai_message_wasm.d.ts @@ -1,15 +1,15 @@ /* tslint:disable */ /* eslint-disable */ /** -* @param {string} encryption_sk +* @param {string} input * @returns {string} */ -export function convert_encryption_sk_string_to_encryption_pk_string(encryption_sk: string): string; +export function calculate_blake3_hash(input: string): string; /** -* @param {string} input +* @param {string} encryption_sk * @returns {string} */ -export function calculate_blake3_hash(input: string): string; +export function convert_encryption_sk_string_to_encryption_pk_string(encryption_sk: string): string; /** */ export class InboxNameWrapper { diff --git a/libs/shinkai-message-ts/src/pkg/shinkai_message_wasm_bg.js b/libs/shinkai-message-ts/src/pkg/shinkai_message_wasm_bg.js index abf8ea6ab..a3dffe040 100644 --- a/libs/shinkai-message-ts/src/pkg/shinkai_message_wasm_bg.js +++ b/libs/shinkai-message-ts/src/pkg/shinkai_message_wasm_bg.js @@ -213,6 +213,29 @@ function addBorrowedObject(obj) { heap[--stack_pointer] = obj; return stack_pointer; } +/** +* @param {string} input +* @returns {string} +*/ +export function calculate_blake3_hash(input) { + let deferred2_0; + let deferred2_1; + try { + const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); + const ptr0 = passStringToWasm0(input, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); + const len0 = WASM_VECTOR_LEN; + wasm.calculate_blake3_hash(retptr, ptr0, len0); + var r0 = getInt32Memory0()[retptr / 4 + 0]; + var r1 = getInt32Memory0()[retptr / 4 + 1]; + deferred2_0 = r0; + deferred2_1 = r1; + return getStringFromWasm0(r0, r1); + } finally { + wasm.__wbindgen_add_to_stack_pointer(16); + wasm.__wbindgen_free(deferred2_0, deferred2_1, 1); + } +} + /** * @param {string} encryption_sk * @returns {string} @@ -244,29 +267,6 @@ export function convert_encryption_sk_string_to_encryption_pk_string(encryption_ } } -/** -* @param {string} input -* @returns {string} -*/ -export function calculate_blake3_hash(input) { - let deferred2_0; - let deferred2_1; - try { - const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); - const ptr0 = passStringToWasm0(input, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); - const len0 = WASM_VECTOR_LEN; - wasm.calculate_blake3_hash(retptr, ptr0, len0); - var r0 = getInt32Memory0()[retptr / 4 + 0]; - var r1 = getInt32Memory0()[retptr / 4 + 1]; - deferred2_0 = r0; - deferred2_1 = r1; - return getStringFromWasm0(r0, r1); - } finally { - wasm.__wbindgen_add_to_stack_pointer(16); - wasm.__wbindgen_free(deferred2_0, deferred2_1, 1); - } -} - function handleError(f, args) { try { return f.apply(this, args); diff --git a/libs/shinkai-message-ts/src/pkg/shinkai_message_wasm_bg.wasm b/libs/shinkai-message-ts/src/pkg/shinkai_message_wasm_bg.wasm index 7ccaa0f9e..e0f24522c 100644 Binary files a/libs/shinkai-message-ts/src/pkg/shinkai_message_wasm_bg.wasm and b/libs/shinkai-message-ts/src/pkg/shinkai_message_wasm_bg.wasm differ diff --git a/libs/shinkai-message-ts/src/pkg/shinkai_message_wasm_bg.wasm.d.ts b/libs/shinkai-message-ts/src/pkg/shinkai_message_wasm_bg.wasm.d.ts index e76244e1c..6101359a5 100644 --- a/libs/shinkai-message-ts/src/pkg/shinkai_message_wasm_bg.wasm.d.ts +++ b/libs/shinkai-message-ts/src/pkg/shinkai_message_wasm_bg.wasm.d.ts @@ -36,56 +36,6 @@ export function shinkaimessagebuilderwrapper_job_message(a: number, b: number, c export function shinkaimessagebuilderwrapper_terminate_message(a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number, j: number, k: number, l: number, m: number): void; export function shinkaimessagebuilderwrapper_error_message(a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number, j: number, k: number, l: number, m: number, n: number, o: number): void; export function shinkaimessagebuilderwrapper_get_last_unread_messages_from_inbox(a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number, j: number, k: number, l: number, m: number, n: number, o: number, p: number, q: number, r: number, s: number, t: number): void; -export function __wbg_inboxnamewrapper_free(a: number): void; -export function inboxnamewrapper_new(a: number, b: number): void; -export function inboxnamewrapper_to_string(a: number, b: number): void; -export function inboxnamewrapper_get_value(a: number): number; -export function inboxnamewrapper_get_is_e2e(a: number): number; -export function inboxnamewrapper_get_identities(a: number, b: number): void; -export function inboxnamewrapper_get_unique_id(a: number): number; -export function inboxnamewrapper_to_jsvalue(a: number, b: number): void; -export function inboxnamewrapper_to_json_str(a: number, b: number): void; -export function inboxnamewrapper_get_regular_inbox_name_from_params(a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number, j: number): void; -export function inboxnamewrapper_get_job_inbox_name_from_params(a: number, b: number, c: number): void; -export function inboxnamewrapper_get_inner(a: number): number; -export function __wbg_wasmencryptionmethod_free(a: number): void; -export function wasmencryptionmethod_new(a: number, b: number): number; -export function wasmencryptionmethod_as_str(a: number, b: number): void; -export function wasmencryptionmethod_DiffieHellmanChaChaPoly1305(a: number): void; -export function wasmencryptionmethod_None(a: number): void; -export function convert_encryption_sk_string_to_encryption_pk_string(a: number, b: number, c: number): void; -export function __wbg_shinkaimessagewrapper_free(a: number): void; -export function shinkaimessagewrapper_message_body(a: number, b: number): void; -export function shinkaimessagewrapper_set_message_body(a: number, b: number, c: number): void; -export function shinkaimessagewrapper_external_metadata(a: number, b: number): void; -export function shinkaimessagewrapper_set_external_metadata(a: number, b: number, c: number): void; -export function shinkaimessagewrapper_encryption(a: number, b: number): void; -export function shinkaimessagewrapper_set_encryption(a: number, b: number, c: number): void; -export function shinkaimessagewrapper_to_jsvalue(a: number, b: number): void; -export function shinkaimessagewrapper_fromJsValue(a: number, b: number): void; -export function shinkaimessagewrapper_to_json_str(a: number, b: number): void; -export function shinkaimessagewrapper_from_json_str(a: number, b: number, c: number): void; -export function shinkaimessagewrapper_calculate_blake3_hash(a: number, b: number): void; -export function shinkaimessagewrapper_new_with_empty_outer_signature(a: number): number; -export function shinkaimessagewrapper_new_with_empty_inner_signature(a: number, b: number): void; -export function shinkaimessagewrapper_inner_content_for_hashing(a: number, b: number): void; -export function shinkaimessagewrapper_calculate_blake3_hash_with_empty_outer_signature(a: number, b: number): void; -export function shinkaimessagewrapper_calculate_blake3_hash_with_empty_inner_signature(a: number, b: number): void; -export function shinkaimessagewrapper_generate_time_now(a: number): void; -export function __wbg_serializedagentwrapper_free(a: number): void; -export function serializedagentwrapper_fromStrings(a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number, j: number, k: number, l: number, m: number, n: number, o: number, p: number, q: number, r: number, s: number): void; -export function serializedagentwrapper_fromJsValue(a: number, b: number): void; -export function serializedagentwrapper_to_json_str(a: number, b: number): void; -export function serializedagentwrapper_from_json_str(a: number, b: number, c: number): void; -export function serializedagentwrapper_inner(a: number, b: number): void; -export function serializedagentwrapper_new(a: number, b: number): void; -export function serializedagentwrapper_to_jsvalue(a: number, b: number): void; -export function shinkaimessagewrapper_new(a: number, b: number): void; -export function shinkaistringtime_generateTimeNow(a: number): void; -export function shinkaistringtime_generateTimeInFutureWithSecs(a: number, b: number): void; -export function shinkaistringtime_generateSpecificTime(a: number, b: number, c: number, d: number, e: number, f: number, g: number): void; -export function calculate_blake3_hash(a: number, b: number, c: number): void; -export function __wbg_shinkaistringtime_free(a: number): void; export function __wbg_shinkainamewrapper_free(a: number): void; export function shinkainamewrapper_new(a: number, b: number): void; export function shinkainamewrapper_get_full_name(a: number): number; @@ -116,6 +66,56 @@ export function jobmessagewrapper_to_json_str(a: number, b: number): void; export function jobmessagewrapper_from_json_str(a: number, b: number, c: number): void; export function jobmessagewrapper_from_jsvalue(a: number, b: number): void; export function jobmessagewrapper_fromStrings(a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number): number; +export function __wbg_shinkaimessagewrapper_free(a: number): void; +export function shinkaimessagewrapper_message_body(a: number, b: number): void; +export function shinkaimessagewrapper_set_message_body(a: number, b: number, c: number): void; +export function shinkaimessagewrapper_external_metadata(a: number, b: number): void; +export function shinkaimessagewrapper_set_external_metadata(a: number, b: number, c: number): void; +export function shinkaimessagewrapper_encryption(a: number, b: number): void; +export function shinkaimessagewrapper_set_encryption(a: number, b: number, c: number): void; +export function shinkaimessagewrapper_to_jsvalue(a: number, b: number): void; +export function shinkaimessagewrapper_fromJsValue(a: number, b: number): void; +export function shinkaimessagewrapper_to_json_str(a: number, b: number): void; +export function shinkaimessagewrapper_from_json_str(a: number, b: number, c: number): void; +export function shinkaimessagewrapper_calculate_blake3_hash(a: number, b: number): void; +export function shinkaimessagewrapper_new_with_empty_outer_signature(a: number): number; +export function shinkaimessagewrapper_new_with_empty_inner_signature(a: number, b: number): void; +export function shinkaimessagewrapper_inner_content_for_hashing(a: number, b: number): void; +export function shinkaimessagewrapper_calculate_blake3_hash_with_empty_outer_signature(a: number, b: number): void; +export function shinkaimessagewrapper_calculate_blake3_hash_with_empty_inner_signature(a: number, b: number): void; +export function shinkaimessagewrapper_generate_time_now(a: number): void; +export function __wbg_serializedagentwrapper_free(a: number): void; +export function serializedagentwrapper_fromStrings(a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number, j: number, k: number, l: number, m: number, n: number, o: number, p: number, q: number, r: number, s: number): void; +export function serializedagentwrapper_fromJsValue(a: number, b: number): void; +export function serializedagentwrapper_to_json_str(a: number, b: number): void; +export function serializedagentwrapper_from_json_str(a: number, b: number, c: number): void; +export function serializedagentwrapper_inner(a: number, b: number): void; +export function shinkaistringtime_generateTimeNow(a: number): void; +export function shinkaistringtime_generateTimeInFutureWithSecs(a: number, b: number): void; +export function shinkaistringtime_generateSpecificTime(a: number, b: number, c: number, d: number, e: number, f: number, g: number): void; +export function calculate_blake3_hash(a: number, b: number, c: number): void; +export function serializedagentwrapper_new(a: number, b: number): void; +export function serializedagentwrapper_to_jsvalue(a: number, b: number): void; +export function __wbg_shinkaistringtime_free(a: number): void; +export function shinkaimessagewrapper_new(a: number, b: number): void; +export function __wbg_wasmencryptionmethod_free(a: number): void; +export function wasmencryptionmethod_new(a: number, b: number): number; +export function wasmencryptionmethod_as_str(a: number, b: number): void; +export function wasmencryptionmethod_DiffieHellmanChaChaPoly1305(a: number): void; +export function wasmencryptionmethod_None(a: number): void; +export function convert_encryption_sk_string_to_encryption_pk_string(a: number, b: number, c: number): void; +export function __wbg_inboxnamewrapper_free(a: number): void; +export function inboxnamewrapper_new(a: number, b: number): void; +export function inboxnamewrapper_to_string(a: number, b: number): void; +export function inboxnamewrapper_get_value(a: number): number; +export function inboxnamewrapper_get_is_e2e(a: number): number; +export function inboxnamewrapper_get_identities(a: number, b: number): void; +export function inboxnamewrapper_get_unique_id(a: number): number; +export function inboxnamewrapper_to_jsvalue(a: number, b: number): void; +export function inboxnamewrapper_to_json_str(a: number, b: number): void; +export function inboxnamewrapper_get_regular_inbox_name_from_params(a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number, j: number): void; +export function inboxnamewrapper_get_job_inbox_name_from_params(a: number, b: number, c: number): void; +export function inboxnamewrapper_get_inner(a: number): number; export function __wbindgen_malloc(a: number, b: number): number; export function __wbindgen_realloc(a: number, b: number, c: number, d: number): number; export function __wbindgen_add_to_stack_pointer(a: number): number; diff --git a/libs/shinkai-message-ts/src/wasm/JobCreationWrapper.test.ts b/libs/shinkai-message-ts/src/wasm/JobCreationWrapper.test.ts index ff809b416..843aa4aa7 100644 --- a/libs/shinkai-message-ts/src/wasm/JobCreationWrapper.test.ts +++ b/libs/shinkai-message-ts/src/wasm/JobCreationWrapper.test.ts @@ -4,7 +4,7 @@ import { JobCreationWrapper } from './JobCreationWrapper'; const jobCreationJson = `{ "scope": { - "database": [], + "vector_fs": [], "local": [] } }`; @@ -39,7 +39,7 @@ describe('JobCreationWrapper', () => { expect(JSON.parse(jsonString)).toEqual({ scope: { - database: [], + vector_fs: [], local: [], }, }); diff --git a/libs/shinkai-message-ts/src/wasm/SerializedAgentWrapper.test.ts b/libs/shinkai-message-ts/src/wasm/SerializedAgentWrapper.test.ts index b2163c290..e94811e0e 100644 --- a/libs/shinkai-message-ts/src/wasm/SerializedAgentWrapper.test.ts +++ b/libs/shinkai-message-ts/src/wasm/SerializedAgentWrapper.test.ts @@ -1,76 +1,136 @@ -import { test } from "vitest"; +import { test } from 'vitest'; -import { SerializedAgent } from "../models/SchemaTypes"; -import { SerializedAgentWrapper } from "./SerializedAgentWrapper"; -import { ShinkaiNameWrapper } from "./ShinkaiNameWrapper"; +import { SerializedAgent } from '../models/SchemaTypes'; +import { SerializedAgentWrapper } from './SerializedAgentWrapper'; +import { ShinkaiNameWrapper } from './ShinkaiNameWrapper'; -test("SerializedAgentWrapper conversion", async () => { +test('SerializedAgentWrapper conversion', async () => { // Create a SerializedAgentWrapper using fromStrings const serializedAgentWrapper = SerializedAgentWrapper.fromStrings( - "test_agent", - "@@node.shinkai/main/agent/test_agent", - "false", - "http://example.com", - "123456", - "openai:chatgpt3-turbo", - "permission1,permission2", - "bucket1,bucket2", - "sender1,sender2" + 'test_agent', + '@@node.shinkai/main/agent/test_agent', + 'false', + 'http://example.com', + '123456', + 'openai:chatgpt3-turbo', + 'permission1,permission2', + 'bucket1,bucket2', + 'sender1,sender2', ); // Get the inner SerializedAgent const agent = serializedAgentWrapper.inner; + console.log('Agent from SerializedAgentWrapper:'); + console.log(agent.full_identity_name); + // Create a ShinkaiNameWrapper from the full_identity_name const fullIdentityNameWrapper = new ShinkaiNameWrapper( - agent.full_identity_name.full_name + agent.full_identity_name, ); // Check that the fields are correctly converted - expect(agent.id).toBe("test_agent"); - expect(fullIdentityNameWrapper.get_full_name).toBe("@@node.shinkai/main/agent/test_agent") + expect(agent.id).toBe('test_agent'); + expect(fullIdentityNameWrapper.get_full_name).toBe( + '@@node.shinkai/main/agent/test_agent', + ); expect(agent.perform_locally).toBe(false); - expect(agent.external_url).toBe("http://example.com"); - expect(agent.api_key).toBe("123456"); - expect(agent.model.openai.model_type).toBe("chatgpt3-turbo"); - expect(agent.toolkit_permissions).toEqual(["permission1", "permission2"]); - expect(agent.storage_bucket_permissions).toEqual(["bucket1", "bucket2"]); - expect(agent.allowed_message_senders).toEqual(["sender1", "sender2"]); + expect(agent.external_url).toBe('http://example.com'); + expect(agent.api_key).toBe('123456'); + expect(agent.model).toBe('openai:chatgpt3-turbo'); + expect(agent.toolkit_permissions).toEqual(['permission1', 'permission2']); + expect(agent.storage_bucket_permissions).toEqual(['bucket1', 'bucket2']); + expect(agent.allowed_message_senders).toEqual(['sender1', 'sender2']); }); -test("SerializedAgent to SerializedAgentWrapper conversion", async () => { +test('SerializedAgent to SerializedAgentWrapper conversion', async () => { // Create a SerializedAgent const serializedAgent: SerializedAgent = { - id: "test_agent", - full_identity_name: "@@node.shinkai/main/agent/test_agent", + id: 'test_agent', + full_identity_name: '@@node.shinkai/main/agent/test_agent', perform_locally: false, - external_url: "http://example.com", - api_key: "123456", - model: { OpenAI: { model_type: "chatgpt3-turbo" } }, - toolkit_permissions: ["permission1", "permission2"], - storage_bucket_permissions: ["bucket1", "bucket2"], - allowed_message_senders: ["sender1", "sender2"] + external_url: 'http://example.com', + api_key: '123456', + model: { OpenAI: { model_type: 'chatgpt3-turbo' } }, + toolkit_permissions: ['permission1', 'permission2'], + storage_bucket_permissions: ['bucket1', 'bucket2'], + allowed_message_senders: ['sender1', 'sender2'], }; // Convert the SerializedAgent to a SerializedAgentWrapper - const serializedAgentWrapper = SerializedAgentWrapper.fromSerializedAgent(serializedAgent); + const serializedAgentWrapper = + SerializedAgentWrapper.fromSerializedAgent(serializedAgent); // Get the inner SerializedAgent const agent = serializedAgentWrapper.inner; // Create a ShinkaiNameWrapper from the full_identity_name const fullIdentityNameWrapper = new ShinkaiNameWrapper( - agent.full_identity_name.full_name + agent.full_identity_name, ); // Check that the fields are correctly converted - expect(agent.id).toBe("test_agent"); - expect(fullIdentityNameWrapper.get_full_name).toBe("@@node.shinkai/main/agent/test_agent") + expect(agent.id).toBe('test_agent'); + expect(fullIdentityNameWrapper.get_full_name).toBe( + '@@node.shinkai/main/agent/test_agent', + ); expect(agent.perform_locally).toBe(false); - expect(agent.external_url).toBe("http://example.com"); - expect(agent.api_key).toBe("123456"); - expect(agent.model.openai.model_type).toBe("chatgpt3-turbo"); - expect(agent.toolkit_permissions).toEqual(["permission1", "permission2"]); - expect(agent.storage_bucket_permissions).toEqual(["bucket1", "bucket2"]); - expect(agent.allowed_message_senders).toEqual(["sender1", "sender2"]); -}); \ No newline at end of file + expect(agent.external_url).toBe('http://example.com'); + expect(agent.api_key).toBe('123456'); + if (serializedAgent.model && serializedAgent.model.OpenAI) { + expect(agent.model).toBe( + `openai:${serializedAgent.model.OpenAI.model_type}`, + ); + } + expect(agent.toolkit_permissions).toEqual(['permission1', 'permission2']); + expect(agent.storage_bucket_permissions).toEqual(['bucket1', 'bucket2']); + expect(agent.allowed_message_senders).toEqual(['sender1', 'sender2']); +}); + +test('SerializedAgentWrapper serialization to string', async () => { + // Create a SerializedAgent + const serializedAgent: SerializedAgent = { + id: 'test_agent', + full_identity_name: '@@node.shinkai/main/agent/test_agent', + perform_locally: false, + external_url: 'http://example.com', + api_key: '123456', + model: { OpenAI: { model_type: 'chatgpt3-turbo' } }, + toolkit_permissions: ['permission1', 'permission2'], + storage_bucket_permissions: ['bucket1', 'bucket2'], + allowed_message_senders: ['sender1', 'sender2'], + }; + + // Convert the SerializedAgent to a SerializedAgentWrapper + const serializedAgentWrapper = + SerializedAgentWrapper.fromSerializedAgent(serializedAgent); + + // Serialize the SerializedAgentWrapper to a string + const serializedString = serializedAgentWrapper.to_json_str(); + + // Parse the serialized string back to an object + const parsedObject = JSON.parse(serializedString); + + // Check that the common fields are correctly serialized + expect(parsedObject.id).toBe(serializedAgent.id); + expect(parsedObject.full_identity_name).toBe( + serializedAgent.full_identity_name, + ); + expect(parsedObject.perform_locally).toBe(serializedAgent.perform_locally); + expect(parsedObject.external_url).toBe(serializedAgent.external_url); + expect(parsedObject.api_key).toBe(serializedAgent.api_key); + if (serializedAgent.model && serializedAgent.model.OpenAI) { + expect(parsedObject.model).toBe( + `openai:${serializedAgent.model.OpenAI.model_type}`, + ); + } + expect(parsedObject.toolkit_permissions).toEqual( + serializedAgent.toolkit_permissions, + ); + expect(parsedObject.storage_bucket_permissions).toEqual( + serializedAgent.storage_bucket_permissions, + ); + expect(parsedObject.allowed_message_senders).toEqual( + serializedAgent.allowed_message_senders, + ); +});