-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add server api for apps + Add external hooks for apps #101
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
87cc884
add server api for apps
VictorS67 abc9e20
add hooks used in encre-apps
VictorS67 5df0943
add debugger logging
VictorS67 6834cae
add entrypoint
VictorS67 b87965f
add dependencies for hooks
VictorS67 bca2b2c
add tests
VictorS67 7390d70
Merge branch 'master' of https://github.com/VictorS67/encre into app-…
VictorS67 51fd0f3
add abort signal to onOutput hook
VictorS67 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,4 @@ | ||
{ | ||
"presets": [["@babel/env"], "@babel/react", "@babel/preset-typescript"], | ||
"plugins": ["@babel/plugin-transform-runtime"] | ||
} |
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,106 @@ | ||
{ | ||
"env": { | ||
"browser": true, | ||
"es2021": true, | ||
"node": true | ||
}, | ||
"extends": [ | ||
"eslint:recommended", | ||
"plugin:@typescript-eslint/recommended", | ||
"plugin:react/recommended", | ||
"plugin:prettier/recommended", | ||
"prettier" | ||
], | ||
"parser": "@typescript-eslint/parser", | ||
"parserOptions": { | ||
"ecmaVersion": "latest", | ||
"sourceType": "module", | ||
"ecmaFeatures": { | ||
"jsx": true | ||
}, | ||
"project": "../../tsconfig.json" | ||
}, | ||
"plugins": ["prettier", "react", "import", "@atlaskit/design-system"], | ||
"rules": { | ||
// e.g. "@typescript-eslint/explicit-function-return-type": "off", | ||
// "@atlaskit/design-system/ensure-design-token-usage": "warn", | ||
"@atlaskit/design-system/no-deprecated-design-token-usage": "warn", | ||
"@atlaskit/design-system/no-unsafe-design-token-usage": "error", | ||
"@atlaskit/design-system/use-visually-hidden": "error", | ||
"@atlaskit/design-system/no-deprecated-imports": "error", | ||
"@atlaskit/design-system/no-deprecated-apis": "error", | ||
"react/no-unknown-property": ["error", { "ignore": ["css"] }], | ||
"linebreak-style": "off", | ||
"prettier/prettier": [ | ||
"error", | ||
{ "singleQuote": true, "endOfLine": "auto" } | ||
], | ||
"semi": ["error", "always"], | ||
"object-curly-spacing": ["error", "always"], | ||
"camelcase": "off", | ||
"@typescript-eslint/explicit-function-return-type": "off", | ||
"@typescript-eslint/no-explicit-any": ["off"], | ||
"@typescript-eslint/no-inferrable-types": [ | ||
"warn", | ||
{ | ||
"ignoreParameters": true | ||
} | ||
], | ||
"no-underscore-dangle": "off", | ||
"no-shadow": "off", | ||
"no-new": 0, | ||
"@typescript-eslint/no-shadow": ["error"], | ||
"@typescript-eslint/no-unused-vars": "warn", | ||
"no-restricted-imports": "off", | ||
"@typescript-eslint/no-restricted-imports": [ | ||
"warn", | ||
{ | ||
"name": "react-redux", | ||
"importNames": ["useSelector", "useDispatch"], | ||
"message": "Use typed hooks `useAppDispatch` and `useAppSelector` instead." | ||
} | ||
], | ||
"quotes": [2, "single", { "avoidEscape": true }], | ||
"class-methods-use-this": "off", | ||
"import/order": [ | ||
"error", | ||
{ | ||
"groups": ["builtin", "external", "parent", "sibling", "index"], | ||
"pathGroups": [ | ||
{ | ||
"pattern": "react?(-*)", | ||
"group": "builtin", | ||
"position": "before" | ||
}, | ||
{ | ||
"group": "external", | ||
"pattern": "internal/**/*", | ||
"position": "after" | ||
} | ||
], | ||
"pathGroupsExcludedImportTypes": ["react"], | ||
"newlines-between": "always", | ||
"alphabetize": { | ||
"order": "asc", | ||
"caseInsensitive": true | ||
} | ||
} | ||
], | ||
"import/extensions": [ | ||
"error", | ||
"ignorePackages", | ||
{ | ||
"": "never", | ||
"js": "never", | ||
"jsx": "never", | ||
"ts": "never", | ||
"tsx": "never" | ||
} | ||
] | ||
}, | ||
"settings": { | ||
"react": { | ||
"version": "detect" | ||
} | ||
} | ||
} |
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,9 @@ | ||
node_modules | ||
|
||
build | ||
es | ||
lib | ||
dist | ||
|
||
.DS_Store | ||
.env |
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,9 @@ | ||
{ | ||
"git": { | ||
"requireCleanWorkingDir": false, | ||
"tag": false | ||
}, | ||
"npm": { | ||
"versionArgs": ["--workspaces-update=false"] | ||
} | ||
} |
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,49 @@ | ||
const gulp = require("gulp"); | ||
const babel = require("gulp-babel"); | ||
const ts = require("gulp-typescript"); | ||
const sourcemaps = require("gulp-sourcemaps"); | ||
const del = require("del"); | ||
|
||
gulp.task("clean", async function () { | ||
await del("lib/**"); | ||
await del("es/**"); | ||
await del("dist/**"); | ||
}); | ||
|
||
gulp.task("cjs", function () { | ||
return gulp | ||
.src(["./es/**/*.js"]) | ||
.pipe( | ||
babel({ | ||
configFile: "./.babelrc", | ||
}) | ||
) | ||
.pipe(gulp.dest("lib/")); | ||
}); | ||
|
||
gulp.task("es", function () { | ||
const tsProject = ts.createProject("tsconfig.pro.json", { | ||
module: "ESNext", | ||
}); | ||
return tsProject | ||
.src() | ||
.pipe(sourcemaps.init()) | ||
.pipe(tsProject()) | ||
.pipe(babel()) | ||
.pipe(sourcemaps.write(".")) | ||
.pipe(gulp.dest("es/")); | ||
}); | ||
|
||
gulp.task("declaration", function () { | ||
const tsProject = ts.createProject("tsconfig.pro.json", { | ||
declaration: true, | ||
emitDeclarationOnly: true, | ||
}); | ||
return tsProject | ||
.src() | ||
.pipe(tsProject()) | ||
.pipe(gulp.dest("es/")) | ||
.pipe(gulp.dest("lib/")); | ||
}); | ||
|
||
exports.default = gulp.series("clean", "es", "cjs", "declaration"); |
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,85 @@ | ||
{ | ||
"name": "@encrejs/hooks", | ||
"version": "0.0.0", | ||
"engines": { | ||
"node": ">=20.0.0" | ||
}, | ||
"author": "Encre", | ||
"license": "MIT", | ||
"files": [ | ||
"dist", | ||
"lib", | ||
"es", | ||
"package.json" | ||
], | ||
"main": "./lib/index.js", | ||
"module": "./es/index.js", | ||
"types": "./lib/index.d.ts", | ||
"unpkg": "dist/hooks.js", | ||
"sideEffects": false, | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/VictorS67/encre.git", | ||
"directory": "packages/ui" | ||
}, | ||
"publishConfig": { | ||
"access": "public", | ||
"registry": "https://registry.npmjs.org" | ||
}, | ||
"packageManager": "[email protected]", | ||
"devDependencies": { | ||
"@babel/cli": "^7.10.1", | ||
"@babel/core": "^7.25.2", | ||
"@babel/plugin-transform-runtime": "^7.25.4", | ||
"@babel/preset-typescript": "^7.24.7", | ||
"@testing-library/jest-dom": "^5.16.5", | ||
"@testing-library/react": "^13.4.0", | ||
"@types/gulp": "^4.0.17", | ||
"@types/gulp-babel": "^6.1.33", | ||
"@types/jest": "^29.5.4", | ||
"@types/react": "^18.2.21", | ||
"@types/react-dom": "^18.2.7", | ||
"@typescript-eslint/eslint-plugin": "^6.7.0", | ||
"@typescript-eslint/parser": "^6.7.0", | ||
"babel-loader": "^9.1.3", | ||
"babel-plugin-import": "^1.12.0", | ||
"cross-env": "^7.0.3", | ||
"del": "^5.1.0", | ||
"eslint": "^8.49.0", | ||
"eslint-cjs-to-esm": "^2.2.0", | ||
"eslint-config-prettier": "^9.0.0", | ||
"eslint-config-standard-with-typescript": "^39.0.0", | ||
"eslint-import-resolver-typescript": "^3.6.0", | ||
"eslint-plugin-import": "^2.28.1", | ||
"eslint-plugin-n": "^16.1.0", | ||
"eslint-plugin-prettier": "^5.0.0", | ||
"eslint-plugin-promise": "^6.1.1", | ||
"gulp": "^5.0.0", | ||
"gulp-babel": "^8.0.0", | ||
"gulp-sourcemaps": "^3.0.0", | ||
"gulp-typescript": "^6.0.0-alpha.1", | ||
"jest": "^29.4.1", | ||
"prettier": "^3.0.3", | ||
"react": "^18.2.0", | ||
"react-dom": "^18.2.0", | ||
"typescript": "^5.2.2", | ||
"webpack": "^5.90.0", | ||
"webpack-cli": "^5.1.4" | ||
}, | ||
"dependencies": { | ||
"eventsource-parser": "1.0.0", | ||
"lodash-es": "^4.17.21", | ||
"lru-cache": "^11.0.0", | ||
"webpack-cli": "^5.1.4" | ||
}, | ||
"peerDependencies": { | ||
"react": "^16.8.0 || ^17.0.0 || ^18.0.0" | ||
}, | ||
"scripts": { | ||
"clean": "rimraf '{lib,es,dist}'", | ||
"build": "gulp && webpack-cli", | ||
"lint": "eslint src/*.ts src/**/*.ts", | ||
"lint-fix": "eslint --fix src/*.ts src/**/*.ts", | ||
"test": "cross-env NODE_ENV=test jest" | ||
} | ||
} |
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,45 @@ | ||
import { LRUCache } from 'lru-cache'; | ||
|
||
import { EncreData } from './types'; | ||
|
||
export interface EncreCache { | ||
get: ( | ||
graphId: string, | ||
nodeId: string, | ||
) => [string, Record<string, EncreData>] | undefined; | ||
|
||
has: (graphId: string, nodeId: string) => boolean; | ||
|
||
set: ( | ||
graphId: string, | ||
nodeId: string, | ||
data: [string, Record<string, EncreData>] | undefined, | ||
) => void; | ||
} | ||
|
||
export const encreCache = (): EncreCache => { | ||
const ref = new LRUCache<string, [string, Record<string, EncreData>]>({ | ||
maxSize: 500, | ||
sizeCalculation: (value) => { | ||
return JSON.stringify(value).length; | ||
}, | ||
}); | ||
|
||
const set = ( | ||
graphId: string, | ||
nodeId: string, | ||
data: [string, Record<string, EncreData>] | undefined, | ||
) => { | ||
ref.set(`${graphId}-${nodeId}`, data); | ||
}; | ||
|
||
const get = (graphId: string, nodeId: string) => { | ||
return ref.get(`${graphId}-${nodeId}`); | ||
}; | ||
|
||
const has = (graphId: string, nodeId: string) => { | ||
return ref.has(`${graphId}-${nodeId}`); | ||
}; | ||
|
||
return { set, get, has } satisfies EncreCache; | ||
}; |
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,2 @@ | ||
export * from './types'; | ||
export { useAppHandler } from './useAppHandler'; |
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,9 @@ | ||
import * as hooks from '..'; | ||
|
||
describe('hooks', () => { | ||
test('exports modules should be defined', () => { | ||
Object.keys(hooks).forEach((module) => { | ||
expect(hooks[module]).toBeDefined(); | ||
}); | ||
}); | ||
}); |
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,6 @@ | ||
import { EncreAppHander } from './handlers'; | ||
|
||
export interface EncreAppConfig { | ||
workflow: string; | ||
handlers: Record<string, EncreAppHander>; | ||
} |
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 @@ | ||
export interface Context { | ||
pageContent: string; | ||
metadata?: Record<string, unknown>; | ||
} |
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,11 @@ | ||
export type EncreData = { | ||
type: | ||
| 'string' | ||
| 'number' | ||
| 'boolean' | ||
| 'context' | ||
| 'chat-message' | ||
| 'object' | ||
| 'unknown'; | ||
value: unknown; | ||
}; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is this interface for specifically, I understand that it is storing a graph and a node, but just want to make sure I understand the software, what part fo the process does EncreCache speeds up specifically?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good Question!
EncreCache
is used for storing incoming data from input handlers. You can image a scenario where there is a message box that connects to an input handler, so whenever user change the message, the input handler should store that changed value. But this changed value is not sent to the workflow immediately, since no action is triggered by the uset. So we need a cache to store this value.