@skillyo/embed 0.1.0
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/CHANGELOG.md +5 -0
- package/LICENSE +21 -0
- package/README.md +126 -0
- package/dist/index.cjs +167 -0
- package/dist/index.d.cts +83 -0
- package/dist/index.d.ts +83 -0
- package/dist/index.js +139 -0
- package/dist/react.cjs +95 -0
- package/dist/react.d.cts +45 -0
- package/dist/react.d.ts +45 -0
- package/dist/react.js +70 -0
- package/package.json +87 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## 0.1.0
|
|
4
|
+
|
|
5
|
+
First release: `SkillyoSkill`, `SkillyoProvider` and `SkillyoSkillHandle` for React and Next.js; `mount()` for everything else; the `ready`, `resize`, `run:started`, `run:completed` and `error` events. Built against Skillyo's loader API version 1.
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Skillyo
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
# @skillyo/embed
|
|
2
|
+
|
|
3
|
+
Put a Skillyo skill in your web app. Your visitors fill in a short form and get a finished result on your page, in your brand, without signing in. Runs are billed to the skill's owner, within the budget they set.
|
|
4
|
+
|
|
5
|
+
Works with React and Next.js out of the box, and with Vue, Svelte, Angular or plain JavaScript through `mount()`.
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```sh
|
|
10
|
+
npm install @skillyo/embed
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Use
|
|
14
|
+
|
|
15
|
+
```tsx
|
|
16
|
+
import { SkillyoSkill } from "@skillyo/embed/react";
|
|
17
|
+
|
|
18
|
+
export function PricingHelp() {
|
|
19
|
+
return <SkillyoSkill publicKey="sko_pub_…" skill="positioning-matrix" />;
|
|
20
|
+
}
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
You need a **website key** from Skillyo (Settings › API keys › Create key › Website key) with the skill ticked and your sites listed: your domain, any preview address, and `http://localhost:3000` for local work. Website keys are by invitation for now: email hello@skillyo.ai to ask for one.
|
|
24
|
+
|
|
25
|
+
How the skill looks and opens - in the page, a button, a slide-over or a floating button, with your brand - is set on the key in Skillyo. Change it there and your app picks it up on the next page load, with no new release.
|
|
26
|
+
|
|
27
|
+
## About the key
|
|
28
|
+
|
|
29
|
+
**The website key is meant to be in your code.** It is a public key, the same mechanism Stripe uses for its publishable keys, Google Maps for browser keys and Mapbox for public tokens: an identifier that is safe in a web page because everything it can do is limited on the server.
|
|
30
|
+
|
|
31
|
+
| A website key… | Because |
|
|
32
|
+
|---|---|
|
|
33
|
+
| Only works on your sites | Skillyo checks every request against the sites listed on the key |
|
|
34
|
+
| Only runs the skills you ticked | Any other skill name answers "not found" |
|
|
35
|
+
| Can't change the skill | Visitors run the version you saved; instructions and model can't be changed from the page |
|
|
36
|
+
| Can't run up a bill | A monthly budget, a per-key rate limit and a per-visitor limit all cap it |
|
|
37
|
+
| Sees nothing of yours | Visitors are anonymous: none of your knowledge, notes or connected data |
|
|
38
|
+
| Can be cut off at once | Pause or revoke it in Skillyo |
|
|
39
|
+
|
|
40
|
+
So: keep it in the code, or in a public environment variable (`VITE_SKILLYO_KEY`, `NEXT_PUBLIC_SKILLYO_KEY`). **Do not put it in a secrets store** - browser code can't read those, and the skill will not load.
|
|
41
|
+
|
|
42
|
+
A **secret key** (`sko_live_…`) is different: it acts as you, and belongs only on a server. This package refuses one.
|
|
43
|
+
|
|
44
|
+
## React
|
|
45
|
+
|
|
46
|
+
```tsx
|
|
47
|
+
<SkillyoSkill
|
|
48
|
+
publicKey="sko_pub_…"
|
|
49
|
+
skill="positioning-matrix"
|
|
50
|
+
inputs={{ company: account.name }} // fill in fields from your app
|
|
51
|
+
onRunComplete={({ runId, status }) => {}} // react when a run ends
|
|
52
|
+
/>
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
Several skills on one site? Set the key once:
|
|
56
|
+
|
|
57
|
+
```tsx
|
|
58
|
+
import { SkillyoProvider, SkillyoSkill } from "@skillyo/embed/react";
|
|
59
|
+
|
|
60
|
+
<SkillyoProvider publicKey="sko_pub_…">
|
|
61
|
+
<SkillyoSkill skill="positioning-matrix" />
|
|
62
|
+
<SkillyoSkill skill="pricing-check" />
|
|
63
|
+
</SkillyoProvider>
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
Open a button, slide-over or floating style from your own button:
|
|
67
|
+
|
|
68
|
+
```tsx
|
|
69
|
+
const skill = useRef<SkillyoSkillHandle>(null);
|
|
70
|
+
|
|
71
|
+
<button onClick={() => skill.current?.open()}>Find my position</button>
|
|
72
|
+
<SkillyoSkill ref={skill} publicKey="sko_pub_…" skill="positioning-matrix" />
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
| Prop | Type | |
|
|
76
|
+
|---|---|---|
|
|
77
|
+
| `publicKey` | `string` | The website key. Optional inside `SkillyoProvider` |
|
|
78
|
+
| `skill` | `string` | Required. The skill's name as it appears in its address |
|
|
79
|
+
| `inputs` | `Record<string, string \| number \| boolean>` | Fields to fill in, by input id. Visible and editable by the visitor |
|
|
80
|
+
| `autoHeight` | `boolean` | In the page only. Default `true`: grows to fit, never below the key's height |
|
|
81
|
+
| `className`, `style` | | On the element the skill mounts into |
|
|
82
|
+
| `onReady` | `() => void` | The skill is on screen |
|
|
83
|
+
| `onRunStarted` | `() => void` | The visitor pressed Run |
|
|
84
|
+
| `onRunComplete` | `({ runId, status }) => void` | `status`: `succeeded`, `failed` or `cancelled` |
|
|
85
|
+
| `onError` | `({ code }) => void` | The skill could not load - see the codes below |
|
|
86
|
+
| `onResize` | `({ height }) => void` | The skill's content height |
|
|
87
|
+
|
|
88
|
+
**Next.js:** the component is a client component and can be used from a server component. Nothing loads during server rendering.
|
|
89
|
+
|
|
90
|
+
## Any other framework
|
|
91
|
+
|
|
92
|
+
```js
|
|
93
|
+
import { mount } from "@skillyo/embed";
|
|
94
|
+
|
|
95
|
+
const skill = mount(document.querySelector("#pricing-help"), {
|
|
96
|
+
publicKey: "sko_pub_…",
|
|
97
|
+
skill: "positioning-matrix",
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
skill.on("run:completed", ({ runId, status }) => {});
|
|
101
|
+
skill.open();
|
|
102
|
+
skill.destroy(); // when your view goes away
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
## Error codes
|
|
106
|
+
|
|
107
|
+
| Code | Means | Fix |
|
|
108
|
+
|---|---|---|
|
|
109
|
+
| `origin_not_allowed` | This address isn't on the key's sites | Add it on the key, including preview addresses and localhost |
|
|
110
|
+
| `skill_not_allowed` | The key can't run this skill | Tick the skill on the key, and check its name |
|
|
111
|
+
| `key_invalid` | The key doesn't exist or was revoked | Copy the key again from its page in Skillyo |
|
|
112
|
+
| `key_paused` | The monthly budget is used up | Raise the budget, or wait for next month |
|
|
113
|
+
| `network` | Skillyo couldn't be reached | Check a content security policy allows `app.skillyo.ai` |
|
|
114
|
+
| `secret_key` | A secret key was passed | Use the website key, `sko_pub_…` |
|
|
115
|
+
|
|
116
|
+
## For AI coding agents
|
|
117
|
+
|
|
118
|
+
- Use the component exactly as shown. Do not also add Skillyo's script tag or write your own loader.
|
|
119
|
+
- The key is public and belongs in the code. Do not move it to a secrets store.
|
|
120
|
+
- If the skill shows "This tool isn't available right now", the fix is a setting on the key in Skillyo, not the code. Read the `onError` code.
|
|
121
|
+
|
|
122
|
+
## Versions
|
|
123
|
+
|
|
124
|
+
Semantic versioning. A change to a prop, an event or an error code is a new major version, listed in the changelog. How the skill draws and runs comes from Skillyo at load time, so most improvements reach your app without updating this package.
|
|
125
|
+
|
|
126
|
+
MIT licensed.
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var src_exports = {};
|
|
22
|
+
__export(src_exports, {
|
|
23
|
+
API_VERSION: () => API_VERSION,
|
|
24
|
+
DEFAULT_ORIGIN: () => DEFAULT_ORIGIN,
|
|
25
|
+
loadSkillyo: () => loadSkillyo,
|
|
26
|
+
mount: () => mount
|
|
27
|
+
});
|
|
28
|
+
module.exports = __toCommonJS(src_exports);
|
|
29
|
+
var DEFAULT_ORIGIN = "https://app.skillyo.ai";
|
|
30
|
+
var API_VERSION = 1;
|
|
31
|
+
var EVENTS = ["ready", "resize", "run:started", "run:completed", "error"];
|
|
32
|
+
function existing() {
|
|
33
|
+
const api = window.Skillyo;
|
|
34
|
+
return api && typeof api.mount === "function" && api.apiVersion >= API_VERSION ? api : null;
|
|
35
|
+
}
|
|
36
|
+
var loads = /* @__PURE__ */ new Map();
|
|
37
|
+
function loadSkillyo(origin = DEFAULT_ORIGIN) {
|
|
38
|
+
if (typeof window === "undefined") return Promise.reject(new Error("network"));
|
|
39
|
+
const ready = existing();
|
|
40
|
+
if (ready) return Promise.resolve(ready);
|
|
41
|
+
const base = origin.replace(/\/+$/, "");
|
|
42
|
+
let load = loads.get(base);
|
|
43
|
+
if (!load) {
|
|
44
|
+
load = new Promise((resolve, reject) => {
|
|
45
|
+
const s = document.createElement("script");
|
|
46
|
+
s.src = `${base}/embed.js`;
|
|
47
|
+
s.async = true;
|
|
48
|
+
s.setAttribute("data-skillyo-loader", "");
|
|
49
|
+
s.onload = () => {
|
|
50
|
+
const api = existing();
|
|
51
|
+
if (api) resolve(api);
|
|
52
|
+
else {
|
|
53
|
+
loads.delete(base);
|
|
54
|
+
reject(new Error("network"));
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
s.onerror = () => {
|
|
58
|
+
loads.delete(base);
|
|
59
|
+
s.remove();
|
|
60
|
+
reject(new Error("network"));
|
|
61
|
+
};
|
|
62
|
+
document.head.appendChild(s);
|
|
63
|
+
});
|
|
64
|
+
loads.set(base, load);
|
|
65
|
+
}
|
|
66
|
+
return load;
|
|
67
|
+
}
|
|
68
|
+
function warn(msg) {
|
|
69
|
+
if (typeof console !== "undefined") console.warn(`[skillyo] ${msg}`);
|
|
70
|
+
}
|
|
71
|
+
function mount(el, options) {
|
|
72
|
+
const listeners = /* @__PURE__ */ new Map();
|
|
73
|
+
let inner = null;
|
|
74
|
+
let destroyed = false;
|
|
75
|
+
let openWhenReady = false;
|
|
76
|
+
let settle;
|
|
77
|
+
const ready = new Promise((r) => {
|
|
78
|
+
settle = r;
|
|
79
|
+
});
|
|
80
|
+
const emit = (type, e) => {
|
|
81
|
+
var _a;
|
|
82
|
+
(_a = listeners.get(type)) == null ? void 0 : _a.forEach((fn) => {
|
|
83
|
+
try {
|
|
84
|
+
fn(e);
|
|
85
|
+
} catch {
|
|
86
|
+
warn(`a ${type} listener threw`);
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
};
|
|
90
|
+
const fail = (code) => {
|
|
91
|
+
Promise.resolve().then(() => {
|
|
92
|
+
if (!destroyed) {
|
|
93
|
+
emit("error", { code });
|
|
94
|
+
settle({ ok: false, code });
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
};
|
|
98
|
+
const handle = {
|
|
99
|
+
ready,
|
|
100
|
+
on(type, fn) {
|
|
101
|
+
let set = listeners.get(type);
|
|
102
|
+
if (!set) listeners.set(type, set = /* @__PURE__ */ new Set());
|
|
103
|
+
set.add(fn);
|
|
104
|
+
return () => {
|
|
105
|
+
set.delete(fn);
|
|
106
|
+
};
|
|
107
|
+
},
|
|
108
|
+
open() {
|
|
109
|
+
if (destroyed) return;
|
|
110
|
+
if (inner) inner.open();
|
|
111
|
+
else openWhenReady = true;
|
|
112
|
+
},
|
|
113
|
+
close() {
|
|
114
|
+
openWhenReady = false;
|
|
115
|
+
inner == null ? void 0 : inner.close();
|
|
116
|
+
},
|
|
117
|
+
destroy() {
|
|
118
|
+
if (destroyed) return;
|
|
119
|
+
destroyed = true;
|
|
120
|
+
inner == null ? void 0 : inner.destroy();
|
|
121
|
+
inner = null;
|
|
122
|
+
listeners.clear();
|
|
123
|
+
settle({ ok: false, code: null });
|
|
124
|
+
}
|
|
125
|
+
};
|
|
126
|
+
if (!el || !options || !options.publicKey || !options.skill) {
|
|
127
|
+
warn("mount() needs an element, a publicKey and a skill");
|
|
128
|
+
fail("invalid_options");
|
|
129
|
+
return handle;
|
|
130
|
+
}
|
|
131
|
+
if (options.publicKey.startsWith("sko_live_")) {
|
|
132
|
+
warn("That is a secret key. Use the website key (sko_pub_\u2026) from Settings \u203A API keys.");
|
|
133
|
+
fail("secret_key");
|
|
134
|
+
return handle;
|
|
135
|
+
}
|
|
136
|
+
loadSkillyo(options.origin).then(
|
|
137
|
+
(api) => {
|
|
138
|
+
if (destroyed) return;
|
|
139
|
+
const h = api.mount(el, {
|
|
140
|
+
key: options.publicKey,
|
|
141
|
+
skill: options.skill,
|
|
142
|
+
inputs: options.inputs,
|
|
143
|
+
autoHeight: options.autoHeight !== false
|
|
144
|
+
});
|
|
145
|
+
inner = h;
|
|
146
|
+
for (const type of EVENTS) h.on(type, (e) => emit(type, e != null ? e : {}));
|
|
147
|
+
h.ready.then((r) => {
|
|
148
|
+
var _a;
|
|
149
|
+
if (destroyed) return;
|
|
150
|
+
settle({ ok: r.ok, code: (_a = r.code) != null ? _a : null });
|
|
151
|
+
if (r.ok && openWhenReady) {
|
|
152
|
+
openWhenReady = false;
|
|
153
|
+
h.open();
|
|
154
|
+
}
|
|
155
|
+
});
|
|
156
|
+
},
|
|
157
|
+
() => fail("network")
|
|
158
|
+
);
|
|
159
|
+
return handle;
|
|
160
|
+
}
|
|
161
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
162
|
+
0 && (module.exports = {
|
|
163
|
+
API_VERSION,
|
|
164
|
+
DEFAULT_ORIGIN,
|
|
165
|
+
loadSkillyo,
|
|
166
|
+
mount
|
|
167
|
+
});
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
/** How a run ended. */
|
|
2
|
+
type RunStatus = 'succeeded' | 'failed' | 'cancelled';
|
|
3
|
+
/** Why a skill could not load. The fix for each is in the package reference. */
|
|
4
|
+
type ErrorCode = 'origin_not_allowed' | 'skill_not_allowed' | 'key_invalid' | 'key_paused' | 'network' | 'secret_key' | 'invalid_options' | (string & {});
|
|
5
|
+
interface SkillyoEvents {
|
|
6
|
+
/** The skill is on screen. */
|
|
7
|
+
ready: Record<string, never>;
|
|
8
|
+
/** The skill's content height, in px. */
|
|
9
|
+
resize: {
|
|
10
|
+
height: number;
|
|
11
|
+
};
|
|
12
|
+
/** The visitor pressed Run. */
|
|
13
|
+
'run:started': Record<string, never>;
|
|
14
|
+
/** A run ended. `runId` reads the run from Skillyo's API with your key. */
|
|
15
|
+
'run:completed': {
|
|
16
|
+
runId: string | null;
|
|
17
|
+
status: RunStatus;
|
|
18
|
+
};
|
|
19
|
+
/** The skill could not load. */
|
|
20
|
+
error: {
|
|
21
|
+
code: ErrorCode;
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
type SkillyoEvent = keyof SkillyoEvents;
|
|
25
|
+
/** A value a skill's input can be filled with. */
|
|
26
|
+
type InputValue = string | number | boolean | null | undefined;
|
|
27
|
+
interface MountOptions {
|
|
28
|
+
/** The website key, `sko_pub_…`. Public by design: it belongs in your code. */
|
|
29
|
+
publicKey: string;
|
|
30
|
+
/** The skill's name as it appears in its address, e.g. "positioning-matrix". */
|
|
31
|
+
skill: string;
|
|
32
|
+
/** Fields to fill in, by input id. The visitor can see and change them, so
|
|
33
|
+
* never pass anything private. An input the key prefills wins. */
|
|
34
|
+
inputs?: Record<string, InputValue>;
|
|
35
|
+
/** "In the page" grows to fit its content, never below the height set on
|
|
36
|
+
* the key. Default true. */
|
|
37
|
+
autoHeight?: boolean;
|
|
38
|
+
/** Where Skillyo is. Default https://app.skillyo.ai - for testing only. */
|
|
39
|
+
origin?: string;
|
|
40
|
+
}
|
|
41
|
+
interface SkillyoHandle {
|
|
42
|
+
/** Settles once the skill is drawn, or could not be. Never rejects. */
|
|
43
|
+
ready: Promise<{
|
|
44
|
+
ok: boolean;
|
|
45
|
+
code: ErrorCode | null;
|
|
46
|
+
}>;
|
|
47
|
+
/** Listen for an event. Returns the function that stops listening. */
|
|
48
|
+
on<K extends SkillyoEvent>(type: K, fn: (event: SkillyoEvents[K]) => void): () => void;
|
|
49
|
+
/** Open the skill, for the button, slide-over and floating styles. */
|
|
50
|
+
open(): void;
|
|
51
|
+
close(): void;
|
|
52
|
+
/** Remove the skill and everything it put on the page. Call it when your view unmounts. */
|
|
53
|
+
destroy(): void;
|
|
54
|
+
}
|
|
55
|
+
declare const DEFAULT_ORIGIN = "https://app.skillyo.ai";
|
|
56
|
+
/** The loader API this package was built against. `embed.js` honors it. */
|
|
57
|
+
declare const API_VERSION = 1;
|
|
58
|
+
interface LoaderHandle {
|
|
59
|
+
ready: Promise<{
|
|
60
|
+
ok: boolean;
|
|
61
|
+
code: string | null;
|
|
62
|
+
}>;
|
|
63
|
+
on(type: string, fn: (e: unknown) => void): () => void;
|
|
64
|
+
open(): void;
|
|
65
|
+
close(): void;
|
|
66
|
+
destroy(): void;
|
|
67
|
+
}
|
|
68
|
+
interface LoaderApi {
|
|
69
|
+
apiVersion: number;
|
|
70
|
+
mount(el: Element, opts: {
|
|
71
|
+
key: string;
|
|
72
|
+
skill: string;
|
|
73
|
+
inputs?: Record<string, InputValue>;
|
|
74
|
+
autoHeight?: boolean;
|
|
75
|
+
}): LoaderHandle;
|
|
76
|
+
}
|
|
77
|
+
/** Load Skillyo's loader once per page. A page that also has the script tag
|
|
78
|
+
* pasted in shares it rather than loading a second copy. */
|
|
79
|
+
declare function loadSkillyo(origin?: string): Promise<LoaderApi>;
|
|
80
|
+
/** Put a skill into an element. Returns at once; the skill draws when Skillyo answers. */
|
|
81
|
+
declare function mount(el: HTMLElement, options: MountOptions): SkillyoHandle;
|
|
82
|
+
|
|
83
|
+
export { API_VERSION, DEFAULT_ORIGIN, type ErrorCode, type InputValue, type MountOptions, type RunStatus, type SkillyoEvent, type SkillyoEvents, type SkillyoHandle, loadSkillyo, mount };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
/** How a run ended. */
|
|
2
|
+
type RunStatus = 'succeeded' | 'failed' | 'cancelled';
|
|
3
|
+
/** Why a skill could not load. The fix for each is in the package reference. */
|
|
4
|
+
type ErrorCode = 'origin_not_allowed' | 'skill_not_allowed' | 'key_invalid' | 'key_paused' | 'network' | 'secret_key' | 'invalid_options' | (string & {});
|
|
5
|
+
interface SkillyoEvents {
|
|
6
|
+
/** The skill is on screen. */
|
|
7
|
+
ready: Record<string, never>;
|
|
8
|
+
/** The skill's content height, in px. */
|
|
9
|
+
resize: {
|
|
10
|
+
height: number;
|
|
11
|
+
};
|
|
12
|
+
/** The visitor pressed Run. */
|
|
13
|
+
'run:started': Record<string, never>;
|
|
14
|
+
/** A run ended. `runId` reads the run from Skillyo's API with your key. */
|
|
15
|
+
'run:completed': {
|
|
16
|
+
runId: string | null;
|
|
17
|
+
status: RunStatus;
|
|
18
|
+
};
|
|
19
|
+
/** The skill could not load. */
|
|
20
|
+
error: {
|
|
21
|
+
code: ErrorCode;
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
type SkillyoEvent = keyof SkillyoEvents;
|
|
25
|
+
/** A value a skill's input can be filled with. */
|
|
26
|
+
type InputValue = string | number | boolean | null | undefined;
|
|
27
|
+
interface MountOptions {
|
|
28
|
+
/** The website key, `sko_pub_…`. Public by design: it belongs in your code. */
|
|
29
|
+
publicKey: string;
|
|
30
|
+
/** The skill's name as it appears in its address, e.g. "positioning-matrix". */
|
|
31
|
+
skill: string;
|
|
32
|
+
/** Fields to fill in, by input id. The visitor can see and change them, so
|
|
33
|
+
* never pass anything private. An input the key prefills wins. */
|
|
34
|
+
inputs?: Record<string, InputValue>;
|
|
35
|
+
/** "In the page" grows to fit its content, never below the height set on
|
|
36
|
+
* the key. Default true. */
|
|
37
|
+
autoHeight?: boolean;
|
|
38
|
+
/** Where Skillyo is. Default https://app.skillyo.ai - for testing only. */
|
|
39
|
+
origin?: string;
|
|
40
|
+
}
|
|
41
|
+
interface SkillyoHandle {
|
|
42
|
+
/** Settles once the skill is drawn, or could not be. Never rejects. */
|
|
43
|
+
ready: Promise<{
|
|
44
|
+
ok: boolean;
|
|
45
|
+
code: ErrorCode | null;
|
|
46
|
+
}>;
|
|
47
|
+
/** Listen for an event. Returns the function that stops listening. */
|
|
48
|
+
on<K extends SkillyoEvent>(type: K, fn: (event: SkillyoEvents[K]) => void): () => void;
|
|
49
|
+
/** Open the skill, for the button, slide-over and floating styles. */
|
|
50
|
+
open(): void;
|
|
51
|
+
close(): void;
|
|
52
|
+
/** Remove the skill and everything it put on the page. Call it when your view unmounts. */
|
|
53
|
+
destroy(): void;
|
|
54
|
+
}
|
|
55
|
+
declare const DEFAULT_ORIGIN = "https://app.skillyo.ai";
|
|
56
|
+
/** The loader API this package was built against. `embed.js` honors it. */
|
|
57
|
+
declare const API_VERSION = 1;
|
|
58
|
+
interface LoaderHandle {
|
|
59
|
+
ready: Promise<{
|
|
60
|
+
ok: boolean;
|
|
61
|
+
code: string | null;
|
|
62
|
+
}>;
|
|
63
|
+
on(type: string, fn: (e: unknown) => void): () => void;
|
|
64
|
+
open(): void;
|
|
65
|
+
close(): void;
|
|
66
|
+
destroy(): void;
|
|
67
|
+
}
|
|
68
|
+
interface LoaderApi {
|
|
69
|
+
apiVersion: number;
|
|
70
|
+
mount(el: Element, opts: {
|
|
71
|
+
key: string;
|
|
72
|
+
skill: string;
|
|
73
|
+
inputs?: Record<string, InputValue>;
|
|
74
|
+
autoHeight?: boolean;
|
|
75
|
+
}): LoaderHandle;
|
|
76
|
+
}
|
|
77
|
+
/** Load Skillyo's loader once per page. A page that also has the script tag
|
|
78
|
+
* pasted in shares it rather than loading a second copy. */
|
|
79
|
+
declare function loadSkillyo(origin?: string): Promise<LoaderApi>;
|
|
80
|
+
/** Put a skill into an element. Returns at once; the skill draws when Skillyo answers. */
|
|
81
|
+
declare function mount(el: HTMLElement, options: MountOptions): SkillyoHandle;
|
|
82
|
+
|
|
83
|
+
export { API_VERSION, DEFAULT_ORIGIN, type ErrorCode, type InputValue, type MountOptions, type RunStatus, type SkillyoEvent, type SkillyoEvents, type SkillyoHandle, loadSkillyo, mount };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
// src/index.ts
|
|
2
|
+
var DEFAULT_ORIGIN = "https://app.skillyo.ai";
|
|
3
|
+
var API_VERSION = 1;
|
|
4
|
+
var EVENTS = ["ready", "resize", "run:started", "run:completed", "error"];
|
|
5
|
+
function existing() {
|
|
6
|
+
const api = window.Skillyo;
|
|
7
|
+
return api && typeof api.mount === "function" && api.apiVersion >= API_VERSION ? api : null;
|
|
8
|
+
}
|
|
9
|
+
var loads = /* @__PURE__ */ new Map();
|
|
10
|
+
function loadSkillyo(origin = DEFAULT_ORIGIN) {
|
|
11
|
+
if (typeof window === "undefined") return Promise.reject(new Error("network"));
|
|
12
|
+
const ready = existing();
|
|
13
|
+
if (ready) return Promise.resolve(ready);
|
|
14
|
+
const base = origin.replace(/\/+$/, "");
|
|
15
|
+
let load = loads.get(base);
|
|
16
|
+
if (!load) {
|
|
17
|
+
load = new Promise((resolve, reject) => {
|
|
18
|
+
const s = document.createElement("script");
|
|
19
|
+
s.src = `${base}/embed.js`;
|
|
20
|
+
s.async = true;
|
|
21
|
+
s.setAttribute("data-skillyo-loader", "");
|
|
22
|
+
s.onload = () => {
|
|
23
|
+
const api = existing();
|
|
24
|
+
if (api) resolve(api);
|
|
25
|
+
else {
|
|
26
|
+
loads.delete(base);
|
|
27
|
+
reject(new Error("network"));
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
s.onerror = () => {
|
|
31
|
+
loads.delete(base);
|
|
32
|
+
s.remove();
|
|
33
|
+
reject(new Error("network"));
|
|
34
|
+
};
|
|
35
|
+
document.head.appendChild(s);
|
|
36
|
+
});
|
|
37
|
+
loads.set(base, load);
|
|
38
|
+
}
|
|
39
|
+
return load;
|
|
40
|
+
}
|
|
41
|
+
function warn(msg) {
|
|
42
|
+
if (typeof console !== "undefined") console.warn(`[skillyo] ${msg}`);
|
|
43
|
+
}
|
|
44
|
+
function mount(el, options) {
|
|
45
|
+
const listeners = /* @__PURE__ */ new Map();
|
|
46
|
+
let inner = null;
|
|
47
|
+
let destroyed = false;
|
|
48
|
+
let openWhenReady = false;
|
|
49
|
+
let settle;
|
|
50
|
+
const ready = new Promise((r) => {
|
|
51
|
+
settle = r;
|
|
52
|
+
});
|
|
53
|
+
const emit = (type, e) => {
|
|
54
|
+
var _a;
|
|
55
|
+
(_a = listeners.get(type)) == null ? void 0 : _a.forEach((fn) => {
|
|
56
|
+
try {
|
|
57
|
+
fn(e);
|
|
58
|
+
} catch {
|
|
59
|
+
warn(`a ${type} listener threw`);
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
};
|
|
63
|
+
const fail = (code) => {
|
|
64
|
+
Promise.resolve().then(() => {
|
|
65
|
+
if (!destroyed) {
|
|
66
|
+
emit("error", { code });
|
|
67
|
+
settle({ ok: false, code });
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
};
|
|
71
|
+
const handle = {
|
|
72
|
+
ready,
|
|
73
|
+
on(type, fn) {
|
|
74
|
+
let set = listeners.get(type);
|
|
75
|
+
if (!set) listeners.set(type, set = /* @__PURE__ */ new Set());
|
|
76
|
+
set.add(fn);
|
|
77
|
+
return () => {
|
|
78
|
+
set.delete(fn);
|
|
79
|
+
};
|
|
80
|
+
},
|
|
81
|
+
open() {
|
|
82
|
+
if (destroyed) return;
|
|
83
|
+
if (inner) inner.open();
|
|
84
|
+
else openWhenReady = true;
|
|
85
|
+
},
|
|
86
|
+
close() {
|
|
87
|
+
openWhenReady = false;
|
|
88
|
+
inner == null ? void 0 : inner.close();
|
|
89
|
+
},
|
|
90
|
+
destroy() {
|
|
91
|
+
if (destroyed) return;
|
|
92
|
+
destroyed = true;
|
|
93
|
+
inner == null ? void 0 : inner.destroy();
|
|
94
|
+
inner = null;
|
|
95
|
+
listeners.clear();
|
|
96
|
+
settle({ ok: false, code: null });
|
|
97
|
+
}
|
|
98
|
+
};
|
|
99
|
+
if (!el || !options || !options.publicKey || !options.skill) {
|
|
100
|
+
warn("mount() needs an element, a publicKey and a skill");
|
|
101
|
+
fail("invalid_options");
|
|
102
|
+
return handle;
|
|
103
|
+
}
|
|
104
|
+
if (options.publicKey.startsWith("sko_live_")) {
|
|
105
|
+
warn("That is a secret key. Use the website key (sko_pub_\u2026) from Settings \u203A API keys.");
|
|
106
|
+
fail("secret_key");
|
|
107
|
+
return handle;
|
|
108
|
+
}
|
|
109
|
+
loadSkillyo(options.origin).then(
|
|
110
|
+
(api) => {
|
|
111
|
+
if (destroyed) return;
|
|
112
|
+
const h = api.mount(el, {
|
|
113
|
+
key: options.publicKey,
|
|
114
|
+
skill: options.skill,
|
|
115
|
+
inputs: options.inputs,
|
|
116
|
+
autoHeight: options.autoHeight !== false
|
|
117
|
+
});
|
|
118
|
+
inner = h;
|
|
119
|
+
for (const type of EVENTS) h.on(type, (e) => emit(type, e != null ? e : {}));
|
|
120
|
+
h.ready.then((r) => {
|
|
121
|
+
var _a;
|
|
122
|
+
if (destroyed) return;
|
|
123
|
+
settle({ ok: r.ok, code: (_a = r.code) != null ? _a : null });
|
|
124
|
+
if (r.ok && openWhenReady) {
|
|
125
|
+
openWhenReady = false;
|
|
126
|
+
h.open();
|
|
127
|
+
}
|
|
128
|
+
});
|
|
129
|
+
},
|
|
130
|
+
() => fail("network")
|
|
131
|
+
);
|
|
132
|
+
return handle;
|
|
133
|
+
}
|
|
134
|
+
export {
|
|
135
|
+
API_VERSION,
|
|
136
|
+
DEFAULT_ORIGIN,
|
|
137
|
+
loadSkillyo,
|
|
138
|
+
mount
|
|
139
|
+
};
|
package/dist/react.cjs
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
"use strict";
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
20
|
+
|
|
21
|
+
// src/react.tsx
|
|
22
|
+
var react_exports = {};
|
|
23
|
+
__export(react_exports, {
|
|
24
|
+
SkillyoProvider: () => SkillyoProvider,
|
|
25
|
+
SkillyoSkill: () => SkillyoSkill
|
|
26
|
+
});
|
|
27
|
+
module.exports = __toCommonJS(react_exports);
|
|
28
|
+
var import_react = require("react");
|
|
29
|
+
var import_embed = require("@skillyo/embed");
|
|
30
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
31
|
+
var SkillyoContext = (0, import_react.createContext)({});
|
|
32
|
+
function SkillyoProvider({ publicKey, origin, children }) {
|
|
33
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(SkillyoContext.Provider, { value: { publicKey, origin }, children });
|
|
34
|
+
}
|
|
35
|
+
var SkillyoSkill = (0, import_react.forwardRef)(function SkillyoSkill2(props, ref) {
|
|
36
|
+
var _a, _b, _c;
|
|
37
|
+
const fromProvider = (0, import_react.useContext)(SkillyoContext);
|
|
38
|
+
const publicKey = (_a = props.publicKey) != null ? _a : fromProvider.publicKey;
|
|
39
|
+
const origin = (_b = props.origin) != null ? _b : fromProvider.origin;
|
|
40
|
+
const el = (0, import_react.useRef)(null);
|
|
41
|
+
const handle = (0, import_react.useRef)(null);
|
|
42
|
+
const latest = (0, import_react.useRef)(props);
|
|
43
|
+
latest.current = props;
|
|
44
|
+
const inputsKey = JSON.stringify((_c = props.inputs) != null ? _c : null);
|
|
45
|
+
(0, import_react.useEffect)(() => {
|
|
46
|
+
const node = el.current;
|
|
47
|
+
if (!node) return;
|
|
48
|
+
if (!publicKey) {
|
|
49
|
+
console.warn("[skillyo] SkillyoSkill needs a publicKey, or a SkillyoProvider around it");
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
const h = (0, import_embed.mount)(node, { publicKey, skill: props.skill, inputs: props.inputs, autoHeight: props.autoHeight, origin });
|
|
53
|
+
handle.current = h;
|
|
54
|
+
h.on("ready", () => {
|
|
55
|
+
var _a2, _b2;
|
|
56
|
+
return (_b2 = (_a2 = latest.current).onReady) == null ? void 0 : _b2.call(_a2);
|
|
57
|
+
});
|
|
58
|
+
h.on("run:started", () => {
|
|
59
|
+
var _a2, _b2;
|
|
60
|
+
return (_b2 = (_a2 = latest.current).onRunStarted) == null ? void 0 : _b2.call(_a2);
|
|
61
|
+
});
|
|
62
|
+
h.on("run:completed", (e) => {
|
|
63
|
+
var _a2, _b2;
|
|
64
|
+
return (_b2 = (_a2 = latest.current).onRunComplete) == null ? void 0 : _b2.call(_a2, e);
|
|
65
|
+
});
|
|
66
|
+
h.on("error", (e) => {
|
|
67
|
+
var _a2, _b2;
|
|
68
|
+
return (_b2 = (_a2 = latest.current).onError) == null ? void 0 : _b2.call(_a2, e);
|
|
69
|
+
});
|
|
70
|
+
h.on("resize", (e) => {
|
|
71
|
+
var _a2, _b2;
|
|
72
|
+
return (_b2 = (_a2 = latest.current).onResize) == null ? void 0 : _b2.call(_a2, e);
|
|
73
|
+
});
|
|
74
|
+
return () => {
|
|
75
|
+
h.destroy();
|
|
76
|
+
if (handle.current === h) handle.current = null;
|
|
77
|
+
};
|
|
78
|
+
}, [publicKey, props.skill, origin, inputsKey, props.autoHeight]);
|
|
79
|
+
(0, import_react.useImperativeHandle)(ref, () => ({
|
|
80
|
+
open: () => {
|
|
81
|
+
var _a2;
|
|
82
|
+
return (_a2 = handle.current) == null ? void 0 : _a2.open();
|
|
83
|
+
},
|
|
84
|
+
close: () => {
|
|
85
|
+
var _a2;
|
|
86
|
+
return (_a2 = handle.current) == null ? void 0 : _a2.close();
|
|
87
|
+
}
|
|
88
|
+
}), []);
|
|
89
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { ref: el, className: props.className, style: props.style, "data-skillyo-skill": props.skill });
|
|
90
|
+
});
|
|
91
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
92
|
+
0 && (module.exports = {
|
|
93
|
+
SkillyoProvider,
|
|
94
|
+
SkillyoSkill
|
|
95
|
+
});
|
package/dist/react.d.cts
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import * as react from 'react';
|
|
2
|
+
import { ReactNode, CSSProperties } from 'react';
|
|
3
|
+
import { InputValue, RunStatus, ErrorCode } from '@skillyo/embed';
|
|
4
|
+
export { ErrorCode, InputValue, RunStatus } from '@skillyo/embed';
|
|
5
|
+
|
|
6
|
+
/** Set the website key once for every SkillyoSkill inside it. */
|
|
7
|
+
declare function SkillyoProvider({ publicKey, origin, children }: {
|
|
8
|
+
publicKey: string;
|
|
9
|
+
origin?: string;
|
|
10
|
+
children?: ReactNode;
|
|
11
|
+
}): react.JSX.Element;
|
|
12
|
+
interface SkillyoSkillProps {
|
|
13
|
+
/** The website key, `sko_pub_…`. Optional inside a SkillyoProvider. */
|
|
14
|
+
publicKey?: string;
|
|
15
|
+
/** The skill's name as it appears in its address. */
|
|
16
|
+
skill: string;
|
|
17
|
+
/** Fields to fill in, by input id. Visible and editable by the visitor. */
|
|
18
|
+
inputs?: Record<string, InputValue>;
|
|
19
|
+
/** "In the page" grows to fit its content. Default true. */
|
|
20
|
+
autoHeight?: boolean;
|
|
21
|
+
/** Where Skillyo is. For testing only. */
|
|
22
|
+
origin?: string;
|
|
23
|
+
className?: string;
|
|
24
|
+
style?: CSSProperties;
|
|
25
|
+
onReady?: () => void;
|
|
26
|
+
onRunStarted?: () => void;
|
|
27
|
+
onRunComplete?: (run: {
|
|
28
|
+
runId: string | null;
|
|
29
|
+
status: RunStatus;
|
|
30
|
+
}) => void;
|
|
31
|
+
onError?: (error: {
|
|
32
|
+
code: ErrorCode;
|
|
33
|
+
}) => void;
|
|
34
|
+
onResize?: (size: {
|
|
35
|
+
height: number;
|
|
36
|
+
}) => void;
|
|
37
|
+
}
|
|
38
|
+
/** For the button, slide-over and floating styles: open it from your own button. */
|
|
39
|
+
interface SkillyoSkillHandle {
|
|
40
|
+
open(): void;
|
|
41
|
+
close(): void;
|
|
42
|
+
}
|
|
43
|
+
declare const SkillyoSkill: react.ForwardRefExoticComponent<SkillyoSkillProps & react.RefAttributes<SkillyoSkillHandle>>;
|
|
44
|
+
|
|
45
|
+
export { SkillyoProvider, SkillyoSkill, type SkillyoSkillHandle, type SkillyoSkillProps };
|
package/dist/react.d.ts
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import * as react from 'react';
|
|
2
|
+
import { ReactNode, CSSProperties } from 'react';
|
|
3
|
+
import { InputValue, RunStatus, ErrorCode } from '@skillyo/embed';
|
|
4
|
+
export { ErrorCode, InputValue, RunStatus } from '@skillyo/embed';
|
|
5
|
+
|
|
6
|
+
/** Set the website key once for every SkillyoSkill inside it. */
|
|
7
|
+
declare function SkillyoProvider({ publicKey, origin, children }: {
|
|
8
|
+
publicKey: string;
|
|
9
|
+
origin?: string;
|
|
10
|
+
children?: ReactNode;
|
|
11
|
+
}): react.JSX.Element;
|
|
12
|
+
interface SkillyoSkillProps {
|
|
13
|
+
/** The website key, `sko_pub_…`. Optional inside a SkillyoProvider. */
|
|
14
|
+
publicKey?: string;
|
|
15
|
+
/** The skill's name as it appears in its address. */
|
|
16
|
+
skill: string;
|
|
17
|
+
/** Fields to fill in, by input id. Visible and editable by the visitor. */
|
|
18
|
+
inputs?: Record<string, InputValue>;
|
|
19
|
+
/** "In the page" grows to fit its content. Default true. */
|
|
20
|
+
autoHeight?: boolean;
|
|
21
|
+
/** Where Skillyo is. For testing only. */
|
|
22
|
+
origin?: string;
|
|
23
|
+
className?: string;
|
|
24
|
+
style?: CSSProperties;
|
|
25
|
+
onReady?: () => void;
|
|
26
|
+
onRunStarted?: () => void;
|
|
27
|
+
onRunComplete?: (run: {
|
|
28
|
+
runId: string | null;
|
|
29
|
+
status: RunStatus;
|
|
30
|
+
}) => void;
|
|
31
|
+
onError?: (error: {
|
|
32
|
+
code: ErrorCode;
|
|
33
|
+
}) => void;
|
|
34
|
+
onResize?: (size: {
|
|
35
|
+
height: number;
|
|
36
|
+
}) => void;
|
|
37
|
+
}
|
|
38
|
+
/** For the button, slide-over and floating styles: open it from your own button. */
|
|
39
|
+
interface SkillyoSkillHandle {
|
|
40
|
+
open(): void;
|
|
41
|
+
close(): void;
|
|
42
|
+
}
|
|
43
|
+
declare const SkillyoSkill: react.ForwardRefExoticComponent<SkillyoSkillProps & react.RefAttributes<SkillyoSkillHandle>>;
|
|
44
|
+
|
|
45
|
+
export { SkillyoProvider, SkillyoSkill, type SkillyoSkillHandle, type SkillyoSkillProps };
|
package/dist/react.js
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
// src/react.tsx
|
|
4
|
+
import { createContext, forwardRef, useContext, useEffect, useImperativeHandle, useRef } from "react";
|
|
5
|
+
import { mount } from "@skillyo/embed";
|
|
6
|
+
import { jsx } from "react/jsx-runtime";
|
|
7
|
+
var SkillyoContext = createContext({});
|
|
8
|
+
function SkillyoProvider({ publicKey, origin, children }) {
|
|
9
|
+
return /* @__PURE__ */ jsx(SkillyoContext.Provider, { value: { publicKey, origin }, children });
|
|
10
|
+
}
|
|
11
|
+
var SkillyoSkill = forwardRef(function SkillyoSkill2(props, ref) {
|
|
12
|
+
var _a, _b, _c;
|
|
13
|
+
const fromProvider = useContext(SkillyoContext);
|
|
14
|
+
const publicKey = (_a = props.publicKey) != null ? _a : fromProvider.publicKey;
|
|
15
|
+
const origin = (_b = props.origin) != null ? _b : fromProvider.origin;
|
|
16
|
+
const el = useRef(null);
|
|
17
|
+
const handle = useRef(null);
|
|
18
|
+
const latest = useRef(props);
|
|
19
|
+
latest.current = props;
|
|
20
|
+
const inputsKey = JSON.stringify((_c = props.inputs) != null ? _c : null);
|
|
21
|
+
useEffect(() => {
|
|
22
|
+
const node = el.current;
|
|
23
|
+
if (!node) return;
|
|
24
|
+
if (!publicKey) {
|
|
25
|
+
console.warn("[skillyo] SkillyoSkill needs a publicKey, or a SkillyoProvider around it");
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
const h = mount(node, { publicKey, skill: props.skill, inputs: props.inputs, autoHeight: props.autoHeight, origin });
|
|
29
|
+
handle.current = h;
|
|
30
|
+
h.on("ready", () => {
|
|
31
|
+
var _a2, _b2;
|
|
32
|
+
return (_b2 = (_a2 = latest.current).onReady) == null ? void 0 : _b2.call(_a2);
|
|
33
|
+
});
|
|
34
|
+
h.on("run:started", () => {
|
|
35
|
+
var _a2, _b2;
|
|
36
|
+
return (_b2 = (_a2 = latest.current).onRunStarted) == null ? void 0 : _b2.call(_a2);
|
|
37
|
+
});
|
|
38
|
+
h.on("run:completed", (e) => {
|
|
39
|
+
var _a2, _b2;
|
|
40
|
+
return (_b2 = (_a2 = latest.current).onRunComplete) == null ? void 0 : _b2.call(_a2, e);
|
|
41
|
+
});
|
|
42
|
+
h.on("error", (e) => {
|
|
43
|
+
var _a2, _b2;
|
|
44
|
+
return (_b2 = (_a2 = latest.current).onError) == null ? void 0 : _b2.call(_a2, e);
|
|
45
|
+
});
|
|
46
|
+
h.on("resize", (e) => {
|
|
47
|
+
var _a2, _b2;
|
|
48
|
+
return (_b2 = (_a2 = latest.current).onResize) == null ? void 0 : _b2.call(_a2, e);
|
|
49
|
+
});
|
|
50
|
+
return () => {
|
|
51
|
+
h.destroy();
|
|
52
|
+
if (handle.current === h) handle.current = null;
|
|
53
|
+
};
|
|
54
|
+
}, [publicKey, props.skill, origin, inputsKey, props.autoHeight]);
|
|
55
|
+
useImperativeHandle(ref, () => ({
|
|
56
|
+
open: () => {
|
|
57
|
+
var _a2;
|
|
58
|
+
return (_a2 = handle.current) == null ? void 0 : _a2.open();
|
|
59
|
+
},
|
|
60
|
+
close: () => {
|
|
61
|
+
var _a2;
|
|
62
|
+
return (_a2 = handle.current) == null ? void 0 : _a2.close();
|
|
63
|
+
}
|
|
64
|
+
}), []);
|
|
65
|
+
return /* @__PURE__ */ jsx("div", { ref: el, className: props.className, style: props.style, "data-skillyo-skill": props.skill });
|
|
66
|
+
});
|
|
67
|
+
export {
|
|
68
|
+
SkillyoProvider,
|
|
69
|
+
SkillyoSkill
|
|
70
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@skillyo/embed",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Put a Skillyo skill in your web app: a React component, or mount() for any framework.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"author": "Skillyo",
|
|
7
|
+
"homepage": "https://skillyo.ai",
|
|
8
|
+
"keywords": [
|
|
9
|
+
"skillyo",
|
|
10
|
+
"embed",
|
|
11
|
+
"skill",
|
|
12
|
+
"ai",
|
|
13
|
+
"react",
|
|
14
|
+
"nextjs",
|
|
15
|
+
"widget"
|
|
16
|
+
],
|
|
17
|
+
"type": "module",
|
|
18
|
+
"main": "./dist/index.cjs",
|
|
19
|
+
"module": "./dist/index.js",
|
|
20
|
+
"types": "./dist/index.d.ts",
|
|
21
|
+
"typesVersions": {
|
|
22
|
+
"*": {
|
|
23
|
+
"react": [
|
|
24
|
+
"./dist/react.d.ts"
|
|
25
|
+
]
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
"exports": {
|
|
29
|
+
".": {
|
|
30
|
+
"import": {
|
|
31
|
+
"types": "./dist/index.d.ts",
|
|
32
|
+
"default": "./dist/index.js"
|
|
33
|
+
},
|
|
34
|
+
"require": {
|
|
35
|
+
"types": "./dist/index.d.cts",
|
|
36
|
+
"default": "./dist/index.cjs"
|
|
37
|
+
}
|
|
38
|
+
},
|
|
39
|
+
"./react": {
|
|
40
|
+
"import": {
|
|
41
|
+
"types": "./dist/react.d.ts",
|
|
42
|
+
"default": "./dist/react.js"
|
|
43
|
+
},
|
|
44
|
+
"require": {
|
|
45
|
+
"types": "./dist/react.d.cts",
|
|
46
|
+
"default": "./dist/react.cjs"
|
|
47
|
+
}
|
|
48
|
+
},
|
|
49
|
+
"./package.json": "./package.json"
|
|
50
|
+
},
|
|
51
|
+
"files": [
|
|
52
|
+
"dist",
|
|
53
|
+
"README.md",
|
|
54
|
+
"LICENSE",
|
|
55
|
+
"CHANGELOG.md"
|
|
56
|
+
],
|
|
57
|
+
"sideEffects": false,
|
|
58
|
+
"peerDependencies": {
|
|
59
|
+
"react": ">=18"
|
|
60
|
+
},
|
|
61
|
+
"peerDependenciesMeta": {
|
|
62
|
+
"react": {
|
|
63
|
+
"optional": true
|
|
64
|
+
}
|
|
65
|
+
},
|
|
66
|
+
"devDependencies": {
|
|
67
|
+
"@testing-library/dom": "^10.4.2",
|
|
68
|
+
"@testing-library/react": "^16.3.2",
|
|
69
|
+
"@types/react": "^18.3.18",
|
|
70
|
+
"@types/react-dom": "^18.3.5",
|
|
71
|
+
"jsdom": "^29.1.1",
|
|
72
|
+
"react": "^18.3.1",
|
|
73
|
+
"react-dom": "^18.3.1",
|
|
74
|
+
"tsup": "^8.5.1",
|
|
75
|
+
"typescript": "^5.7.3",
|
|
76
|
+
"vitest": "^4.1.4"
|
|
77
|
+
},
|
|
78
|
+
"scripts": {
|
|
79
|
+
"build": "tsup",
|
|
80
|
+
"test": "vitest run",
|
|
81
|
+
"typecheck": "tsc --noEmit",
|
|
82
|
+
"prepublishOnly": "npm run typecheck && npm test && npm run build"
|
|
83
|
+
},
|
|
84
|
+
"publishConfig": {
|
|
85
|
+
"access": "public"
|
|
86
|
+
}
|
|
87
|
+
}
|