@web-applets/sdk 0.0.6 → 0.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -2,6 +2,8 @@
2
2
 
3
3
  > An open SDK to create interoperable actions & views for agents – _a web of capabilities!_
4
4
 
5
+ 🔗 [Community Applets Repo](https://github.com/unternet-co/community-applets)
6
+
5
7
  ## What is it?
6
8
 
7
9
  Web Applets is a specification for modular, local web software that can be read and used by both humans and machines. Web Applets aims to be an interoperabe application layer for agents – instead of chatbots that can only interact in plain text, Web Applets allow them to actuate real software, read the results, and render rich, graphical views in response.
@@ -10,15 +12,27 @@ Did we mention it's _interoperable_? We think the future of software should be o
10
12
 
11
13
  ## Getting started
12
14
 
13
- First, clone this repo and run `npm run install`. There are a few sample applets included in `/applets`. To install these applets and start the playground, run `npm run playground`.
15
+ Install the applets SDK & CLI:
16
+
17
+ ```bash
18
+ npm i --save @web-applets/sdk
19
+ npm i --save-dev @web-applets/cli
20
+ ```
21
+
22
+ Then, initialize the `applets.config.json` and create a new blank applet:
23
+
24
+ ```bash
25
+ npx applets init
26
+ npx applets create <your-applet-name>
27
+ ```
14
28
 
15
- The fastest way to create a new applet is by duplicating one of the applet folders in `/applets`. The folder title will be part of the URL of your applet, so make sure it doesn't include any spaces or other non-URL-safe characters.
29
+ This creates an applet folder, with a build system built-in using Vite. You can change this to anything you want. We recommend building at this stage, as the SDK currently needs to be bundled. We're working on adding a statically hosted script to import.
16
30
 
17
31
  Inside your applet folder, you'll find a basic web app setup:
18
32
 
19
33
  - `public/manifest.json`: This file describes the Applet, and tells the model what actions are available and what parameters each action takes
20
34
  - `index.html`: Much like a website, this holds the main page for your applet
21
- - `main.js`: Declares functions that respond to each action, and a render function that updates the view based on state
35
+ - `src/main.ts`: Declares functions that respond to each action, and a render function that updates the view based on state
22
36
 
23
37
  > Want to use React? Svelte? Vue? – No problem, just install the dependencies and create an app the way you normally would in a website. So long as you're receiving the action events, it will all just work.
24
38
 
@@ -42,7 +56,7 @@ Let's say we want our applet to respond to a "set_name" action and render the us
42
56
  }
43
57
  ```
44
58
 
45
- Now let's update `main.ts` to assign an action handler:
59
+ Now let's update `src/main.ts` to assign an action handler:
46
60
 
47
61
  ```js
48
62
  // First, import the SDK
@@ -69,44 +83,42 @@ applet.onrender = () => {
69
83
  };
70
84
  ```
71
85
 
72
- Now if you run `npm run playground` from the project root, you should be able to test out your new applet action directly. This applet will now work in any environment where the SDK is installed.
86
+ Now if you run `npx applets playground`, you should be able to test out your new applet action directly. This applet will now work in any environment where the SDK is installed.
73
87
 
74
88
  ![A screenshot showing the 'playground' editing UI, with a web applets showing 'Hello, Web Applets'](docs/assets/web-applets-playground.png)
75
89
 
76
90
  ## Integrating Web Applets into your client
77
91
 
78
- Integrating Web Applets is just as easy as creating one. First, in your project, make sure you have the sdk installed:
92
+ Using Web Applets is just as easy as creating them!
93
+
94
+ First, build your applets. By default, this goes into a folder called `dist/`, but you'll likely want to change this in `applets.config.json` to point to wherever you're serving public files from. For example, in a Vite project, edit this to be `./public`.
95
+
96
+ Then, run:
79
97
 
80
98
  ```bash
81
- npm install @unternet/web-applets
99
+ npx applets build
82
100
  ```
83
101
 
84
- In your code, you can import the applets client:
102
+ Now in your main app, you can import the applets client:
85
103
 
86
104
  ```js
87
- import { applets } from '@unternet/web-applets';
105
+ import { applets } from '@web-applets/sdk';
88
106
  ```
89
107
 
90
- Now you can create a new applet from a URL:
108
+ Now you can import your applets from wherever they're being served from (note – you can also host them anywhere on the web):
91
109
 
92
110
  ```js
93
- const applet = await applets.load(
94
- `https://unternet.co/applets/helloworld.applet`
95
- );
111
+ const applet = await applets.load('/helloworld.applet'); // replace with a URL if hosted remotely
96
112
  applet.onstateupdated = (state) => console.log(state);
97
113
  applet.dispatchAction('set_name', { name: 'Web Applets' });
