-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
158 additions
and
12 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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@statelyai/inspect': patch | ||
--- | ||
|
||
Adds `createSkyInspector`, which allows you to inspect machines in Node or the browser. The inspection will send the events to a server backend through websockets and allows you to open and share a live inspection URL. |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,21 @@ | ||
#!/bin/bash | ||
|
||
# This script copies the source code of the packages in the packages/ directory | ||
# to the node_modules/@statelyai/ directory of each destination project. | ||
|
||
# Load environment variables from .env file | ||
if [ -f .env ]; then | ||
export $(cat .env | xargs) | ||
fi | ||
|
||
# Split the DEV_DESTINATIONS variable into an array | ||
IFS=',' read -r -a destinations <<<"$DEV_DESTINATIONS" | ||
|
||
# Package name | ||
package="inspect" | ||
|
||
for destination in "${destinations[@]}"; do | ||
echo "Copying ${package} to ${destination}" | ||
rm -rf "${destination}/node_modules/@statelyai/${package}" | ||
cp -r "./" "${destination}/node_modules/@statelyai/${package}" | ||
done |
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,58 @@ | ||
import PartySocket from 'partysocket'; | ||
import { stringify } from 'superjson'; | ||
import { v4 as uuidv4 } from 'uuid'; | ||
import { createBrowserInspector } from './browser'; | ||
import { | ||
InspectorOptions, | ||
createInspector as inspectCreator, | ||
} from './createInspector'; | ||
import { isNode } from './utils'; | ||
|
||
export function createSkyInspector( | ||
options: { | ||
apiKey?: string; // Not used yet, will be used to add additional premium features later | ||
onerror?: (error: Error) => void; | ||
} & InspectorOptions = {} | ||
): ReturnType<typeof inspectCreator> { | ||
const { host, apiBaseURL } = { | ||
host: 'localhost:1999', // 'stately-sky-beta.mellson.partykit.dev' | ||
apiBaseURL: 'http://localhost:3000/registry/api/sky', // 'https://stately.ai/registry/api/sky', | ||
}; | ||
const server = apiBaseURL.replace('/api/sky', ''); | ||
const { apiKey, onerror, ...inspectorOptions } = options; | ||
const sessionId = uuidv4(); // Generate a unique session ID | ||
const room = `inspect-${sessionId}`; | ||
const socket = new PartySocket({ | ||
host, | ||
room, | ||
WebSocket: isNode ? require('isomorphic-ws') : undefined, | ||
}); | ||
const liveInspectUrl = `${server}/inspect/${sessionId}`; | ||
socket.onerror = onerror ?? console.error; | ||
socket.onopen = () => { | ||
console.log('Connected to Sky, link to your live inspect session:'); | ||
console.log(liveInspectUrl); | ||
}; | ||
if (isNode) { | ||
return inspectCreator({ | ||
...inspectorOptions, | ||
send(event) { | ||
const skyEvent = apiKey ? { apiKey, ...event } : event; | ||
socket.send(stringify(skyEvent)); | ||
}, | ||
}); | ||
} else { | ||
const { filter, serialize } = inspectorOptions; | ||
return createBrowserInspector({ | ||
...inspectorOptions, | ||
url: liveInspectUrl, | ||
serialize(event) { | ||
if (!filter || filter(event)) { | ||
const skyEvent = apiKey ? { apiKey, ...event } : event; | ||
socket.send(stringify(skyEvent)); | ||
} | ||
return serialize ? serialize(event) : event; | ||
}, | ||
}); | ||
} | ||
} |
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,9 +1,10 @@ | ||
export { createInspector } from './createInspector'; | ||
export { createWebSocketInspector, createWebSocketReceiver } from './webSocket'; | ||
export { createBrowserInspector, createBrowserReceiver } from './browser'; | ||
export { createInspector } from './createInspector'; | ||
export { createSkyInspector } from './createSkyInspector'; | ||
export type { | ||
StatelyActorEvent, | ||
StatelyInspectionEvent, | ||
StatelyEventEvent, | ||
StatelyInspectionEvent, | ||
StatelySnapshotEvent, | ||
} from './types'; | ||
export { createWebSocketInspector, createWebSocketReceiver } from './webSocket'; |
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