@dxos/plugin-automation 0.7.1-staging.8709ba7 → 0.7.2-staging.6d26b2a
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/dist/lib/browser/index.mjs +436 -993
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node/index.cjs +425 -965
- package/dist/lib/node/index.cjs.map +4 -4
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node-esm/index.mjs +436 -993
- package/dist/lib/node-esm/index.mjs.map +4 -4
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/types/src/components/TriggerEditor/TriggerEditor.d.ts +1 -1
- package/dist/types/src/components/TriggerEditor/TriggerEditor.d.ts.map +1 -1
- package/dist/types/src/components/TriggerEditor/TriggerEditor.stories.d.ts +1 -1
- package/dist/types/src/components/TriggerEditor/TriggerEditor.stories.d.ts.map +1 -1
- package/dist/types/src/components/index.d.ts +0 -2
- package/dist/types/src/components/index.d.ts.map +1 -1
- package/dist/types/src/hooks/invocation-handler.d.ts.map +1 -1
- package/dist/types/src/hooks/useLocalTriggerManager.d.ts.map +1 -1
- package/dist/types/src/translations.d.ts +1 -1
- package/package.json +34 -34
- package/src/AutomationPlugin.tsx +3 -3
- package/src/components/TriggerEditor/TriggerEditor.stories.tsx +40 -22
- package/src/components/TriggerEditor/TriggerEditor.tsx +71 -322
- package/src/components/index.ts +0 -5
- package/src/hooks/invocation-handler.ts +6 -9
- package/src/hooks/useLocalTriggerManager.ts +2 -4
- package/src/translations.ts +1 -1
- package/dist/lib/browser/PromptContainer-6CBNCUKQ.mjs +0 -19
- package/dist/lib/browser/PromptContainer-6CBNCUKQ.mjs.map +0 -7
- package/dist/lib/browser/chunk-CJMV64XO.mjs +0 -217
- package/dist/lib/browser/chunk-CJMV64XO.mjs.map +0 -7
- package/dist/lib/node/PromptContainer-7RCGCU3K.cjs +0 -45
- package/dist/lib/node/PromptContainer-7RCGCU3K.cjs.map +0 -7
- package/dist/lib/node/chunk-YGRHTCOX.cjs +0 -240
- package/dist/lib/node/chunk-YGRHTCOX.cjs.map +0 -7
- package/dist/lib/node-esm/PromptContainer-4SCHQV5C.mjs +0 -20
- package/dist/lib/node-esm/PromptContainer-4SCHQV5C.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-62AB5HXX.mjs +0 -218
- package/dist/lib/node-esm/chunk-62AB5HXX.mjs.map +0 -7
- package/dist/types/src/components/Chain.d.ts +0 -12
- package/dist/types/src/components/Chain.d.ts.map +0 -1
- package/dist/types/src/components/PromptContainer.d.ts +0 -6
- package/dist/types/src/components/PromptContainer.d.ts.map +0 -1
- package/dist/types/src/components/TriggerEditor/Form.d.ts +0 -5
- package/dist/types/src/components/TriggerEditor/Form.d.ts.map +0 -1
- package/dist/types/src/components/TriggerEditor/meta.d.ts +0 -25
- package/dist/types/src/components/TriggerEditor/meta.d.ts.map +0 -1
- package/src/components/Chain.tsx +0 -66
- package/src/components/PromptContainer.tsx +0 -19
- package/src/components/TriggerEditor/Form.tsx +0 -18
- package/src/components/TriggerEditor/meta.tsx +0 -226
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
//
|
|
4
4
|
|
|
5
5
|
import { sleep } from '@dxos/async';
|
|
6
|
-
import { getObjectCore } from '@dxos/echo-db';
|
|
7
|
-
import {
|
|
6
|
+
import { getObjectCore, ResultFormat } from '@dxos/echo-db';
|
|
7
|
+
import type { AnyObjectData } from '@dxos/echo-schema';
|
|
8
8
|
import { type FunctionTrigger } from '@dxos/functions';
|
|
9
9
|
import { invariant } from '@dxos/invariant';
|
|
10
10
|
import { DXN, LOCAL_SPACE_TAG } from '@dxos/keys';
|
|
@@ -13,8 +13,6 @@ import { FunctionType } from '@dxos/plugin-script';
|
|
|
13
13
|
import { type Client, type Config } from '@dxos/react-client';
|
|
14
14
|
import { type Space } from '@dxos/react-client/echo';
|
|
15
15
|
|
|
16
|
-
import { handleEmail } from './email';
|
|
17
|
-
|
|
18
16
|
const MAX_RETRIES = 3;
|
|
19
17
|
const RETRY_DELAY = 1_000;
|
|
20
18
|
|
|
@@ -49,12 +47,11 @@ export const invokeFunction = async (client: Client, space: Space, trigger: Func
|
|
|
49
47
|
try {
|
|
50
48
|
invariant(trigger.spec);
|
|
51
49
|
invariant(trigger.function);
|
|
52
|
-
if (trigger.spec.type === 'websocket') {
|
|
53
|
-
return handleEmail(space, data.data);
|
|
54
|
-
}
|
|
55
50
|
|
|
56
|
-
const script = await space.
|
|
57
|
-
const { objects: functions } = await space.
|
|
51
|
+
const script = await space.db.query({ id: trigger.function }, { format: ResultFormat.Plain }).first();
|
|
52
|
+
const { objects: functions } = await space.db
|
|
53
|
+
.query({ __typename: FunctionType.typename }, { format: ResultFormat.Plain })
|
|
54
|
+
.run();
|
|
58
55
|
const func = functions.find((fn) => referenceEquals(fn.source, trigger.function!)) as AnyObjectData | undefined;
|
|
59
56
|
const funcSlug = func?.__meta.keys.find((key) => key.source === USERFUNCTIONS_META_KEY)?.id;
|
|
60
57
|
if (!funcSlug) {
|
|
@@ -6,8 +6,8 @@ import { useEffect, useState } from 'react';
|
|
|
6
6
|
|
|
7
7
|
import { Mutex } from '@dxos/async';
|
|
8
8
|
import { Context } from '@dxos/context';
|
|
9
|
-
import { createSubscriptionTrigger,
|
|
10
|
-
import { FunctionTrigger } from '@dxos/functions
|
|
9
|
+
import { createSubscriptionTrigger, type TriggerFactory } from '@dxos/functions';
|
|
10
|
+
import { FunctionTrigger } from '@dxos/functions';
|
|
11
11
|
import { invariant } from '@dxos/invariant';
|
|
12
12
|
import { log } from '@dxos/log';
|
|
13
13
|
import { useClient } from '@dxos/react-client';
|
|
@@ -50,8 +50,6 @@ export const useLocalTriggerManager = (space: Space) => {
|
|
|
50
50
|
let triggerFactory: TriggerFactory<any>;
|
|
51
51
|
if (triggerSpec.type === 'subscription') {
|
|
52
52
|
triggerFactory = createSubscriptionTrigger;
|
|
53
|
-
} else if (triggerSpec.type === 'websocket') {
|
|
54
|
-
triggerFactory = createWebsocketTrigger;
|
|
55
53
|
} else {
|
|
56
54
|
log.info('unsupported trigger', { type: triggerSpec.type });
|
|
57
55
|
continue;
|
package/src/translations.ts
CHANGED
|
@@ -25,10 +25,10 @@ export default [
|
|
|
25
25
|
'trigger select label': 'Trigger',
|
|
26
26
|
'trigger select placeholder': 'Trigger type',
|
|
27
27
|
|
|
28
|
-
'trigger type subscription': 'Subscription',
|
|
29
28
|
'trigger type timer': 'Timer',
|
|
30
29
|
'trigger type webhook': 'Webhook',
|
|
31
30
|
'trigger type websocket': 'Websocket',
|
|
31
|
+
'trigger type subscription': 'Subscription',
|
|
32
32
|
|
|
33
33
|
'trigger filter': 'Filter',
|
|
34
34
|
'trigger cron': 'Cron',
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
PromptEditor
|
|
3
|
-
} from "./chunk-CJMV64XO.mjs";
|
|
4
|
-
import "./chunk-B3Z4NQC2.mjs";
|
|
5
|
-
import "./chunk-PQLGYMNY.mjs";
|
|
6
|
-
|
|
7
|
-
// packages/plugins/experimental/plugin-automation/src/components/PromptContainer.tsx
|
|
8
|
-
import React from "react";
|
|
9
|
-
var PromptContainer = (props) => {
|
|
10
|
-
return /* @__PURE__ */ React.createElement("div", {
|
|
11
|
-
role: "none",
|
|
12
|
-
className: "row-span-2 pli-2"
|
|
13
|
-
}, /* @__PURE__ */ React.createElement(PromptEditor, props));
|
|
14
|
-
};
|
|
15
|
-
var PromptContainer_default = PromptContainer;
|
|
16
|
-
export {
|
|
17
|
-
PromptContainer_default as default
|
|
18
|
-
};
|
|
19
|
-
//# sourceMappingURL=PromptContainer-6CBNCUKQ.mjs.map
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../../src/components/PromptContainer.tsx"],
|
|
4
|
-
"sourcesContent": ["//\n// Copyright 2024 DXOS.org\n//\n\nimport React from 'react';\n\nimport { PromptEditor, type PromptEditorProps } from './PromptEditor';\n\ntype PromptContainerProps = PromptEditorProps;\n\nconst PromptContainer = (props: PromptContainerProps) => {\n return (\n <div role='none' className='row-span-2 pli-2'>\n <PromptEditor {...props} />\n </div>\n );\n};\n\nexport default PromptContainer;\n"],
|
|
5
|
-
"mappings": ";;;;;;;AAIA,OAAOA,WAAW;AAMlB,IAAMC,kBAAkB,CAACC,UAAAA;AACvB,SACE,sBAAA,cAACC,OAAAA;IAAIC,MAAK;IAAOC,WAAU;KACzB,sBAAA,cAACC,cAAiBJ,KAAAA,CAAAA;AAGxB;AAEA,IAAA,0BAAeD;",
|
|
6
|
-
"names": ["React", "PromptContainer", "props", "div", "role", "className", "PromptEditor"]
|
|
7
|
-
}
|
|
@@ -1,217 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
ChainInputType
|
|
3
|
-
} from "./chunk-B3Z4NQC2.mjs";
|
|
4
|
-
import {
|
|
5
|
-
AUTOMATION_PLUGIN
|
|
6
|
-
} from "./chunk-PQLGYMNY.mjs";
|
|
7
|
-
|
|
8
|
-
// packages/plugins/experimental/plugin-automation/src/components/PromptEditor/PromptEditor.tsx
|
|
9
|
-
import React, { useEffect } from "react";
|
|
10
|
-
import { createDocAccessor } from "@dxos/react-client/echo";
|
|
11
|
-
import { Input, Select, useThemeContext, useTranslation } from "@dxos/react-ui";
|
|
12
|
-
import { createBasicExtensions, createDataExtensions, createThemeExtensions, useTextEditor } from "@dxos/react-ui-editor";
|
|
13
|
-
import { attentionSurface, groupBorder, mx as mx2 } from "@dxos/react-ui-theme";
|
|
14
|
-
import { nonNullable } from "@dxos/util";
|
|
15
|
-
|
|
16
|
-
// packages/plugins/experimental/plugin-automation/src/components/PromptEditor/prompt-extension.ts
|
|
17
|
-
import { HighlightStyle, StreamLanguage, syntaxHighlighting } from "@codemirror/language";
|
|
18
|
-
import { tags } from "@dxos/react-ui-editor";
|
|
19
|
-
import { mx } from "@dxos/react-ui-theme";
|
|
20
|
-
var nameRegex = /\{([\w-]+)}/;
|
|
21
|
-
var parser = StreamLanguage.define({
|
|
22
|
-
token: (stream) => {
|
|
23
|
-
if (stream.eatSpace()) {
|
|
24
|
-
return null;
|
|
25
|
-
}
|
|
26
|
-
if (stream.match(/^#.*/)) {
|
|
27
|
-
return "lineComment";
|
|
28
|
-
}
|
|
29
|
-
if (stream.match(/^-+$/)) {
|
|
30
|
-
return "lineComment";
|
|
31
|
-
}
|
|
32
|
-
if (stream.match(nameRegex)) {
|
|
33
|
-
return "variableName";
|
|
34
|
-
}
|
|
35
|
-
stream.next();
|
|
36
|
-
return null;
|
|
37
|
-
}
|
|
38
|
-
});
|
|
39
|
-
var highlightStyles = HighlightStyle.define([
|
|
40
|
-
{
|
|
41
|
-
tag: tags.variableName,
|
|
42
|
-
class: mx("rounded border border-yellow-500 bg-yellow-100 text-black font-mono text-sm")
|
|
43
|
-
}
|
|
44
|
-
]);
|
|
45
|
-
var promptExtension = [
|
|
46
|
-
parser,
|
|
47
|
-
syntaxHighlighting(highlightStyles)
|
|
48
|
-
];
|
|
49
|
-
|
|
50
|
-
// packages/plugins/experimental/plugin-automation/src/components/PromptEditor/PromptEditor.tsx
|
|
51
|
-
var inputTypes = [
|
|
52
|
-
{
|
|
53
|
-
value: ChainInputType.VALUE,
|
|
54
|
-
label: "Value"
|
|
55
|
-
},
|
|
56
|
-
{
|
|
57
|
-
value: ChainInputType.PASS_THROUGH,
|
|
58
|
-
label: "Pass through"
|
|
59
|
-
},
|
|
60
|
-
{
|
|
61
|
-
value: ChainInputType.RETRIEVER,
|
|
62
|
-
label: "Retriever"
|
|
63
|
-
},
|
|
64
|
-
// {
|
|
65
|
-
// value: ChainInputType.FUNCTION,
|
|
66
|
-
// label: 'Function',
|
|
67
|
-
// },
|
|
68
|
-
// {
|
|
69
|
-
// value: ChainInputType.QUERY,
|
|
70
|
-
// label: 'Query',
|
|
71
|
-
// },
|
|
72
|
-
{
|
|
73
|
-
value: ChainInputType.RESOLVER,
|
|
74
|
-
label: "Resolver"
|
|
75
|
-
},
|
|
76
|
-
{
|
|
77
|
-
value: ChainInputType.CONTEXT,
|
|
78
|
-
label: "Context"
|
|
79
|
-
},
|
|
80
|
-
{
|
|
81
|
-
value: ChainInputType.SCHEMA,
|
|
82
|
-
label: "Schema"
|
|
83
|
-
}
|
|
84
|
-
];
|
|
85
|
-
var getInputType = (type) => inputTypes.find(({ value }) => String(value) === type)?.value;
|
|
86
|
-
var usePromptInputs = (prompt) => {
|
|
87
|
-
useEffect(() => {
|
|
88
|
-
const text = prompt.template ?? "";
|
|
89
|
-
if (!prompt.inputs) {
|
|
90
|
-
prompt.inputs = [];
|
|
91
|
-
}
|
|
92
|
-
const regex = new RegExp(nameRegex, "g");
|
|
93
|
-
const variables = new Set([
|
|
94
|
-
...text.matchAll(regex)
|
|
95
|
-
].map((m) => m[1]));
|
|
96
|
-
const unclaimed = new Map(prompt.inputs?.filter(nonNullable).map((input) => [
|
|
97
|
-
input.name,
|
|
98
|
-
input
|
|
99
|
-
]));
|
|
100
|
-
const missing = [];
|
|
101
|
-
Array.from(variables.values()).forEach((name) => {
|
|
102
|
-
if (unclaimed.has(name)) {
|
|
103
|
-
unclaimed.delete(name);
|
|
104
|
-
} else {
|
|
105
|
-
missing.push(name);
|
|
106
|
-
}
|
|
107
|
-
});
|
|
108
|
-
const values = unclaimed.values();
|
|
109
|
-
missing.forEach((name) => {
|
|
110
|
-
const next = values.next().value;
|
|
111
|
-
if (next) {
|
|
112
|
-
next.name = name;
|
|
113
|
-
} else {
|
|
114
|
-
prompt.inputs?.push({
|
|
115
|
-
name
|
|
116
|
-
});
|
|
117
|
-
}
|
|
118
|
-
});
|
|
119
|
-
for (const input of values) {
|
|
120
|
-
prompt.inputs.splice(prompt.inputs.indexOf(input), 1);
|
|
121
|
-
}
|
|
122
|
-
}, [
|
|
123
|
-
prompt.template
|
|
124
|
-
]);
|
|
125
|
-
};
|
|
126
|
-
var PromptEditor = ({ prompt, commandEditable = true }) => {
|
|
127
|
-
const { t } = useTranslation(AUTOMATION_PLUGIN);
|
|
128
|
-
const { themeMode } = useThemeContext();
|
|
129
|
-
const { parentRef } = useTextEditor(() => ({
|
|
130
|
-
initialValue: prompt.template,
|
|
131
|
-
extensions: [
|
|
132
|
-
createDataExtensions({
|
|
133
|
-
id: prompt.id,
|
|
134
|
-
text: prompt.template !== void 0 ? createDocAccessor(prompt, [
|
|
135
|
-
"template"
|
|
136
|
-
]) : void 0
|
|
137
|
-
}),
|
|
138
|
-
createBasicExtensions({
|
|
139
|
-
bracketMatching: false,
|
|
140
|
-
lineWrapping: true,
|
|
141
|
-
placeholder: t("template placeholder")
|
|
142
|
-
}),
|
|
143
|
-
createThemeExtensions({
|
|
144
|
-
themeMode,
|
|
145
|
-
slots: {
|
|
146
|
-
content: {
|
|
147
|
-
className: "!p-3"
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
}),
|
|
151
|
-
promptExtension
|
|
152
|
-
]
|
|
153
|
-
}), [
|
|
154
|
-
themeMode,
|
|
155
|
-
prompt
|
|
156
|
-
]);
|
|
157
|
-
usePromptInputs(prompt);
|
|
158
|
-
return /* @__PURE__ */ React.createElement("div", {
|
|
159
|
-
className: mx2("flex flex-col w-full overflow-hidden gap-4", groupBorder)
|
|
160
|
-
}, commandEditable && /* @__PURE__ */ React.createElement("div", {
|
|
161
|
-
className: "flex items-center pl-4"
|
|
162
|
-
}, /* @__PURE__ */ React.createElement("span", {
|
|
163
|
-
className: "text-neutral-500"
|
|
164
|
-
}, "/"), /* @__PURE__ */ React.createElement(Input.Root, null, /* @__PURE__ */ React.createElement(Input.TextInput, {
|
|
165
|
-
placeholder: t("command placeholder"),
|
|
166
|
-
classNames: mx2("is-full bg-transparent m-2"),
|
|
167
|
-
value: prompt.command ?? "",
|
|
168
|
-
onChange: (event) => {
|
|
169
|
-
prompt.command = event.target.value.replace(/\w/g, "");
|
|
170
|
-
}
|
|
171
|
-
}))), /* @__PURE__ */ React.createElement("div", {
|
|
172
|
-
ref: parentRef,
|
|
173
|
-
className: mx2(attentionSurface, "rounded", "min-h-[120px]")
|
|
174
|
-
}), (prompt.inputs?.length ?? 0) > 0 && /* @__PURE__ */ React.createElement("div", {
|
|
175
|
-
className: "flex flex-col"
|
|
176
|
-
}, /* @__PURE__ */ React.createElement("table", {
|
|
177
|
-
className: "w-full table-fixed border-collapse my-2"
|
|
178
|
-
}, /* @__PURE__ */ React.createElement("tbody", null, prompt.inputs?.filter(nonNullable).map((input) => /* @__PURE__ */ React.createElement("tr", {
|
|
179
|
-
key: input.name
|
|
180
|
-
}, /* @__PURE__ */ React.createElement("td", {
|
|
181
|
-
className: "w-[160px] p-1 font-mono text-sm whitespace-nowrap truncate"
|
|
182
|
-
}, /* @__PURE__ */ React.createElement("code", {
|
|
183
|
-
className: "px-2"
|
|
184
|
-
}, input.name)), /* @__PURE__ */ React.createElement("td", {
|
|
185
|
-
className: "w-[120px] p-1"
|
|
186
|
-
}, /* @__PURE__ */ React.createElement(Input.Root, null, /* @__PURE__ */ React.createElement(Select.Root, {
|
|
187
|
-
value: String(input.type),
|
|
188
|
-
onValueChange: (type) => {
|
|
189
|
-
input.type = getInputType(type) ?? ChainInputType.VALUE;
|
|
190
|
-
}
|
|
191
|
-
}, /* @__PURE__ */ React.createElement(Select.TriggerButton, {
|
|
192
|
-
placeholder: "Type",
|
|
193
|
-
classNames: "is-full"
|
|
194
|
-
}), /* @__PURE__ */ React.createElement(Select.Portal, null, /* @__PURE__ */ React.createElement(Select.Content, null, /* @__PURE__ */ React.createElement(Select.Viewport, null, inputTypes.map(({ value, label }) => /* @__PURE__ */ React.createElement(Select.Option, {
|
|
195
|
-
key: value,
|
|
196
|
-
value: String(value)
|
|
197
|
-
}, label)))))))), /* @__PURE__ */ React.createElement("td", {
|
|
198
|
-
className: "p-1 pr-2"
|
|
199
|
-
}, input.type !== void 0 && [
|
|
200
|
-
ChainInputType.VALUE,
|
|
201
|
-
ChainInputType.CONTEXT,
|
|
202
|
-
ChainInputType.RESOLVER,
|
|
203
|
-
ChainInputType.SCHEMA
|
|
204
|
-
].includes(input.type) && /* @__PURE__ */ React.createElement("div", null, /* @__PURE__ */ React.createElement(Input.Root, null, /* @__PURE__ */ React.createElement(Input.TextInput, {
|
|
205
|
-
placeholder: t("command placeholder"),
|
|
206
|
-
classNames: mx2("is-full bg-transparent"),
|
|
207
|
-
value: input.value ?? "",
|
|
208
|
-
onChange: (event) => {
|
|
209
|
-
input.value = event.target.value;
|
|
210
|
-
}
|
|
211
|
-
}))))))))));
|
|
212
|
-
};
|
|
213
|
-
|
|
214
|
-
export {
|
|
215
|
-
PromptEditor
|
|
216
|
-
};
|
|
217
|
-
//# sourceMappingURL=chunk-CJMV64XO.mjs.map
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../../src/components/PromptEditor/PromptEditor.tsx", "../../../src/components/PromptEditor/prompt-extension.ts"],
|
|
4
|
-
"sourcesContent": ["//\n// Copyright 2023 DXOS.org\n//\n\nimport { type Schema as S } from '@effect/schema';\nimport React, { useEffect } from 'react';\n\nimport { createDocAccessor } from '@dxos/react-client/echo';\nimport { Input, Select, useThemeContext, useTranslation } from '@dxos/react-ui';\nimport {\n createBasicExtensions,\n createDataExtensions,\n createThemeExtensions,\n useTextEditor,\n} from '@dxos/react-ui-editor';\nimport { attentionSurface, groupBorder, mx } from '@dxos/react-ui-theme';\nimport { nonNullable } from '@dxos/util';\n\nimport { nameRegex, promptExtension } from './prompt-extension';\nimport { AUTOMATION_PLUGIN } from '../../meta';\nimport { type ChainInput, ChainInputType, type ChainPromptType } from '../../types';\n\nconst inputTypes = [\n {\n value: ChainInputType.VALUE,\n label: 'Value',\n },\n {\n value: ChainInputType.PASS_THROUGH,\n label: 'Pass through',\n },\n {\n value: ChainInputType.RETRIEVER,\n label: 'Retriever',\n },\n // {\n // value: ChainInputType.FUNCTION,\n // label: 'Function',\n // },\n // {\n // value: ChainInputType.QUERY,\n // label: 'Query',\n // },\n {\n value: ChainInputType.RESOLVER,\n label: 'Resolver',\n },\n {\n value: ChainInputType.CONTEXT,\n label: 'Context',\n },\n {\n value: ChainInputType.SCHEMA,\n label: 'Schema',\n },\n];\n\nconst getInputType = (type: string) => inputTypes.find(({ value }) => String(value) === type)?.value;\n\nconst usePromptInputs = (prompt: ChainPromptType) => {\n useEffect(() => {\n const text = prompt.template ?? '';\n if (!prompt.inputs) {\n prompt.inputs = []; // TODO(burdon): Required?\n }\n\n const regex = new RegExp(nameRegex, 'g');\n const variables = new Set<string>([...text.matchAll(regex)].map((m) => m[1]));\n\n // Create map of unclaimed inputs.\n const unclaimed = new Map<string, ChainInput>(\n prompt.inputs?.filter(nonNullable).map((input) => [input.name, input]),\n );\n const missing: string[] = [];\n Array.from(variables.values()).forEach((name) => {\n if (unclaimed.has(name)) {\n unclaimed.delete(name);\n } else {\n missing.push(name);\n }\n });\n\n // Match or create new inputs.\n const values = unclaimed.values();\n missing.forEach((name) => {\n const next = values.next().value;\n if (next) {\n next.name = name;\n } else {\n prompt.inputs?.push({ name });\n }\n });\n\n // Remove unclaimed (deleted) inputs.\n // TODO(burdon): If user types incorrect name value, it will be deleted. Garbage collect?\n for (const input of values) {\n prompt.inputs.splice(prompt.inputs.indexOf(input), 1);\n }\n }, [prompt.template]);\n};\n\nexport type PromptEditorProps = {\n prompt: ChainPromptType;\n commandEditable?: boolean;\n schema?: S.Schema<any, any, any>;\n};\n\nexport const PromptEditor = ({ prompt, commandEditable = true }: PromptEditorProps) => {\n const { t } = useTranslation(AUTOMATION_PLUGIN);\n const { themeMode } = useThemeContext();\n\n const { parentRef } = useTextEditor(\n () => ({\n initialValue: prompt.template,\n extensions: [\n createDataExtensions({\n id: prompt.id,\n text: prompt.template !== undefined ? createDocAccessor(prompt, ['template']) : undefined,\n }),\n createBasicExtensions({\n bracketMatching: false,\n lineWrapping: true,\n placeholder: t('template placeholder'),\n }),\n createThemeExtensions({\n themeMode,\n slots: {\n content: { className: '!p-3' },\n },\n }),\n promptExtension,\n ],\n }),\n [themeMode, prompt],\n );\n\n usePromptInputs(prompt);\n\n return (\n <div className={mx('flex flex-col w-full overflow-hidden gap-4', groupBorder)}>\n {commandEditable && (\n <div className='flex items-center pl-4'>\n <span className='text-neutral-500'>/</span>\n <Input.Root>\n <Input.TextInput\n placeholder={t('command placeholder')}\n classNames={mx('is-full bg-transparent m-2')}\n value={prompt.command ?? ''}\n onChange={(event) => {\n prompt.command = event.target.value.replace(/\\w/g, '');\n }}\n />\n </Input.Root>\n </div>\n )}\n\n <div ref={parentRef} className={mx(attentionSurface, 'rounded', 'min-h-[120px]')} />\n\n {(prompt.inputs?.length ?? 0) > 0 && (\n <div className='flex flex-col'>\n {/* TODO(zan): Improve layout with grid */}\n <table className='w-full table-fixed border-collapse my-2'>\n <tbody>\n {prompt.inputs?.filter(nonNullable).map((input) => (\n <tr key={input.name}>\n <td className='w-[160px] p-1 font-mono text-sm whitespace-nowrap truncate'>\n <code className='px-2'>{input.name}</code>\n </td>\n <td className='w-[120px] p-1'>\n <Input.Root>\n <Select.Root\n value={String(input.type)}\n onValueChange={(type) => {\n input.type = getInputType(type) ?? ChainInputType.VALUE;\n }}\n >\n <Select.TriggerButton placeholder='Type' classNames='is-full' />\n <Select.Portal>\n <Select.Content>\n <Select.Viewport>\n {inputTypes.map(({ value, label }) => (\n <Select.Option key={value} value={String(value)}>\n {label}\n </Select.Option>\n ))}\n </Select.Viewport>\n </Select.Content>\n </Select.Portal>\n </Select.Root>\n </Input.Root>\n </td>\n <td className='p-1 pr-2'>\n {input.type !== undefined &&\n [\n ChainInputType.VALUE,\n ChainInputType.CONTEXT,\n ChainInputType.RESOLVER,\n ChainInputType.SCHEMA,\n ].includes(input.type) && (\n <div>\n <Input.Root>\n <Input.TextInput\n placeholder={t('command placeholder')}\n classNames={mx('is-full bg-transparent')}\n value={input.value ?? ''}\n onChange={(event) => {\n input.value = event.target.value;\n }}\n />\n </Input.Root>\n </div>\n )}\n </td>\n </tr>\n ))}\n </tbody>\n </table>\n </div>\n )}\n </div>\n );\n};\n", "//\n// Copyright 2023 DXOS.org\n//\n\nimport { HighlightStyle, StreamLanguage, syntaxHighlighting } from '@codemirror/language';\nimport { type Extension } from '@codemirror/state';\n\nimport { tags } from '@dxos/react-ui-editor';\nimport { mx } from '@dxos/react-ui-theme';\n\nexport const nameRegex = /\\{([\\w-]+)}/;\n\nconst parser = StreamLanguage.define({\n token: (stream) => {\n if (stream.eatSpace()) {\n return null;\n }\n if (stream.match(/^#.*/)) {\n return 'lineComment';\n }\n if (stream.match(/^-+$/)) {\n return 'lineComment';\n }\n if (stream.match(nameRegex)) {\n return 'variableName';\n }\n stream.next();\n return null;\n },\n});\n\n/**\n * https://codemirror.net/examples/styling\n * https://lezer.codemirror.net/docs/ref/#highlight\n */\nconst highlightStyles = HighlightStyle.define([\n {\n tag: tags.variableName,\n class: mx('rounded border border-yellow-500 bg-yellow-100 text-black font-mono text-sm'),\n },\n]);\n\nexport const promptExtension: Extension = [parser, syntaxHighlighting(highlightStyles)];\n"],
|
|
5
|
-
"mappings": ";;;;;;;;AAKA,OAAOA,SAASC,iBAAiB;AAEjC,SAASC,yBAAyB;AAClC,SAASC,OAAOC,QAAQC,iBAAiBC,sBAAsB;AAC/D,SACEC,uBACAC,sBACAC,uBACAC,qBACK;AACP,SAASC,kBAAkBC,aAAaC,MAAAA,WAAU;AAClD,SAASC,mBAAmB;;;ACZ5B,SAASC,gBAAgBC,gBAAgBC,0BAA0B;AAGnE,SAASC,YAAY;AACrB,SAASC,UAAU;AAEZ,IAAMC,YAAY;AAEzB,IAAMC,SAASC,eAAeC,OAAO;EACnCC,OAAO,CAACC,WAAAA;AACN,QAAIA,OAAOC,SAAQ,GAAI;AACrB,aAAO;IACT;AACA,QAAID,OAAOE,MAAM,MAAA,GAAS;AACxB,aAAO;IACT;AACA,QAAIF,OAAOE,MAAM,MAAA,GAAS;AACxB,aAAO;IACT;AACA,QAAIF,OAAOE,MAAMP,SAAAA,GAAY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CAAAA,CAAAA,GASjB,sBAAA,cAACqF,MAAAA;IAAGtB,WAAU;KACXnC,MAAMrB,SAAS+C,UACd;IACExD,eAAeC;IACfD,eAAeM;IACfN,eAAeK;IACfL,eAAeO;IACfyF,SAASlE,MAAMrB,IAAI,KACnB,sBAAA,cAAC0D,OAAAA,MACC,sBAAA,cAACI,MAAMC,MAAI,MACT,sBAAA,cAACD,MAAME,WAAS;IACdZ,aAAahB,EAAE,qBAAA;IACf6B,YAAYN,IAAG,wBAAA;IACfrE,OAAO+B,MAAM/B,SAAS;IACtB6E,UAAU,CAACC,UAAAA;AACT/C,YAAM/B,QAAQ8E,MAAMC,OAAO/E;IAC7B;;AAc9B;",
|
|
6
|
-
"names": ["React", "useEffect", "createDocAccessor", "Input", "Select", "useThemeContext", "useTranslation", "createBasicExtensions", "createDataExtensions", "createThemeExtensions", "useTextEditor", "attentionSurface", "groupBorder", "mx", "nonNullable", "HighlightStyle", "StreamLanguage", "syntaxHighlighting", "tags", "mx", "nameRegex", "parser", "StreamLanguage", "define", "token", "stream", "eatSpace", "match", "next", "highlightStyles", "HighlightStyle", "tag", "tags", "variableName", "class", "mx", "promptExtension", "syntaxHighlighting", "inputTypes", "value", "ChainInputType", "VALUE", "label", "PASS_THROUGH", "RETRIEVER", "RESOLVER", "CONTEXT", "SCHEMA", "getInputType", "type", "find", "String", "usePromptInputs", "prompt", "useEffect", "text", "template", "inputs", "regex", "RegExp", "nameRegex", "variables", "Set", "matchAll", "map", "m", "unclaimed", "Map", "filter", "nonNullable", "input", "name", "missing", "Array", "from", "values", "forEach", "has", "delete", "push", "next", "splice", "indexOf", "PromptEditor", "commandEditable", "t", "useTranslation", "AUTOMATION_PLUGIN", "themeMode", "useThemeContext", "parentRef", "useTextEditor", "initialValue", "extensions", "createDataExtensions", "id", "undefined", "createDocAccessor", "createBasicExtensions", "bracketMatching", "lineWrapping", "placeholder", "createThemeExtensions", "slots", "content", "className", "promptExtension", "div", "mx", "groupBorder", "span", "Input", "Root", "TextInput", "classNames", "command", "onChange", "event", "target", "replace", "ref", "attentionSurface", "length", "table", "tbody", "tr", "key", "td", "code", "Select", "onValueChange", "TriggerButton", "Portal", "Content", "Viewport", "Option", "includes"]
|
|
7
|
-
}
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __create = Object.create;
|
|
3
|
-
var __defProp = Object.defineProperty;
|
|
4
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __export = (target, all) => {
|
|
9
|
-
for (var name in all)
|
|
10
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
-
};
|
|
12
|
-
var __copyProps = (to, from, except, desc) => {
|
|
13
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
-
for (let key of __getOwnPropNames(from))
|
|
15
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
-
}
|
|
18
|
-
return to;
|
|
19
|
-
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
-
mod
|
|
27
|
-
));
|
|
28
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
-
var PromptContainer_7RCGCU3K_exports = {};
|
|
30
|
-
__export(PromptContainer_7RCGCU3K_exports, {
|
|
31
|
-
default: () => PromptContainer_default
|
|
32
|
-
});
|
|
33
|
-
module.exports = __toCommonJS(PromptContainer_7RCGCU3K_exports);
|
|
34
|
-
var import_chunk_YGRHTCOX = require("./chunk-YGRHTCOX.cjs");
|
|
35
|
-
var import_chunk_SUMUWFZA = require("./chunk-SUMUWFZA.cjs");
|
|
36
|
-
var import_chunk_JSZ6PAYL = require("./chunk-JSZ6PAYL.cjs");
|
|
37
|
-
var import_react = __toESM(require("react"));
|
|
38
|
-
var PromptContainer = (props) => {
|
|
39
|
-
return /* @__PURE__ */ import_react.default.createElement("div", {
|
|
40
|
-
role: "none",
|
|
41
|
-
className: "row-span-2 pli-2"
|
|
42
|
-
}, /* @__PURE__ */ import_react.default.createElement(import_chunk_YGRHTCOX.PromptEditor, props));
|
|
43
|
-
};
|
|
44
|
-
var PromptContainer_default = PromptContainer;
|
|
45
|
-
//# sourceMappingURL=PromptContainer-7RCGCU3K.cjs.map
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../../src/components/PromptContainer.tsx"],
|
|
4
|
-
"sourcesContent": ["//\n// Copyright 2024 DXOS.org\n//\n\nimport React from 'react';\n\nimport { PromptEditor, type PromptEditorProps } from './PromptEditor';\n\ntype PromptContainerProps = PromptEditorProps;\n\nconst PromptContainer = (props: PromptContainerProps) => {\n return (\n <div role='none' className='row-span-2 pli-2'>\n <PromptEditor {...props} />\n </div>\n );\n};\n\nexport default PromptContainer;\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAIA,mBAAkB;AAMlB,IAAMA,kBAAkB,CAACC,UAAAA;AACvB,SACE,6BAAAC,QAAA,cAACC,OAAAA;IAAIC,MAAK;IAAOC,WAAU;KACzB,6BAAAH,QAAA,cAACI,oCAAiBL,KAAAA,CAAAA;AAGxB;AAEA,IAAA,0BAAeD;",
|
|
6
|
-
"names": ["PromptContainer", "props", "React", "div", "role", "className", "PromptEditor"]
|
|
7
|
-
}
|
|
@@ -1,240 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __create = Object.create;
|
|
3
|
-
var __defProp = Object.defineProperty;
|
|
4
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __export = (target, all) => {
|
|
9
|
-
for (var name in all)
|
|
10
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
-
};
|
|
12
|
-
var __copyProps = (to, from, except, desc) => {
|
|
13
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
-
for (let key of __getOwnPropNames(from))
|
|
15
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
-
}
|
|
18
|
-
return to;
|
|
19
|
-
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
-
mod
|
|
27
|
-
));
|
|
28
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
-
var chunk_YGRHTCOX_exports = {};
|
|
30
|
-
__export(chunk_YGRHTCOX_exports, {
|
|
31
|
-
PromptEditor: () => PromptEditor
|
|
32
|
-
});
|
|
33
|
-
module.exports = __toCommonJS(chunk_YGRHTCOX_exports);
|
|
34
|
-
var import_chunk_SUMUWFZA = require("./chunk-SUMUWFZA.cjs");
|
|
35
|
-
var import_chunk_JSZ6PAYL = require("./chunk-JSZ6PAYL.cjs");
|
|
36
|
-
var import_react = __toESM(require("react"));
|
|
37
|
-
var import_echo = require("@dxos/react-client/echo");
|
|
38
|
-
var import_react_ui = require("@dxos/react-ui");
|
|
39
|
-
var import_react_ui_editor = require("@dxos/react-ui-editor");
|
|
40
|
-
var import_react_ui_theme = require("@dxos/react-ui-theme");
|
|
41
|
-
var import_util = require("@dxos/util");
|
|
42
|
-
var import_language = require("@codemirror/language");
|
|
43
|
-
var import_react_ui_editor2 = require("@dxos/react-ui-editor");
|
|
44
|
-
var import_react_ui_theme2 = require("@dxos/react-ui-theme");
|
|
45
|
-
var nameRegex = /\{([\w-]+)}/;
|
|
46
|
-
var parser = import_language.StreamLanguage.define({
|
|
47
|
-
token: (stream) => {
|
|
48
|
-
if (stream.eatSpace()) {
|
|
49
|
-
return null;
|
|
50
|
-
}
|
|
51
|
-
if (stream.match(/^#.*/)) {
|
|
52
|
-
return "lineComment";
|
|
53
|
-
}
|
|
54
|
-
if (stream.match(/^-+$/)) {
|
|
55
|
-
return "lineComment";
|
|
56
|
-
}
|
|
57
|
-
if (stream.match(nameRegex)) {
|
|
58
|
-
return "variableName";
|
|
59
|
-
}
|
|
60
|
-
stream.next();
|
|
61
|
-
return null;
|
|
62
|
-
}
|
|
63
|
-
});
|
|
64
|
-
var highlightStyles = import_language.HighlightStyle.define([
|
|
65
|
-
{
|
|
66
|
-
tag: import_react_ui_editor2.tags.variableName,
|
|
67
|
-
class: (0, import_react_ui_theme2.mx)("rounded border border-yellow-500 bg-yellow-100 text-black font-mono text-sm")
|
|
68
|
-
}
|
|
69
|
-
]);
|
|
70
|
-
var promptExtension = [
|
|
71
|
-
parser,
|
|
72
|
-
(0, import_language.syntaxHighlighting)(highlightStyles)
|
|
73
|
-
];
|
|
74
|
-
var inputTypes = [
|
|
75
|
-
{
|
|
76
|
-
value: import_chunk_SUMUWFZA.ChainInputType.VALUE,
|
|
77
|
-
label: "Value"
|
|
78
|
-
},
|
|
79
|
-
{
|
|
80
|
-
value: import_chunk_SUMUWFZA.ChainInputType.PASS_THROUGH,
|
|
81
|
-
label: "Pass through"
|
|
82
|
-
},
|
|
83
|
-
{
|
|
84
|
-
value: import_chunk_SUMUWFZA.ChainInputType.RETRIEVER,
|
|
85
|
-
label: "Retriever"
|
|
86
|
-
},
|
|
87
|
-
// {
|
|
88
|
-
// value: ChainInputType.FUNCTION,
|
|
89
|
-
// label: 'Function',
|
|
90
|
-
// },
|
|
91
|
-
// {
|
|
92
|
-
// value: ChainInputType.QUERY,
|
|
93
|
-
// label: 'Query',
|
|
94
|
-
// },
|
|
95
|
-
{
|
|
96
|
-
value: import_chunk_SUMUWFZA.ChainInputType.RESOLVER,
|
|
97
|
-
label: "Resolver"
|
|
98
|
-
},
|
|
99
|
-
{
|
|
100
|
-
value: import_chunk_SUMUWFZA.ChainInputType.CONTEXT,
|
|
101
|
-
label: "Context"
|
|
102
|
-
},
|
|
103
|
-
{
|
|
104
|
-
value: import_chunk_SUMUWFZA.ChainInputType.SCHEMA,
|
|
105
|
-
label: "Schema"
|
|
106
|
-
}
|
|
107
|
-
];
|
|
108
|
-
var getInputType = (type) => inputTypes.find(({ value }) => String(value) === type)?.value;
|
|
109
|
-
var usePromptInputs = (prompt) => {
|
|
110
|
-
(0, import_react.useEffect)(() => {
|
|
111
|
-
const text = prompt.template ?? "";
|
|
112
|
-
if (!prompt.inputs) {
|
|
113
|
-
prompt.inputs = [];
|
|
114
|
-
}
|
|
115
|
-
const regex = new RegExp(nameRegex, "g");
|
|
116
|
-
const variables = new Set([
|
|
117
|
-
...text.matchAll(regex)
|
|
118
|
-
].map((m) => m[1]));
|
|
119
|
-
const unclaimed = new Map(prompt.inputs?.filter(import_util.nonNullable).map((input) => [
|
|
120
|
-
input.name,
|
|
121
|
-
input
|
|
122
|
-
]));
|
|
123
|
-
const missing = [];
|
|
124
|
-
Array.from(variables.values()).forEach((name) => {
|
|
125
|
-
if (unclaimed.has(name)) {
|
|
126
|
-
unclaimed.delete(name);
|
|
127
|
-
} else {
|
|
128
|
-
missing.push(name);
|
|
129
|
-
}
|
|
130
|
-
});
|
|
131
|
-
const values = unclaimed.values();
|
|
132
|
-
missing.forEach((name) => {
|
|
133
|
-
const next = values.next().value;
|
|
134
|
-
if (next) {
|
|
135
|
-
next.name = name;
|
|
136
|
-
} else {
|
|
137
|
-
prompt.inputs?.push({
|
|
138
|
-
name
|
|
139
|
-
});
|
|
140
|
-
}
|
|
141
|
-
});
|
|
142
|
-
for (const input of values) {
|
|
143
|
-
prompt.inputs.splice(prompt.inputs.indexOf(input), 1);
|
|
144
|
-
}
|
|
145
|
-
}, [
|
|
146
|
-
prompt.template
|
|
147
|
-
]);
|
|
148
|
-
};
|
|
149
|
-
var PromptEditor = ({ prompt, commandEditable = true }) => {
|
|
150
|
-
const { t } = (0, import_react_ui.useTranslation)(import_chunk_JSZ6PAYL.AUTOMATION_PLUGIN);
|
|
151
|
-
const { themeMode } = (0, import_react_ui.useThemeContext)();
|
|
152
|
-
const { parentRef } = (0, import_react_ui_editor.useTextEditor)(() => ({
|
|
153
|
-
initialValue: prompt.template,
|
|
154
|
-
extensions: [
|
|
155
|
-
(0, import_react_ui_editor.createDataExtensions)({
|
|
156
|
-
id: prompt.id,
|
|
157
|
-
text: prompt.template !== void 0 ? (0, import_echo.createDocAccessor)(prompt, [
|
|
158
|
-
"template"
|
|
159
|
-
]) : void 0
|
|
160
|
-
}),
|
|
161
|
-
(0, import_react_ui_editor.createBasicExtensions)({
|
|
162
|
-
bracketMatching: false,
|
|
163
|
-
lineWrapping: true,
|
|
164
|
-
placeholder: t("template placeholder")
|
|
165
|
-
}),
|
|
166
|
-
(0, import_react_ui_editor.createThemeExtensions)({
|
|
167
|
-
themeMode,
|
|
168
|
-
slots: {
|
|
169
|
-
content: {
|
|
170
|
-
className: "!p-3"
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
}),
|
|
174
|
-
promptExtension
|
|
175
|
-
]
|
|
176
|
-
}), [
|
|
177
|
-
themeMode,
|
|
178
|
-
prompt
|
|
179
|
-
]);
|
|
180
|
-
usePromptInputs(prompt);
|
|
181
|
-
return /* @__PURE__ */ import_react.default.createElement("div", {
|
|
182
|
-
className: (0, import_react_ui_theme.mx)("flex flex-col w-full overflow-hidden gap-4", import_react_ui_theme.groupBorder)
|
|
183
|
-
}, commandEditable && /* @__PURE__ */ import_react.default.createElement("div", {
|
|
184
|
-
className: "flex items-center pl-4"
|
|
185
|
-
}, /* @__PURE__ */ import_react.default.createElement("span", {
|
|
186
|
-
className: "text-neutral-500"
|
|
187
|
-
}, "/"), /* @__PURE__ */ import_react.default.createElement(import_react_ui.Input.Root, null, /* @__PURE__ */ import_react.default.createElement(import_react_ui.Input.TextInput, {
|
|
188
|
-
placeholder: t("command placeholder"),
|
|
189
|
-
classNames: (0, import_react_ui_theme.mx)("is-full bg-transparent m-2"),
|
|
190
|
-
value: prompt.command ?? "",
|
|
191
|
-
onChange: (event) => {
|
|
192
|
-
prompt.command = event.target.value.replace(/\w/g, "");
|
|
193
|
-
}
|
|
194
|
-
}))), /* @__PURE__ */ import_react.default.createElement("div", {
|
|
195
|
-
ref: parentRef,
|
|
196
|
-
className: (0, import_react_ui_theme.mx)(import_react_ui_theme.attentionSurface, "rounded", "min-h-[120px]")
|
|
197
|
-
}), (prompt.inputs?.length ?? 0) > 0 && /* @__PURE__ */ import_react.default.createElement("div", {
|
|
198
|
-
className: "flex flex-col"
|
|
199
|
-
}, /* @__PURE__ */ import_react.default.createElement("table", {
|
|
200
|
-
className: "w-full table-fixed border-collapse my-2"
|
|
201
|
-
}, /* @__PURE__ */ import_react.default.createElement("tbody", null, prompt.inputs?.filter(import_util.nonNullable).map((input) => /* @__PURE__ */ import_react.default.createElement("tr", {
|
|
202
|
-
key: input.name
|
|
203
|
-
}, /* @__PURE__ */ import_react.default.createElement("td", {
|
|
204
|
-
className: "w-[160px] p-1 font-mono text-sm whitespace-nowrap truncate"
|
|
205
|
-
}, /* @__PURE__ */ import_react.default.createElement("code", {
|
|
206
|
-
className: "px-2"
|
|
207
|
-
}, input.name)), /* @__PURE__ */ import_react.default.createElement("td", {
|
|
208
|
-
className: "w-[120px] p-1"
|
|
209
|
-
}, /* @__PURE__ */ import_react.default.createElement(import_react_ui.Input.Root, null, /* @__PURE__ */ import_react.default.createElement(import_react_ui.Select.Root, {
|
|
210
|
-
value: String(input.type),
|
|
211
|
-
onValueChange: (type) => {
|
|
212
|
-
input.type = getInputType(type) ?? import_chunk_SUMUWFZA.ChainInputType.VALUE;
|
|
213
|
-
}
|
|
214
|
-
}, /* @__PURE__ */ import_react.default.createElement(import_react_ui.Select.TriggerButton, {
|
|
215
|
-
placeholder: "Type",
|
|
216
|
-
classNames: "is-full"
|
|
217
|
-
}), /* @__PURE__ */ import_react.default.createElement(import_react_ui.Select.Portal, null, /* @__PURE__ */ import_react.default.createElement(import_react_ui.Select.Content, null, /* @__PURE__ */ import_react.default.createElement(import_react_ui.Select.Viewport, null, inputTypes.map(({ value, label }) => /* @__PURE__ */ import_react.default.createElement(import_react_ui.Select.Option, {
|
|
218
|
-
key: value,
|
|
219
|
-
value: String(value)
|
|
220
|
-
}, label)))))))), /* @__PURE__ */ import_react.default.createElement("td", {
|
|
221
|
-
className: "p-1 pr-2"
|
|
222
|
-
}, input.type !== void 0 && [
|
|
223
|
-
import_chunk_SUMUWFZA.ChainInputType.VALUE,
|
|
224
|
-
import_chunk_SUMUWFZA.ChainInputType.CONTEXT,
|
|
225
|
-
import_chunk_SUMUWFZA.ChainInputType.RESOLVER,
|
|
226
|
-
import_chunk_SUMUWFZA.ChainInputType.SCHEMA
|
|
227
|
-
].includes(input.type) && /* @__PURE__ */ import_react.default.createElement("div", null, /* @__PURE__ */ import_react.default.createElement(import_react_ui.Input.Root, null, /* @__PURE__ */ import_react.default.createElement(import_react_ui.Input.TextInput, {
|
|
228
|
-
placeholder: t("command placeholder"),
|
|
229
|
-
classNames: (0, import_react_ui_theme.mx)("is-full bg-transparent"),
|
|
230
|
-
value: input.value ?? "",
|
|
231
|
-
onChange: (event) => {
|
|
232
|
-
input.value = event.target.value;
|
|
233
|
-
}
|
|
234
|
-
}))))))))));
|
|
235
|
-
};
|
|
236
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
237
|
-
0 && (module.exports = {
|
|
238
|
-
PromptEditor
|
|
239
|
-
});
|
|
240
|
-
//# sourceMappingURL=chunk-YGRHTCOX.cjs.map
|