98
- // console.log: { name: "Web Applets" }
99
114
  ```
100
115
 
101
- The above applet is actually running headless, but we can get it to display by attaching it to an iframe. For the loading step, instead run:
116
+ The above applet is actually running headless, but we can get it to display by attaching it to a container. For the loading step, instead run:
102
117
 
103
118
  ```js
104
119
  const container = document.createElement('iframe');
105
120
  document.body.appendChild(container);
106
- const applet = await applets.load(
107
- `https://unternet.co/applets/helloworld.applet`,
108
- container
109
- );
121
+ const applet = await applets.load(`/helloworld.applet`, container);
110
122
  ```
111
123
 
112
124
  To load pre-existing saved state into an applet, simply set the state property:
@@ -116,7 +128,7 @@ applet.state = { name: 'Ada Lovelace' };
116
128
  // console.log: { name: "Ada Lovelace" }
117
129
  ```
118
130
 
119
- It may also be helpful to check available applets at a domain, or in your local public folder if you've downloaded a set of Web Applets you want your product to use. For that you can extract the applet headers from the App Manifest at the public root (`/manifest.json`), and see the available applets and a shorthand for the actions you can take in them. This is automatically created when you build your applets.
131
+ It may also be helpful to check available applets at a domain, or in your public folder. For that you can extract the applet headers from the App Manifest at the public root (`/manifest.json`), and see the available applets and a shorthand for the actions you can take in them. This is automatically created when you build your applets.
120
132
 
121
133
  ```js
122
134
  const headers = await applets.getHeaders('/');
@@ -148,6 +160,10 @@ You can use it to present a quick summary of available tools to your model, and
148
160
 
149
161
  ## Feedback & Community
150
162
 
163
+ This is a community project, and we're open to community members discussing the project direction, and submitting code!
164
+
165
+ To join the conversation, visit the Applets mailing list at [groups.google.com/a/unternet.co/g/community](https://groups.google.com/a/unternet.co/g/community). You can also find more about the company that's kicking off this work at [unternet.co](https://unternet.co)
166
+
151
167
  ## License
152
168
 
153
169
  [MIT](./LICENSE.md)
package/dist/context.d.ts CHANGED
@@ -1,8 +1,8 @@
1
- import { ActionHandlerDict, AppletState, AppletMessage, AppletMessageType, AppletMessageCallback, ActionParams, ActionHandler } from './types';
1
+ import { ActionHandlerDict, AppletMessage, AppletMessageType, AppletMessageCallback, ActionParams, ActionHandler } from './types';
2
2
  /**
3
3
  * Context
4
4
  */
5
- export declare class AppletContext<StateType = AppletState> extends EventTarget {
5
+ export declare class AppletContext<StateType = any> extends EventTarget {
6
6
  client: AppletClient;
7
7
  actionHandlers: ActionHandlerDict;
8
8
  state: StateType;
@@ -20,5 +20,5 @@ declare class AppletClient {
20
20
  on(messageType: AppletMessageType, callback: AppletMessageCallback): void;
21
21
  send(message: AppletMessage): Promise<void>;
22
22
  }
23
- export declare const appletContext: AppletContext<AppletState>;
23
+ export declare const appletContext: AppletContext<any>;
24
24
  export {};
package/dist/utils.d.ts CHANGED
@@ -1,3 +1,18 @@
1
- import { type AppletManifest } from './types';
1
+ import { AppletAction, type AppletManifest } from './types';
2
2
  export declare function getAppletsList(url: string): Promise<any>;
3
3
  export declare function loadAppletManifest(url: string): Promise<AppletManifest>;
4
+ export declare function createOpenAISchemaForAction(action: AppletAction): {
5
+ strict: boolean;
6
+ name: string;
7
+ schema: {
8
+ type: string;
9
+ required: string[];
10
+ properties: {
11
+ id: {
12
+ type: string;
13
+ };
14
+ params: import("./types").ActionParamSchema;
15
+ };
16
+ additionalProperties: boolean;
17
+ };
18
+ };
package/dist/utils.js CHANGED
@@ -31,3 +31,18 @@ export async function loadAppletManifest(url) {
31
31
  appletManifest.entrypoint = parseUrl(appletManifest.entrypoint, url);
32
32
  return appletManifest;
33
33
  }
34
+ export function createOpenAISchemaForAction(action) {
35
+ return {
36
+ strict: true,
37
+ name: 'action_schema',
38
+ schema: {
39
+ type: 'object',
40
+ required: Object.keys(action),
41
+ properties: {
42
+ id: { type: 'string' },
43
+ params: action.params,
44
+ },
45
+ additionalProperties: false,
46
+ },
47
+ };
48
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@web-applets/sdk",
3
- "version": "0.0.6",
3
+ "version": "0.0.7",
4
4
  "description": "The Web Applets SDK, for creating & hosting Web Applets.",
5
5
  "author": "Rupert Manfredi <rupert@unternet.co>",
6
6
  "license": "MIT",