-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Expose the ft_metadata method to the contract wasm. It is needed by wallets to properly show the balance. Docs about setting up the Fungible Token contract Implementation of web4_get to be able to serve a web page from the contract Scripts for bundling for web4, using the AI proxy frontend as an example Docs about submitting javascript code to the contract Docs for deploying the AI proxy to Spin cloud
- Loading branch information
1 parent
5c554e7
commit 6a9e5b6
Showing
13 changed files
with
680 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
target | ||
.spin | ||
dist | ||
web4.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import { KeyPairEd25519 } from "near-workspaces"; | ||
const keypair = KeyPairEd25519.fromRandom(); | ||
console.log(`export REPLACE_REFUND_SIGNATURE_PUBLIC_KEY=${JSON.stringify(Array.from(keypair.getPublicKey().data))}`); | ||
console.log(`export SPIN_VARIABLE_REFUND_SIGNING_KEY=${keypair.secretKey}`); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import html from '@web/rollup-plugin-html'; | ||
import { terser } from 'rollup-plugin-terser'; | ||
import { readFileSync, writeFileSync } from 'fs'; | ||
|
||
const { AI_PROXY_BASEURL, RPC_URL, NETWORK_ID } = process.env; | ||
|
||
if (!AI_PROXY_BASEURL) { | ||
throw ('Environment variable AI_PROXY_BASEURL not set. Must be set to the base URL of where the AI proxy is hosted'); | ||
} | ||
if (!RPC_URL) { | ||
throw ('Environment variable RPC_URL not set. Must be set to the NEAR RPC node URL'); | ||
} | ||
if (!NETWORK_ID) { | ||
throw ('Environment variable NETWORK_ID not set. Must be set to the NEAR protocol network id ( e.g. mainnet, testnet )'); | ||
} | ||
|
||
export default { | ||
input: ['./web/index.html'], | ||
output: { dir: 'dist' }, | ||
plugins: [html({ minify: true }), terser(), { | ||
name: 'inline-js', | ||
closeBundle: () => { | ||
const js = readFileSync('dist/main.js').toString() | ||
.replace('http://localhost:3000', AI_PROXY_BASEURL) | ||
.replace('http://localhost:14500', RPC_URL) | ||
.replace('"sandbox"', `"${NETWORK_ID}"`); | ||
|
||
const html = readFileSync('dist/index.html').toString() | ||
.replace(`<script type="module" src="./main.js"></script>`, `<script type="module">${js}</script>`); | ||
|
||
writeFileSync('web4.js', ` | ||
export function web4_get() { | ||
env.value_return(JSON.stringify({ | ||
contentType: 'text/html; charset=UTF-8', | ||
body: '${Buffer.from(html).toString('base64')}' | ||
}) | ||
); | ||
} | ||
`); | ||
|
||
} | ||
}], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,39 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
|
||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>OpenAI Proxy Streaming</title> | ||
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-QWTKZyjpPEjISv5WaRU9OFeRpok6YctnYmDr5pNlyT2bRjXh0JMhjY6hW+ALEwIH" crossorigin="anonymous"> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>OpenAI Proxy Streaming</title> | ||
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" | ||
integrity="sha384-QWTKZyjpPEjISv5WaRU9OFeRpok6YctnYmDr5pNlyT2bRjXh0JMhjY6hW+ALEwIH" crossorigin="anonymous"> | ||
</head> | ||
|
||
<body> | ||
<div class="container"> | ||
<div class="mb-3"> | ||
<label for="conversation_id" class="form-label">Conversation id ( generated )</label> | ||
<input id="conversation_id" class="form-control" readonly /> | ||
</div> | ||
<button id="startConversationButton" class="btn btn-primary">Start conversation</button> | ||
|
||
<div id="messages"></div> | ||
<div class="mb-3"> | ||
<label for="question" class="form-label">Question</label> | ||
<textarea id="question" class="form-control" disabled rows="4" placeholder="Type your question here..."></textarea> | ||
<button id="askAIButton" class="btn btn-primary" disabled>Ask AI</button> | ||
<label for="question" class="form-label">Question</label> | ||
<textarea id="question" class="form-control" disabled rows="4" | ||
placeholder="Type your question here..."></textarea> | ||
<button id="askAIButton" class="btn btn-primary" disabled>Ask AI</button> | ||
</div> | ||
<button id="refundButton" class="btn btn-primary">Stop conversation and refund tokens</button><br /> | ||
<div style="width: 100%"> | ||
<pre> | ||
<pre> | ||
<code id="refund_message" style="white-space: wrap;"></code> | ||
</pre> | ||
</div> | ||
</div> | ||
<script async src="https://ga.jspm.io/npm:[email protected]/dist/es-module-shims.js" crossorigin="anonymous"></script> | ||
<script type="importmap"> | ||
<script async src="https://ga.jspm.io/npm:[email protected]/dist/es-module-shims.js" | ||
crossorigin="anonymous"></script> | ||
<script type="importmap"> | ||
{ | ||
"imports": { | ||
"near-api-js": "https://ga.jspm.io/npm:[email protected]/lib/browser-index.js" | ||
|
@@ -107,8 +112,10 @@ | |
} | ||
} | ||
</script> | ||
<script src="main.js" type="module"> | ||
</script> | ||
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" integrity="sha384-YvpcrYf0tY3lHB60NNkmXc5s9fDVZLESaAA55NDzOxhy9GkcIdslK1eN7N6jIeHz" crossorigin="anonymous"></script> | ||
<script src="main.js" type="module"></script> | ||
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" | ||
integrity="sha384-YvpcrYf0tY3lHB60NNkmXc5s9fDVZLESaAA55NDzOxhy9GkcIdslK1eN7N6jIeHz" | ||
crossorigin="anonymous"></script> | ||
</body> | ||
|
||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.