@dxos/plugin-script 0.8.0 → 0.8.1-main.ae460ac

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.
Files changed (64) hide show
  1. package/dist/lib/browser/{ScriptContainer-3RFMYKTV.mjs → ScriptContainer-S3MAKTV2.mjs} +3 -3
  2. package/dist/lib/browser/{chunk-N46LE7FS.mjs → chunk-2H6QBQ5Q.mjs} +2 -2
  3. package/dist/lib/browser/{chunk-N46LE7FS.mjs.map → chunk-2H6QBQ5Q.mjs.map} +1 -1
  4. package/dist/lib/browser/{chunk-PZPYF7M4.mjs → chunk-4FWN55UF.mjs} +1 -1
  5. package/dist/lib/browser/{chunk-PZPYF7M4.mjs.map → chunk-4FWN55UF.mjs.map} +2 -2
  6. package/dist/lib/browser/{chunk-VTWBVFBK.mjs → chunk-FWK7MJLK.mjs} +2 -2
  7. package/dist/lib/browser/{chunk-G2FYNDU4.mjs → chunk-PFIX5NKP.mjs} +2 -2
  8. package/dist/lib/browser/index.mjs +5 -5
  9. package/dist/lib/browser/{intent-resolver-D6FPY5ZA.mjs → intent-resolver-5BRHMSBN.mjs} +3 -3
  10. package/dist/lib/browser/meta.json +1 -1
  11. package/dist/lib/browser/{react-surface-G4C2PZ2K.mjs → react-surface-IDIV7XIA.mjs} +4 -4
  12. package/dist/lib/browser/{settings-SZCDKHWO.mjs → settings-LRHZSUEJ.mjs} +2 -2
  13. package/dist/lib/browser/types.mjs +1 -1
  14. package/dist/lib/node/{ScriptContainer-G6FZU4AM.cjs → ScriptContainer-HAN2O43Z.cjs} +13 -13
  15. package/dist/lib/node/{chunk-DJGLGRQV.cjs → chunk-3ICET6JB.cjs} +6 -6
  16. package/dist/lib/node/chunk-3ICET6JB.cjs.map +7 -0
  17. package/dist/lib/node/{chunk-TOXBGIEI.cjs → chunk-7DFSSJOL.cjs} +5 -5
  18. package/dist/lib/node/{chunk-ITAJ3WRW.cjs → chunk-I57SKIAA.cjs} +4 -4
  19. package/dist/lib/node/{chunk-ITAJ3WRW.cjs.map → chunk-I57SKIAA.cjs.map} +2 -2
  20. package/dist/lib/node/{chunk-XKYJYY3T.cjs → chunk-PPGWSKO4.cjs} +7 -7
  21. package/dist/lib/node/index.cjs +10 -10
  22. package/dist/lib/node/{intent-resolver-NYJFPD5B.cjs → intent-resolver-L4WJAAV3.cjs} +8 -8
  23. package/dist/lib/node/meta.json +1 -1
  24. package/dist/lib/node/{react-surface-EGSE3FMN.cjs → react-surface-JRDQP3MO.cjs} +12 -12
  25. package/dist/lib/node/{settings-SZFSMSKM.cjs → settings-TR2CA4IH.cjs} +7 -7
  26. package/dist/lib/node/types.cjs +3 -3
  27. package/dist/lib/node/types.cjs.map +1 -1
  28. package/dist/lib/node-esm/{ScriptContainer-7FTCFIF3.mjs → ScriptContainer-QDP6ASXN.mjs} +3 -3
  29. package/dist/lib/node-esm/{chunk-S64WSJQK.mjs → chunk-HLRR6EJX.mjs} +2 -2
  30. package/dist/lib/node-esm/{chunk-YIWRJ25J.mjs → chunk-J5LF4LOZ.mjs} +1 -1
  31. package/dist/lib/node-esm/{chunk-YIWRJ25J.mjs.map → chunk-J5LF4LOZ.mjs.map} +2 -2
  32. package/dist/lib/node-esm/{chunk-UNQFIERE.mjs → chunk-N52CCVF5.mjs} +2 -2
  33. package/dist/lib/node-esm/{chunk-UNQFIERE.mjs.map → chunk-N52CCVF5.mjs.map} +1 -1
  34. package/dist/lib/node-esm/{chunk-NRICF4KE.mjs → chunk-UOGXH6JB.mjs} +2 -2
  35. package/dist/lib/node-esm/index.mjs +5 -5
  36. package/dist/lib/node-esm/{intent-resolver-KLBHSMW4.mjs → intent-resolver-HFXJQI5Y.mjs} +3 -3
  37. package/dist/lib/node-esm/meta.json +1 -1
  38. package/dist/lib/node-esm/{react-surface-7YSGHZQM.mjs → react-surface-VN7MK3J7.mjs} +4 -4
  39. package/dist/lib/node-esm/{settings-GR4O2WHZ.mjs → settings-Q6B4K7LO.mjs} +2 -2
  40. package/dist/lib/node-esm/types.mjs +1 -1
  41. package/dist/types/src/templates/index.d.ts.map +1 -1
  42. package/package.json +44 -43
  43. package/src/templates/index.ts +0 -7
  44. package/src/types.ts +1 -1
  45. package/src/vite-env.d.ts +20 -0
  46. package/dist/lib/node/chunk-DJGLGRQV.cjs.map +0 -7
  47. /package/dist/lib/browser/{ScriptContainer-3RFMYKTV.mjs.map → ScriptContainer-S3MAKTV2.mjs.map} +0 -0
  48. /package/dist/lib/browser/{chunk-VTWBVFBK.mjs.map → chunk-FWK7MJLK.mjs.map} +0 -0
  49. /package/dist/lib/browser/{chunk-G2FYNDU4.mjs.map → chunk-PFIX5NKP.mjs.map} +0 -0
  50. /package/dist/lib/browser/{intent-resolver-D6FPY5ZA.mjs.map → intent-resolver-5BRHMSBN.mjs.map} +0 -0
  51. /package/dist/lib/browser/{react-surface-G4C2PZ2K.mjs.map → react-surface-IDIV7XIA.mjs.map} +0 -0
  52. /package/dist/lib/browser/{settings-SZCDKHWO.mjs.map → settings-LRHZSUEJ.mjs.map} +0 -0
  53. /package/dist/lib/node/{ScriptContainer-G6FZU4AM.cjs.map → ScriptContainer-HAN2O43Z.cjs.map} +0 -0
  54. /package/dist/lib/node/{chunk-TOXBGIEI.cjs.map → chunk-7DFSSJOL.cjs.map} +0 -0
  55. /package/dist/lib/node/{chunk-XKYJYY3T.cjs.map → chunk-PPGWSKO4.cjs.map} +0 -0
  56. /package/dist/lib/node/{intent-resolver-NYJFPD5B.cjs.map → intent-resolver-L4WJAAV3.cjs.map} +0 -0
  57. /package/dist/lib/node/{react-surface-EGSE3FMN.cjs.map → react-surface-JRDQP3MO.cjs.map} +0 -0
  58. /package/dist/lib/node/{settings-SZFSMSKM.cjs.map → settings-TR2CA4IH.cjs.map} +0 -0
  59. /package/dist/lib/node-esm/{ScriptContainer-7FTCFIF3.mjs.map → ScriptContainer-QDP6ASXN.mjs.map} +0 -0
  60. /package/dist/lib/node-esm/{chunk-S64WSJQK.mjs.map → chunk-HLRR6EJX.mjs.map} +0 -0
  61. /package/dist/lib/node-esm/{chunk-NRICF4KE.mjs.map → chunk-UOGXH6JB.mjs.map} +0 -0
  62. /package/dist/lib/node-esm/{intent-resolver-KLBHSMW4.mjs.map → intent-resolver-HFXJQI5Y.mjs.map} +0 -0
  63. /package/dist/lib/node-esm/{react-surface-7YSGHZQM.mjs.map → react-surface-VN7MK3J7.mjs.map} +0 -0
  64. /package/dist/lib/node-esm/{settings-GR4O2WHZ.mjs.map → settings-Q6B4K7LO.mjs.map} +0 -0
@@ -26,15 +26,15 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
26
26
  mod
27
27
  ));
28
28
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
- var ScriptContainer_G6FZU4AM_exports = {};
30
- __export(ScriptContainer_G6FZU4AM_exports, {
29
+ var ScriptContainer_HAN2O43Z_exports = {};
30
+ __export(ScriptContainer_HAN2O43Z_exports, {
31
31
  ScriptContainer: () => ScriptContainer,
32
32
  default: () => ScriptContainer_default
33
33
  });
34
- module.exports = __toCommonJS(ScriptContainer_G6FZU4AM_exports);
35
- var import_chunk_XKYJYY3T = require("./chunk-XKYJYY3T.cjs");
34
+ module.exports = __toCommonJS(ScriptContainer_HAN2O43Z_exports);
35
+ var import_chunk_PPGWSKO4 = require("./chunk-PPGWSKO4.cjs");
36
36
  var import_chunk_K3ZZWVXS = require("./chunk-K3ZZWVXS.cjs");
37
- var import_chunk_ITAJ3WRW = require("./chunk-ITAJ3WRW.cjs");
37
+ var import_chunk_I57SKIAA = require("./chunk-I57SKIAA.cjs");
38
38
  var import_chunk_5UH3F7TA = require("./chunk-5UH3F7TA.cjs");
39
39
  var import_react = __toESM(require("react"));
40
40
  var import_echo = require("@dxos/react-client/echo");
@@ -60,11 +60,11 @@ var import_react_ui2 = require("@dxos/react-ui");
60
60
  var import_react_ui_editor3 = require("@dxos/react-ui-editor");
61
61
  var import_util = require("@dxos/util");
62
62
  var createToolbar = (state) => {
63
- const templateSelect = (0, import_chunk_XKYJYY3T.createTemplateSelect)();
64
- const format = (0, import_chunk_XKYJYY3T.createFormat)();
63
+ const templateSelect = (0, import_chunk_PPGWSKO4.createTemplateSelect)();
64
+ const format = (0, import_chunk_PPGWSKO4.createFormat)();
65
65
  const gap = (0, import_react_ui_menu.createGapSeparator)();
66
- const deploy = (0, import_chunk_XKYJYY3T.createDeploy)(state);
67
- const view = (0, import_chunk_XKYJYY3T.createView)(state);
66
+ const deploy = (0, import_chunk_PPGWSKO4.createDeploy)(state);
67
+ const view = (0, import_chunk_PPGWSKO4.createView)(state);
68
68
  return {
69
69
  nodes: [
70
70
  ...templateSelect.nodes,
@@ -83,7 +83,7 @@ var createToolbar = (state) => {
83
83
  };
84
84
  };
85
85
  var ScriptToolbar = ({ script, role, state, classNames }) => {
86
- const handleAction = (0, import_chunk_XKYJYY3T.useToolbarAction)({
86
+ const handleAction = (0, import_chunk_PPGWSKO4.useToolbarAction)({
87
87
  state,
88
88
  script
89
89
  });
@@ -238,10 +238,10 @@ var ScriptContainer = ({ role, classNames, script, settings = {
238
238
  space,
239
239
  identity
240
240
  ]);
241
- const state = (0, import_chunk_XKYJYY3T.useToolbarState)({
241
+ const state = (0, import_chunk_PPGWSKO4.useToolbarState)({
242
242
  view: "editor"
243
243
  });
244
- (0, import_chunk_XKYJYY3T.useDeployState)({
244
+ (0, import_chunk_PPGWSKO4.useDeployState)({
245
245
  state,
246
246
  script
247
247
  });
@@ -271,4 +271,4 @@ var ScriptContainer_default = ScriptContainer;
271
271
  0 && (module.exports = {
272
272
  ScriptContainer
273
273
  });
274
- //# sourceMappingURL=ScriptContainer-G6FZU4AM.cjs.map
274
+ //# sourceMappingURL=ScriptContainer-HAN2O43Z.cjs.map
@@ -16,14 +16,14 @@ var __copyProps = (to, from, except, desc) => {
16
16
  return to;
17
17
  };
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
- var chunk_DJGLGRQV_exports = {};
20
- __export(chunk_DJGLGRQV_exports, {
19
+ var chunk_3ICET6JB_exports = {};
20
+ __export(chunk_3ICET6JB_exports, {
21
21
  ScriptAction: () => ScriptAction,
22
22
  ScriptSettingsSchema: () => ScriptSettingsSchema
23
23
  });
24
- module.exports = __toCommonJS(chunk_DJGLGRQV_exports);
24
+ module.exports = __toCommonJS(chunk_3ICET6JB_exports);
25
25
  var import_chunk_5UH3F7TA = require("./chunk-5UH3F7TA.cjs");
26
- var import_AST = require("@effect/schema/AST");
26
+ var import_SchemaAST = require("effect/SchemaAST");
27
27
  var import_echo = require("@dxos/client/echo");
28
28
  var import_echo_schema = require("@dxos/echo-schema");
29
29
  var import_functions = require("@dxos/functions");
@@ -35,7 +35,7 @@ var ScriptAction;
35
35
  name: import_echo_schema.S.optional(import_echo_schema.S.String),
36
36
  // TODO(wittjosiah): Placeholder annotation?
37
37
  gistUrl: import_echo_schema.S.optional(import_echo_schema.S.String.annotations({
38
- [import_AST.TitleAnnotationId]: "Import from Gist (url)"
38
+ [import_SchemaAST.TitleAnnotationId]: "Import from Gist (url)"
39
39
  }))
40
40
  });
41
41
  class Create extends import_echo_schema.S.TaggedClass()(`${SCRIPT_ACTION}/create`, {
@@ -57,4 +57,4 @@ var ScriptSettingsSchema = import_echo_schema.S.mutable(import_echo_schema.S.Str
57
57
  ScriptAction,
58
58
  ScriptSettingsSchema
59
59
  });
60
- //# sourceMappingURL=chunk-DJGLGRQV.cjs.map
60
+ //# sourceMappingURL=chunk-3ICET6JB.cjs.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/types.ts"],
4
+ "sourcesContent": ["//\n// Copyright 2023 DXOS.org\n//\n\nimport { TitleAnnotationId } from 'effect/SchemaAST';\n\nimport { SpaceSchema } from '@dxos/client/echo';\nimport { S } from '@dxos/echo-schema';\nimport { ScriptType } from '@dxos/functions';\nimport { EditorInputMode } from '@dxos/react-ui-editor';\n\nimport { SCRIPT_PLUGIN } from './meta';\n\nexport namespace ScriptAction {\n const SCRIPT_ACTION = `${SCRIPT_PLUGIN}/action`;\n\n export const CreateScriptSchema = S.Struct({\n name: S.optional(S.String),\n // TODO(wittjosiah): Placeholder annotation?\n gistUrl: S.optional(S.String.annotations({ [TitleAnnotationId]: 'Import from Gist (url)' })),\n });\n\n export type CreateScriptProps = S.Schema.Type<typeof CreateScriptSchema>;\n\n export class Create extends S.TaggedClass<Create>()(`${SCRIPT_ACTION}/create`, {\n input: S.extend(CreateScriptSchema, S.Struct({ space: SpaceSchema })),\n output: S.Struct({\n object: ScriptType,\n }),\n }) {}\n}\n\nexport const ScriptSettingsSchema = S.mutable(\n S.Struct({\n editorInputMode: EditorInputMode,\n }),\n);\n\nexport type ScriptSettingsProps = S.Schema.Type<typeof ScriptSettingsSchema>;\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;AAIA,uBAAkC;AAElC,kBAA4B;AAC5B,yBAAkB;AAClB,uBAA2B;AAC3B,6BAAgC;;UAIfA,eAAAA;AACf,QAAMC,gBAAgB,GAAGC,mCAAAA;gBAEZC,qBAAqBC,qBAAEC,OAAO;IACzCC,MAAMF,qBAAEG,SAASH,qBAAEI,MAAM;;IAEzBC,SAASL,qBAAEG,SAASH,qBAAEI,OAAOE,YAAY;MAAE,CAACC,kCAAAA,GAAoB;IAAyB,CAAA,CAAA;EAC3F,CAAA;EAIO,MAAMC,eAAeR,qBAAES,YAAW,EAAW,GAAGZ,aAAAA,WAAwB;IAC7Ea,OAAOV,qBAAEW,OAAMf,cAACG,oBAAoBC,qBAAEC,OAAO;MAAEW,OAAOC;IAAY,CAAA,CAAA;IAClEC,QAAQd,qBAAEC,OAAO;MACfc,QAAQC;IACV,CAAA;EACF,CAAA,EAAA;EAAI;gBALSR,SAAAA;AAMf,GAjBiBZ,iBAAAA,eAAAA,CAAAA,EAAAA;AAmBV,IAAMqB,uBAAuBjB,qBAAEkB,QACpClB,qBAAEC,OAAO;EACPkB,iBAAiBC;AACnB,CAAA,CAAA;",
6
+ "names": ["ScriptAction", "SCRIPT_ACTION", "SCRIPT_PLUGIN", "CreateScriptSchema", "S", "Struct", "name", "optional", "String", "gistUrl", "annotations", "TitleAnnotationId", "Create", "TaggedClass", "input", "extend", "space", "SpaceSchema", "output", "object", "ScriptType", "ScriptSettingsSchema", "mutable", "editorInputMode", "EditorInputMode"]
7
+ }
@@ -26,13 +26,13 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
26
26
  mod
27
27
  ));
28
28
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
- var chunk_TOXBGIEI_exports = {};
30
- __export(chunk_TOXBGIEI_exports, {
29
+ var chunk_7DFSSJOL_exports = {};
30
+ __export(chunk_7DFSSJOL_exports, {
31
31
  ScriptContainer: () => ScriptContainer,
32
32
  ScriptSettings: () => ScriptSettings,
33
33
  ScriptSettingsPanel: () => ScriptSettingsPanel
34
34
  });
35
- module.exports = __toCommonJS(chunk_TOXBGIEI_exports);
35
+ module.exports = __toCommonJS(chunk_7DFSSJOL_exports);
36
36
  var import_chunk_5UH3F7TA = require("./chunk-5UH3F7TA.cjs");
37
37
  var import_react = __toESM(require("react"));
38
38
  var import_react_client = require("@dxos/react-client");
@@ -251,11 +251,11 @@ var ScriptSettingsPanel = ({ script }) => {
251
251
  onClick: handlePublish
252
252
  }, t(publishing ? "publishing label" : "publish label")))));
253
253
  };
254
- var ScriptContainer = (0, import_react3.lazy)(() => import("./ScriptContainer-G6FZU4AM.cjs"));
254
+ var ScriptContainer = (0, import_react3.lazy)(() => import("./ScriptContainer-HAN2O43Z.cjs"));
255
255
  // Annotate the CommonJS export names for ESM import in node:
256
256
  0 && (module.exports = {
257
257
  ScriptContainer,
258
258
  ScriptSettings,
259
259
  ScriptSettingsPanel
260
260
  });
261
- //# sourceMappingURL=chunk-TOXBGIEI.cjs.map
261
+ //# sourceMappingURL=chunk-7DFSSJOL.cjs.map
@@ -16,11 +16,11 @@ var __copyProps = (to, from, except, desc) => {
16
16
  return to;
17
17
  };
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
- var chunk_ITAJ3WRW_exports = {};
20
- __export(chunk_ITAJ3WRW_exports, {
19
+ var chunk_I57SKIAA_exports = {};
20
+ __export(chunk_I57SKIAA_exports, {
21
21
  templates: () => templates
22
22
  });
23
- module.exports = __toCommonJS(chunk_ITAJ3WRW_exports);
23
+ module.exports = __toCommonJS(chunk_I57SKIAA_exports);
24
24
  var chat_default = "//\n// Copyright 2024 DXOS.org\n//\n\n// @ts-ignore\nimport { transformServerSentEvents } from 'https://esm.sh/@dxos/script-toolbox';\n\n/**\n * Chatbot that answers questions based on the context data.\n */\nexport default async ({\n event: {\n data: { request },\n },\n context: { space, ai },\n}: any) => {\n const textBody = await request.text();\n let parsedRequest: any;\n try {\n parsedRequest = JSON.parse(textBody);\n } catch (err) {\n const answer = await ai.run('@cf/meta/llama-3.1-8b-instruct', {\n stream: true,\n prompt: `\n Using only the context data below to answer the user's question.\n If you cannot answer the question from the provided content, then reply with \"I don't know.\"\n\n CONTEXT:\n ${await getContext({ space })}\n\n QUESTION:\n ${textBody}\n `,\n });\n return new Response(transformServerSentEvents(answer));\n }\n\n const promptId = parsedRequest.trigger.promptId;\n const promptObject = await space.crud.query({ id: promptId }).first();\n\n if (parsedRequest.data.objects.length !== 1) {\n return new Response('Message batches not supported.');\n }\n\n const messageId = parsedRequest.data.objects[0];\n let message;\n try {\n message = await space.crud.query({ id: messageId }).first();\n } catch (err) {\n return new Response('Message not replicated yet.', { status: 409 });\n }\n\n if (message.text.includes('--------')) {\n return new Response('Message was already processed.');\n }\n\n let prompt = promptObject.template;\n for (const input of promptObject.inputs) {\n let value: string | null = null;\n if (input.type === TemplateInputType.VALUE) {\n value = String(input.value);\n } else if (input.type === TemplateInputType.RETRIEVER) {\n value = await getContext({ space });\n } else if (input.type === TemplateInputType.PASS_THROUGH) {\n value = message.text;\n }\n if (value) {\n prompt = prompt.replaceAll(`{${input.name}}`, value);\n }\n }\n\n const answer = await ai.run('@cf/meta/llama-3.1-8b-instruct', {\n stream: false,\n prompt,\n });\n const response = { response: answer.response, prompt, message };\n const textWithAnswer = message.text + '\\n--------\\n\\n' + answer.response;\n await space.crud.update({ id: messageId }, { text: textWithAnswer });\n\n return new Response(JSON.stringify(response));\n};\n\nconst getContext = async ({ space }: any) => {\n let context = '';\n const { objects: docs } = await space.crud.query({ __typename: 'dxos.org/type/Document' }).run();\n for (const doc of docs) {\n const { content } = await space.crud.query({ id: doc.content }).first();\n context += content + '\\n\\n';\n }\n return context;\n};\n\nenum TemplateInputType {\n VALUE = 0,\n PASS_THROUGH = 1,\n RETRIEVER = 2,\n FUNCTION = 3,\n QUERY = 4,\n RESOLVER = 5,\n CONTEXT = 6,\n SCHEMA = 7,\n}\n";
25
25
  var chess_default = "// @ts-ignore\nimport { defineFunction, S } from 'dxos:functions';\n// @ts-ignore\nimport { Chess } from 'https://esm.sh/chess.js@0.13.1';\n\nexport default defineFunction({\n description: 'Plays a random move in a chess game.',\n\n inputSchema: S.Struct({\n changedObjectId: S.String.annotations({\n description: 'The objects to play the game on.',\n }),\n player: S.optional(S.Literal('w', 'b')).annotations({\n description: 'The player to play the game as.',\n }),\n }),\n\n outputSchema: S.Struct({\n state: S.String.annotations({\n description: 'The state of the game as an ASCII art board.',\n }),\n }),\n\n handler: async ({\n event: {\n data: { changedObjectId, player = 'b' },\n },\n context: { space },\n }: any) => {\n const { pgn } = await space.db.query({ id: changedObjectId }).first();\n const game = new Chess();\n game.load_pgn(pgn);\n if (game.turn() !== player) {\n return new Response('Invalid turn', { status: 409 });\n }\n\n const moves = game.moves();\n const move = moves[Math.floor(Math.random() * moves.length)];\n if (!move) {\n return new Response('No legal moves', { status: 406 });\n }\n\n game.move(move);\n const newPgn = game.pgn();\n await space.db.update({ id: changedObjectId }, { pgn: newPgn, fen: game.fen() });\n return { state: game.ascii() };\n },\n});\n";
26
26
  var discord_default = "//\n// Copyright 2025 DXOS.org\n//\n\n// @ts-ignore\nimport { createStatic, EchoObject, defineFunction, DXN, Filter, ObjectId, S } from 'dxos:functions';\nimport {\n FetchHttpClient,\n // @ts-ignore\n} from 'https://esm.sh/@effect/platform@0.77.2?deps=effect@3.13.3';\n// @ts-ignore\nimport { DiscordConfig, DiscordREST, DiscordRESTMemoryLive } from 'https://esm.sh/dfx@0.113.0?deps=effect@3.13.3';\n// @ts-ignore\nimport { Effect, Config, Redacted, Ref } from 'https://esm.sh/effect@3.13.3';\n\nconst MessageSchema = S.Struct({\n id: S.String,\n foreignId: S.Any, // bigint?\n from: S.String,\n created: S.String,\n content: S.String,\n}).pipe(EchoObject('example.com/type/Message', '0.1.0'));\n\nconst DEFAULT_AFTER = 1704067200; // 2024-01-01\n\nconst generateSnowflake = (unixTimestamp: number): bigint => {\n const discordEpoch = 1420070400000n; // Discord Epoch (ms)\n return (BigInt(unixTimestamp * 1000) - discordEpoch) << 22n;\n};\n\nexport default defineFunction({\n inputSchema: S.Struct({\n // TODO(wittjosiah): Remove. This is used to provide a terminal for a cron trigger.\n tick: S.optional(S.String),\n channelId: S.String,\n after: S.optional(S.Number),\n pageSize: S.optional(S.Number),\n queueId: S.String,\n }),\n\n outputSchema: S.Struct({\n newMessages: S.Number,\n }),\n\n handler: ({\n event: {\n data: { channelId, queueId, after = DEFAULT_AFTER, pageSize = 5 },\n },\n context: { space },\n }: any) =>\n Effect.gen(function* () {\n const { token } = yield* Effect.tryPromise(() =>\n space.db.query(Filter.typename('dxos.org/type/AccessToken', { source: 'discord.com' })).first(),\n );\n const { objects } = yield* Effect.tryPromise(() => space.queues.queryQueue(DXN.parse(queueId)));\n const backfill = objects.length === 0;\n const newMessages = yield* Ref.make(0);\n const lastMessage = yield* Ref.make(objects.at(-1));\n\n const enqueueMessages = Effect.gen(function* () {\n const rest = yield* DiscordREST;\n\n while (true) {\n const last = yield* Ref.get(lastMessage);\n const options = {\n after: backfill && !last ? `${generateSnowflake(after)}` : last?.foreignId,\n limit: pageSize,\n };\n const messages = yield* rest.getChannelMessages(channelId, options).pipe((res: any) => res.json);\n const queueMessages = messages\n .map((message: any) =>\n createStatic(MessageSchema, {\n id: ObjectId.random(),\n foreignId: message.id,\n from: message.author.username,\n created: message.timestamp,\n content: message.content,\n }),\n )\n .toReversed();\n if (queueMessages.length > 0) {\n yield* Effect.tryPromise(() => space.queues.insertIntoQueue(DXN.parse(queueId), queueMessages));\n yield* Ref.update(newMessages, (n: any) => n + queueMessages.length);\n yield* Ref.update(lastMessage, (m: any) => queueMessages.at(-1));\n }\n if (messages.length < pageSize) {\n break;\n }\n }\n }).pipe(\n Effect.provide(DiscordRESTMemoryLive),\n Effect.provide(\n DiscordConfig.layerConfig({\n token: Config.succeed(Redacted.make(token)),\n }),\n ),\n Effect.provide(FetchHttpClient.layer),\n );\n\n yield* enqueueMessages;\n return { newMessages: yield* Ref.get(newMessages) };\n }),\n});\n";
@@ -74,4 +74,4 @@ var templates = [
74
74
  0 && (module.exports = {
75
75
  templates
76
76
  });
77
- //# sourceMappingURL=chunk-ITAJ3WRW.cjs.map
77
+ //# sourceMappingURL=chunk-I57SKIAA.cjs.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["raw-loader:./chat.ts?raw", "raw-loader:./chess.ts?raw", "raw-loader:./discord.ts?raw", "raw-loader:./echo.ts?raw", "raw-loader:./email.ts?raw", "raw-loader:./forex-effect.ts?raw", "raw-loader:./forex.ts?raw", "../../../src/templates/index.ts"],
4
- "sourcesContent": ["//\n// Copyright 2024 DXOS.org\n//\n\n// @ts-ignore\nimport { transformServerSentEvents } from 'https://esm.sh/@dxos/script-toolbox';\n\n/**\n * Chatbot that answers questions based on the context data.\n */\nexport default async ({\n event: {\n data: { request },\n },\n context: { space, ai },\n}: any) => {\n const textBody = await request.text();\n let parsedRequest: any;\n try {\n parsedRequest = JSON.parse(textBody);\n } catch (err) {\n const answer = await ai.run('@cf/meta/llama-3.1-8b-instruct', {\n stream: true,\n prompt: `\n Using only the context data below to answer the user's question.\n If you cannot answer the question from the provided content, then reply with \"I don't know.\"\n\n CONTEXT:\n ${await getContext({ space })}\n\n QUESTION:\n ${textBody}\n `,\n });\n return new Response(transformServerSentEvents(answer));\n }\n\n const promptId = parsedRequest.trigger.promptId;\n const promptObject = await space.crud.query({ id: promptId }).first();\n\n if (parsedRequest.data.objects.length !== 1) {\n return new Response('Message batches not supported.');\n }\n\n const messageId = parsedRequest.data.objects[0];\n let message;\n try {\n message = await space.crud.query({ id: messageId }).first();\n } catch (err) {\n return new Response('Message not replicated yet.', { status: 409 });\n }\n\n if (message.text.includes('--------')) {\n return new Response('Message was already processed.');\n }\n\n let prompt = promptObject.template;\n for (const input of promptObject.inputs) {\n let value: string | null = null;\n if (input.type === TemplateInputType.VALUE) {\n value = String(input.value);\n } else if (input.type === TemplateInputType.RETRIEVER) {\n value = await getContext({ space });\n } else if (input.type === TemplateInputType.PASS_THROUGH) {\n value = message.text;\n }\n if (value) {\n prompt = prompt.replaceAll(`{${input.name}}`, value);\n }\n }\n\n const answer = await ai.run('@cf/meta/llama-3.1-8b-instruct', {\n stream: false,\n prompt,\n });\n const response = { response: answer.response, prompt, message };\n const textWithAnswer = message.text + '\\n--------\\n\\n' + answer.response;\n await space.crud.update({ id: messageId }, { text: textWithAnswer });\n\n return new Response(JSON.stringify(response));\n};\n\nconst getContext = async ({ space }: any) => {\n let context = '';\n const { objects: docs } = await space.crud.query({ __typename: 'dxos.org/type/Document' }).run();\n for (const doc of docs) {\n const { content } = await space.crud.query({ id: doc.content }).first();\n context += content + '\\n\\n';\n }\n return context;\n};\n\nenum TemplateInputType {\n VALUE = 0,\n PASS_THROUGH = 1,\n RETRIEVER = 2,\n FUNCTION = 3,\n QUERY = 4,\n RESOLVER = 5,\n CONTEXT = 6,\n SCHEMA = 7,\n}\n", "// @ts-ignore\nimport { defineFunction, S } from 'dxos:functions';\n// @ts-ignore\nimport { Chess } from 'https://esm.sh/chess.js@0.13.1';\n\nexport default defineFunction({\n description: 'Plays a random move in a chess game.',\n\n inputSchema: S.Struct({\n changedObjectId: S.String.annotations({\n description: 'The objects to play the game on.',\n }),\n player: S.optional(S.Literal('w', 'b')).annotations({\n description: 'The player to play the game as.',\n }),\n }),\n\n outputSchema: S.Struct({\n state: S.String.annotations({\n description: 'The state of the game as an ASCII art board.',\n }),\n }),\n\n handler: async ({\n event: {\n data: { changedObjectId, player = 'b' },\n },\n context: { space },\n }: any) => {\n const { pgn } = await space.db.query({ id: changedObjectId }).first();\n const game = new Chess();\n game.load_pgn(pgn);\n if (game.turn() !== player) {\n return new Response('Invalid turn', { status: 409 });\n }\n\n const moves = game.moves();\n const move = moves[Math.floor(Math.random() * moves.length)];\n if (!move) {\n return new Response('No legal moves', { status: 406 });\n }\n\n game.move(move);\n const newPgn = game.pgn();\n await space.db.update({ id: changedObjectId }, { pgn: newPgn, fen: game.fen() });\n return { state: game.ascii() };\n },\n});\n", "//\n// Copyright 2025 DXOS.org\n//\n\n// @ts-ignore\nimport { createStatic, EchoObject, defineFunction, DXN, Filter, ObjectId, S } from 'dxos:functions';\nimport {\n FetchHttpClient,\n // @ts-ignore\n} from 'https://esm.sh/@effect/platform@0.77.2?deps=effect@3.13.3';\n// @ts-ignore\nimport { DiscordConfig, DiscordREST, DiscordRESTMemoryLive } from 'https://esm.sh/dfx@0.113.0?deps=effect@3.13.3';\n// @ts-ignore\nimport { Effect, Config, Redacted, Ref } from 'https://esm.sh/effect@3.13.3';\n\nconst MessageSchema = S.Struct({\n id: S.String,\n foreignId: S.Any, // bigint?\n from: S.String,\n created: S.String,\n content: S.String,\n}).pipe(EchoObject('example.com/type/Message', '0.1.0'));\n\nconst DEFAULT_AFTER = 1704067200; // 2024-01-01\n\nconst generateSnowflake = (unixTimestamp: number): bigint => {\n const discordEpoch = 1420070400000n; // Discord Epoch (ms)\n return (BigInt(unixTimestamp * 1000) - discordEpoch) << 22n;\n};\n\nexport default defineFunction({\n inputSchema: S.Struct({\n // TODO(wittjosiah): Remove. This is used to provide a terminal for a cron trigger.\n tick: S.optional(S.String),\n channelId: S.String,\n after: S.optional(S.Number),\n pageSize: S.optional(S.Number),\n queueId: S.String,\n }),\n\n outputSchema: S.Struct({\n newMessages: S.Number,\n }),\n\n handler: ({\n event: {\n data: { channelId, queueId, after = DEFAULT_AFTER, pageSize = 5 },\n },\n context: { space },\n }: any) =>\n Effect.gen(function* () {\n const { token } = yield* Effect.tryPromise(() =>\n space.db.query(Filter.typename('dxos.org/type/AccessToken', { source: 'discord.com' })).first(),\n );\n const { objects } = yield* Effect.tryPromise(() => space.queues.queryQueue(DXN.parse(queueId)));\n const backfill = objects.length === 0;\n const newMessages = yield* Ref.make(0);\n const lastMessage = yield* Ref.make(objects.at(-1));\n\n const enqueueMessages = Effect.gen(function* () {\n const rest = yield* DiscordREST;\n\n while (true) {\n const last = yield* Ref.get(lastMessage);\n const options = {\n after: backfill && !last ? `${generateSnowflake(after)}` : last?.foreignId,\n limit: pageSize,\n };\n const messages = yield* rest.getChannelMessages(channelId, options).pipe((res: any) => res.json);\n const queueMessages = messages\n .map((message: any) =>\n createStatic(MessageSchema, {\n id: ObjectId.random(),\n foreignId: message.id,\n from: message.author.username,\n created: message.timestamp,\n content: message.content,\n }),\n )\n .toReversed();\n if (queueMessages.length > 0) {\n yield* Effect.tryPromise(() => space.queues.insertIntoQueue(DXN.parse(queueId), queueMessages));\n yield* Ref.update(newMessages, (n: any) => n + queueMessages.length);\n yield* Ref.update(lastMessage, (m: any) => queueMessages.at(-1));\n }\n if (messages.length < pageSize) {\n break;\n }\n }\n }).pipe(\n Effect.provide(DiscordRESTMemoryLive),\n Effect.provide(\n DiscordConfig.layerConfig({\n token: Config.succeed(Redacted.make(token)),\n }),\n ),\n Effect.provide(FetchHttpClient.layer),\n );\n\n yield* enqueueMessages;\n return { newMessages: yield* Ref.get(newMessages) };\n }),\n});\n", "//\n// Copyright 2024 DXOS.org\n//\n\n/**\n * Echos the request data.\n */\nexport default async ({\n event: {\n data: { request },\n },\n}: any) => {\n const data = await request.json();\n return new Response(JSON.stringify(data ?? {}), {\n headers: {\n 'Content-Type': 'application/json',\n },\n });\n};\n", "//\n// Copyright 2024 DXOS.org\n//\n\n/**\n * Appends a message to the end of a Document configured through a trigger.\n * Trigger must have a targetDocumentId field set in Meta.\n */\nexport default async ({\n event: {\n data: { request },\n },\n context: { space },\n}: any) => {\n const { data, trigger } = (await request.json()) as RequestPayload;\n\n const documentId = trigger.meta.targetDocumentId;\n const document = await space.db.query({ id: documentId }, { format: 'plain' }).first();\n\n const contentId = document.content['/'].split(':')[3];\n const documentContent = await space.db.query({ id: contentId }, { format: 'plain' }).first();\n const modifiedContent = [\n documentContent.content,\n '',\n '---',\n `**From:** ${data.from}`,\n `**Subject:** ${data.subject}`,\n `**Date:** ${data.created}`,\n '',\n data.body,\n ].join('\\n');\n\n await space.db.update({ id: contentId }, { content: modifiedContent });\n\n return new Response(JSON.stringify({ success: true }));\n};\n\ntype RequestPayload = {\n data: { from: string; subject: string; created: string; body: string };\n trigger: { meta: { targetDocumentId: string } };\n};\n", "//\n// Copyright 2025 DXOS.org\n//\n\n// @ts-ignore\nimport { defineFunction, S } from 'dxos:functions';\nimport {\n HttpClient,\n HttpClientRequest,\n FetchHttpClient,\n // @ts-ignore\n} from 'https://esm.sh/@effect/platform@0.77.2?deps=effect@3.13.3';\n// @ts-ignore\nimport { Effect, Schedule } from 'https://esm.sh/effect@3.13.3';\n\nexport default defineFunction({\n description: 'Returns the exchange rate between two currencies.',\n\n inputSchema: S.Struct({\n from: S.String.annotations({ description: 'The source currency' }),\n to: S.String.annotations({ description: 'The target currency' }),\n }),\n\n outputSchema: S.String.annotations({ description: 'The exchange rate between the two currencies' }),\n\n handler: async ({\n event: {\n data: { from, to },\n },\n }: any) =>\n Effect.gen(function* () {\n const res = yield* HttpClientRequest.get(`https://free.ratesdb.com/v1/rates?from=${from}&to=${to}`).pipe(\n HttpClient.execute,\n Effect.flatMap((res: any) => res.json),\n Effect.timeout('1 second'),\n Effect.retry(Schedule.exponential(1000).pipe(Schedule.compose(Schedule.recurs(3)))),\n Effect.scoped,\n );\n return res.data.rates[to].toString();\n }).pipe(Effect.provide(FetchHttpClient.layer)),\n});\n", "//\n// Copyright 2025 DXOS.org\n//\n\n// @ts-ignore\nimport { defineFunction, S } from 'dxos:functions';\n\nexport default defineFunction({\n description: 'Returns the exchange rate between two currencies.',\n\n inputSchema: S.Struct({\n from: S.String.annotations({ description: 'The source currency' }),\n to: S.String.annotations({ description: 'The target currency' }),\n }),\n\n handler: async ({\n event: {\n data: { from, to },\n },\n }: any) => {\n const res = await fetch(`https://free.ratesdb.com/v1/rates?from=${from}&to=${to}`);\n const {\n data: { rates },\n } = await res.json();\n\n return rates[to].toString();\n },\n});\n", "//\n// Copyright 2024 DXOS.org\n//\n\n// @ts-ignore\nimport chat from './chat.ts?raw';\n// @ts-ignore\nimport chess from './chess.ts?raw';\n// @ts-ignore\nimport discord from './discord.ts?raw';\n// @ts-ignore\nimport echo from './echo.ts?raw';\n// @ts-ignore\nimport email from './email.ts?raw';\n// @ts-ignore\nimport forexEffect from './forex-effect.ts?raw';\n// @ts-ignore\nimport forex from './forex.ts?raw';\n\nconst removeHeader = (str: string) => str.split('\\n').slice(4).join('\\n');\n\nexport type Template = {\n id: string;\n name: string;\n source: string;\n presetId?: string;\n};\n\nexport const templates: Template[] = [\n {\n id: 'dxos.org/script/echo',\n name: 'Echo',\n source: removeHeader(echo),\n },\n {\n id: 'dxos.org/script/forex',\n name: 'Forex',\n source: removeHeader(forex),\n },\n {\n id: 'dxos.org/script/forex-effect',\n name: 'Forex (Effect)',\n source: removeHeader(forexEffect),\n },\n {\n id: 'dxos.org/script/gpt',\n name: 'Gpt',\n source: removeHeader(chat),\n presetId: 'dxos.org/function/gpt',\n },\n {\n id: 'dxos.org/script/chess',\n name: 'Chess',\n source: removeHeader(chess),\n presetId: 'dxos.org/function/chess',\n },\n {\n id: 'dxos.org/script/email',\n name: 'Email',\n source: removeHeader(email),\n presetId: 'dxos.org/function/email',\n },\n {\n id: 'dxos.org/script/discord',\n name: 'Discord',\n source: removeHeader(discord),\n presetId: 'dxos.org/function/discord',\n },\n];\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;AAAA,IAAA,eAAA;ACAA,IAAA,gBAAA;ACAA,IAAA,kBAAA;ACAA,IAAA,eAAA;ACAA,IAAA,gBAAA;ACAA,IAAA,uBAAA;ACAA,IAAA,gBAAA;ACmBA,IAAMA,eAAe,CAACC,QAAgBA,IAAIC,MAAM,IAAA,EAAMC,MAAM,CAAA,EAAGC,KAAK,IAAA;AAS7D,IAAMC,YAAwB;EACnC;IACEC,IAAI;IACJC,MAAM;IACNC,QAAQR,aAAaS,YAAAA;EACvB;EACA;IACEH,IAAI;IACJC,MAAM;IACNC,QAAQR,aAAaU,aAAAA;EACvB;EACA;IACEJ,IAAI;IACJC,MAAM;IACNC,QAAQR,aAAaW,oBAAAA;EACvB;EACA;IACEL,IAAI;IACJC,MAAM;IACNC,QAAQR,aAAaY,YAAAA;IACrBC,UAAU;EACZ;EACA;IACEP,IAAI;IACJC,MAAM;IACNC,QAAQR,aAAac,aAAAA;IACrBD,UAAU;EACZ;EACA;IACEP,IAAI;IACJC,MAAM;IACNC,QAAQR,aAAae,aAAAA;IACrBF,UAAU;EACZ;EACA;IACEP,IAAI;IACJC,MAAM;IACNC,QAAQR,aAAagB,eAAAA;IACrBH,UAAU;EACZ;;",
4
+ "sourcesContent": ["//\n// Copyright 2024 DXOS.org\n//\n\n// @ts-ignore\nimport { transformServerSentEvents } from 'https://esm.sh/@dxos/script-toolbox';\n\n/**\n * Chatbot that answers questions based on the context data.\n */\nexport default async ({\n event: {\n data: { request },\n },\n context: { space, ai },\n}: any) => {\n const textBody = await request.text();\n let parsedRequest: any;\n try {\n parsedRequest = JSON.parse(textBody);\n } catch (err) {\n const answer = await ai.run('@cf/meta/llama-3.1-8b-instruct', {\n stream: true,\n prompt: `\n Using only the context data below to answer the user's question.\n If you cannot answer the question from the provided content, then reply with \"I don't know.\"\n\n CONTEXT:\n ${await getContext({ space })}\n\n QUESTION:\n ${textBody}\n `,\n });\n return new Response(transformServerSentEvents(answer));\n }\n\n const promptId = parsedRequest.trigger.promptId;\n const promptObject = await space.crud.query({ id: promptId }).first();\n\n if (parsedRequest.data.objects.length !== 1) {\n return new Response('Message batches not supported.');\n }\n\n const messageId = parsedRequest.data.objects[0];\n let message;\n try {\n message = await space.crud.query({ id: messageId }).first();\n } catch (err) {\n return new Response('Message not replicated yet.', { status: 409 });\n }\n\n if (message.text.includes('--------')) {\n return new Response('Message was already processed.');\n }\n\n let prompt = promptObject.template;\n for (const input of promptObject.inputs) {\n let value: string | null = null;\n if (input.type === TemplateInputType.VALUE) {\n value = String(input.value);\n } else if (input.type === TemplateInputType.RETRIEVER) {\n value = await getContext({ space });\n } else if (input.type === TemplateInputType.PASS_THROUGH) {\n value = message.text;\n }\n if (value) {\n prompt = prompt.replaceAll(`{${input.name}}`, value);\n }\n }\n\n const answer = await ai.run('@cf/meta/llama-3.1-8b-instruct', {\n stream: false,\n prompt,\n });\n const response = { response: answer.response, prompt, message };\n const textWithAnswer = message.text + '\\n--------\\n\\n' + answer.response;\n await space.crud.update({ id: messageId }, { text: textWithAnswer });\n\n return new Response(JSON.stringify(response));\n};\n\nconst getContext = async ({ space }: any) => {\n let context = '';\n const { objects: docs } = await space.crud.query({ __typename: 'dxos.org/type/Document' }).run();\n for (const doc of docs) {\n const { content } = await space.crud.query({ id: doc.content }).first();\n context += content + '\\n\\n';\n }\n return context;\n};\n\nenum TemplateInputType {\n VALUE = 0,\n PASS_THROUGH = 1,\n RETRIEVER = 2,\n FUNCTION = 3,\n QUERY = 4,\n RESOLVER = 5,\n CONTEXT = 6,\n SCHEMA = 7,\n}\n", "// @ts-ignore\nimport { defineFunction, S } from 'dxos:functions';\n// @ts-ignore\nimport { Chess } from 'https://esm.sh/chess.js@0.13.1';\n\nexport default defineFunction({\n description: 'Plays a random move in a chess game.',\n\n inputSchema: S.Struct({\n changedObjectId: S.String.annotations({\n description: 'The objects to play the game on.',\n }),\n player: S.optional(S.Literal('w', 'b')).annotations({\n description: 'The player to play the game as.',\n }),\n }),\n\n outputSchema: S.Struct({\n state: S.String.annotations({\n description: 'The state of the game as an ASCII art board.',\n }),\n }),\n\n handler: async ({\n event: {\n data: { changedObjectId, player = 'b' },\n },\n context: { space },\n }: any) => {\n const { pgn } = await space.db.query({ id: changedObjectId }).first();\n const game = new Chess();\n game.load_pgn(pgn);\n if (game.turn() !== player) {\n return new Response('Invalid turn', { status: 409 });\n }\n\n const moves = game.moves();\n const move = moves[Math.floor(Math.random() * moves.length)];\n if (!move) {\n return new Response('No legal moves', { status: 406 });\n }\n\n game.move(move);\n const newPgn = game.pgn();\n await space.db.update({ id: changedObjectId }, { pgn: newPgn, fen: game.fen() });\n return { state: game.ascii() };\n },\n});\n", "//\n// Copyright 2025 DXOS.org\n//\n\n// @ts-ignore\nimport { createStatic, EchoObject, defineFunction, DXN, Filter, ObjectId, S } from 'dxos:functions';\nimport {\n FetchHttpClient,\n // @ts-ignore\n} from 'https://esm.sh/@effect/platform@0.77.2?deps=effect@3.13.3';\n// @ts-ignore\nimport { DiscordConfig, DiscordREST, DiscordRESTMemoryLive } from 'https://esm.sh/dfx@0.113.0?deps=effect@3.13.3';\n// @ts-ignore\nimport { Effect, Config, Redacted, Ref } from 'https://esm.sh/effect@3.13.3';\n\nconst MessageSchema = S.Struct({\n id: S.String,\n foreignId: S.Any, // bigint?\n from: S.String,\n created: S.String,\n content: S.String,\n}).pipe(EchoObject('example.com/type/Message', '0.1.0'));\n\nconst DEFAULT_AFTER = 1704067200; // 2024-01-01\n\nconst generateSnowflake = (unixTimestamp: number): bigint => {\n const discordEpoch = 1420070400000n; // Discord Epoch (ms)\n return (BigInt(unixTimestamp * 1000) - discordEpoch) << 22n;\n};\n\nexport default defineFunction({\n inputSchema: S.Struct({\n // TODO(wittjosiah): Remove. This is used to provide a terminal for a cron trigger.\n tick: S.optional(S.String),\n channelId: S.String,\n after: S.optional(S.Number),\n pageSize: S.optional(S.Number),\n queueId: S.String,\n }),\n\n outputSchema: S.Struct({\n newMessages: S.Number,\n }),\n\n handler: ({\n event: {\n data: { channelId, queueId, after = DEFAULT_AFTER, pageSize = 5 },\n },\n context: { space },\n }: any) =>\n Effect.gen(function* () {\n const { token } = yield* Effect.tryPromise(() =>\n space.db.query(Filter.typename('dxos.org/type/AccessToken', { source: 'discord.com' })).first(),\n );\n const { objects } = yield* Effect.tryPromise(() => space.queues.queryQueue(DXN.parse(queueId)));\n const backfill = objects.length === 0;\n const newMessages = yield* Ref.make(0);\n const lastMessage = yield* Ref.make(objects.at(-1));\n\n const enqueueMessages = Effect.gen(function* () {\n const rest = yield* DiscordREST;\n\n while (true) {\n const last = yield* Ref.get(lastMessage);\n const options = {\n after: backfill && !last ? `${generateSnowflake(after)}` : last?.foreignId,\n limit: pageSize,\n };\n const messages = yield* rest.getChannelMessages(channelId, options).pipe((res: any) => res.json);\n const queueMessages = messages\n .map((message: any) =>\n createStatic(MessageSchema, {\n id: ObjectId.random(),\n foreignId: message.id,\n from: message.author.username,\n created: message.timestamp,\n content: message.content,\n }),\n )\n .toReversed();\n if (queueMessages.length > 0) {\n yield* Effect.tryPromise(() => space.queues.insertIntoQueue(DXN.parse(queueId), queueMessages));\n yield* Ref.update(newMessages, (n: any) => n + queueMessages.length);\n yield* Ref.update(lastMessage, (m: any) => queueMessages.at(-1));\n }\n if (messages.length < pageSize) {\n break;\n }\n }\n }).pipe(\n Effect.provide(DiscordRESTMemoryLive),\n Effect.provide(\n DiscordConfig.layerConfig({\n token: Config.succeed(Redacted.make(token)),\n }),\n ),\n Effect.provide(FetchHttpClient.layer),\n );\n\n yield* enqueueMessages;\n return { newMessages: yield* Ref.get(newMessages) };\n }),\n});\n", "//\n// Copyright 2024 DXOS.org\n//\n\n/**\n * Echos the request data.\n */\nexport default async ({\n event: {\n data: { request },\n },\n}: any) => {\n const data = await request.json();\n return new Response(JSON.stringify(data ?? {}), {\n headers: {\n 'Content-Type': 'application/json',\n },\n });\n};\n", "//\n// Copyright 2024 DXOS.org\n//\n\n/**\n * Appends a message to the end of a Document configured through a trigger.\n * Trigger must have a targetDocumentId field set in Meta.\n */\nexport default async ({\n event: {\n data: { request },\n },\n context: { space },\n}: any) => {\n const { data, trigger } = (await request.json()) as RequestPayload;\n\n const documentId = trigger.meta.targetDocumentId;\n const document = await space.db.query({ id: documentId }, { format: 'plain' }).first();\n\n const contentId = document.content['/'].split(':')[3];\n const documentContent = await space.db.query({ id: contentId }, { format: 'plain' }).first();\n const modifiedContent = [\n documentContent.content,\n '',\n '---',\n `**From:** ${data.from}`,\n `**Subject:** ${data.subject}`,\n `**Date:** ${data.created}`,\n '',\n data.body,\n ].join('\\n');\n\n await space.db.update({ id: contentId }, { content: modifiedContent });\n\n return new Response(JSON.stringify({ success: true }));\n};\n\ntype RequestPayload = {\n data: { from: string; subject: string; created: string; body: string };\n trigger: { meta: { targetDocumentId: string } };\n};\n", "//\n// Copyright 2025 DXOS.org\n//\n\n// @ts-ignore\nimport { defineFunction, S } from 'dxos:functions';\nimport {\n HttpClient,\n HttpClientRequest,\n FetchHttpClient,\n // @ts-ignore\n} from 'https://esm.sh/@effect/platform@0.77.2?deps=effect@3.13.3';\n// @ts-ignore\nimport { Effect, Schedule } from 'https://esm.sh/effect@3.13.3';\n\nexport default defineFunction({\n description: 'Returns the exchange rate between two currencies.',\n\n inputSchema: S.Struct({\n from: S.String.annotations({ description: 'The source currency' }),\n to: S.String.annotations({ description: 'The target currency' }),\n }),\n\n outputSchema: S.String.annotations({ description: 'The exchange rate between the two currencies' }),\n\n handler: async ({\n event: {\n data: { from, to },\n },\n }: any) =>\n Effect.gen(function* () {\n const res = yield* HttpClientRequest.get(`https://free.ratesdb.com/v1/rates?from=${from}&to=${to}`).pipe(\n HttpClient.execute,\n Effect.flatMap((res: any) => res.json),\n Effect.timeout('1 second'),\n Effect.retry(Schedule.exponential(1000).pipe(Schedule.compose(Schedule.recurs(3)))),\n Effect.scoped,\n );\n return res.data.rates[to].toString();\n }).pipe(Effect.provide(FetchHttpClient.layer)),\n});\n", "//\n// Copyright 2025 DXOS.org\n//\n\n// @ts-ignore\nimport { defineFunction, S } from 'dxos:functions';\n\nexport default defineFunction({\n description: 'Returns the exchange rate between two currencies.',\n\n inputSchema: S.Struct({\n from: S.String.annotations({ description: 'The source currency' }),\n to: S.String.annotations({ description: 'The target currency' }),\n }),\n\n handler: async ({\n event: {\n data: { from, to },\n },\n }: any) => {\n const res = await fetch(`https://free.ratesdb.com/v1/rates?from=${from}&to=${to}`);\n const {\n data: { rates },\n } = await res.json();\n\n return rates[to].toString();\n },\n});\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport chat from './chat.ts?raw';\nimport chess from './chess.ts?raw';\nimport discord from './discord.ts?raw';\nimport echo from './echo.ts?raw';\nimport email from './email.ts?raw';\nimport forexEffect from './forex-effect.ts?raw';\nimport forex from './forex.ts?raw';\n\nconst removeHeader = (str: string) => str.split('\\n').slice(4).join('\\n');\n\nexport type Template = {\n id: string;\n name: string;\n source: string;\n presetId?: string;\n};\n\nexport const templates: Template[] = [\n {\n id: 'dxos.org/script/echo',\n name: 'Echo',\n source: removeHeader(echo),\n },\n {\n id: 'dxos.org/script/forex',\n name: 'Forex',\n source: removeHeader(forex),\n },\n {\n id: 'dxos.org/script/forex-effect',\n name: 'Forex (Effect)',\n source: removeHeader(forexEffect),\n },\n {\n id: 'dxos.org/script/gpt',\n name: 'Gpt',\n source: removeHeader(chat),\n presetId: 'dxos.org/function/gpt',\n },\n {\n id: 'dxos.org/script/chess',\n name: 'Chess',\n source: removeHeader(chess),\n presetId: 'dxos.org/function/chess',\n },\n {\n id: 'dxos.org/script/email',\n name: 'Email',\n source: removeHeader(email),\n presetId: 'dxos.org/function/email',\n },\n {\n id: 'dxos.org/script/discord',\n name: 'Discord',\n source: removeHeader(discord),\n presetId: 'dxos.org/function/discord',\n },\n];\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;AAAA,IAAA,eAAA;ACAA,IAAA,gBAAA;ACAA,IAAA,kBAAA;ACAA,IAAA,eAAA;ACAA,IAAA,gBAAA;ACAA,IAAA,uBAAA;ACAA,IAAA,gBAAA;ACYA,IAAMA,eAAe,CAACC,QAAgBA,IAAIC,MAAM,IAAA,EAAMC,MAAM,CAAA,EAAGC,KAAK,IAAA;AAS7D,IAAMC,YAAwB;EACnC;IACEC,IAAI;IACJC,MAAM;IACNC,QAAQR,aAAaS,YAAAA;EACvB;EACA;IACEH,IAAI;IACJC,MAAM;IACNC,QAAQR,aAAaU,aAAAA;EACvB;EACA;IACEJ,IAAI;IACJC,MAAM;IACNC,QAAQR,aAAaW,oBAAAA;EACvB;EACA;IACEL,IAAI;IACJC,MAAM;IACNC,QAAQR,aAAaY,YAAAA;IACrBC,UAAU;EACZ;EACA;IACEP,IAAI;IACJC,MAAM;IACNC,QAAQR,aAAac,aAAAA;IACrBD,UAAU;EACZ;EACA;IACEP,IAAI;IACJC,MAAM;IACNC,QAAQR,aAAae,aAAAA;IACrBF,UAAU;EACZ;EACA;IACEP,IAAI;IACJC,MAAM;IACNC,QAAQR,aAAagB,eAAAA;IACrBH,UAAU;EACZ;;",
6
6
  "names": ["removeHeader", "str", "split", "slice", "join", "templates", "id", "name", "source", "echo", "forex", "forexEffect", "chat", "presetId", "chess", "email", "discord"]
7
7
  }
@@ -26,8 +26,8 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
26
26
  mod
27
27
  ));
28
28
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
- var chunk_XKYJYY3T_exports = {};
30
- __export(chunk_XKYJYY3T_exports, {
29
+ var chunk_PPGWSKO4_exports = {};
30
+ __export(chunk_PPGWSKO4_exports, {
31
31
  createDeploy: () => createDeploy,
32
32
  createFormat: () => createFormat,
33
33
  createTemplateSelect: () => createTemplateSelect,
@@ -36,8 +36,8 @@ __export(chunk_XKYJYY3T_exports, {
36
36
  useToolbarAction: () => useToolbarAction,
37
37
  useToolbarState: () => useToolbarState
38
38
  });
39
- module.exports = __toCommonJS(chunk_XKYJYY3T_exports);
40
- var import_chunk_ITAJ3WRW = require("./chunk-ITAJ3WRW.cjs");
39
+ module.exports = __toCommonJS(chunk_PPGWSKO4_exports);
40
+ var import_chunk_I57SKIAA = require("./chunk-I57SKIAA.cjs");
41
41
  var import_chunk_5UH3F7TA = require("./chunk-5UH3F7TA.cjs");
42
42
  var import_react = require("react");
43
43
  var import_functions = require("@dxos/functions");
@@ -343,7 +343,7 @@ var createTemplateSelectGroup = () => {
343
343
  });
344
344
  };
345
345
  var createTemplateSelectActions = () => {
346
- return import_chunk_ITAJ3WRW.templates.map((template) => {
346
+ return import_chunk_I57SKIAA.templates.map((template) => {
347
347
  return (0, import_react_ui_menu3.createMenuAction)(`template--${template.id}`, {
348
348
  label: template.name,
349
349
  value: template.id,
@@ -373,7 +373,7 @@ var createTemplateSelect = () => {
373
373
  };
374
374
  var useTemplateSelectHandler = ({ script }) => {
375
375
  return (0, import_react4.useCallback)((templateId) => {
376
- const template = import_chunk_ITAJ3WRW.templates.find((template2) => template2.id === templateId);
376
+ const template = import_chunk_I57SKIAA.templates.find((template2) => template2.id === templateId);
377
377
  if (template) {
378
378
  script.name = template.name;
379
379
  script.source.target.content = template.source;
@@ -495,4 +495,4 @@ var useToolbarAction = (props) => {
495
495
  useToolbarAction,
496
496
  useToolbarState
497
497
  });
498
- //# sourceMappingURL=chunk-XKYJYY3T.cjs.map
498
+ //# sourceMappingURL=chunk-PPGWSKO4.cjs.map
@@ -31,17 +31,17 @@ __export(node_exports, {
31
31
  DebugPanel: () => import_chunk_K3ZZWVXS.DebugPanel,
32
32
  SCRIPT_PLUGIN: () => import_chunk_5UH3F7TA.SCRIPT_PLUGIN,
33
33
  ScriptCapabilities: () => import_chunk_ALY3N6PW.ScriptCapabilities,
34
- ScriptContainer: () => import_chunk_TOXBGIEI.ScriptContainer,
34
+ ScriptContainer: () => import_chunk_7DFSSJOL.ScriptContainer,
35
35
  ScriptPlugin: () => ScriptPlugin,
36
- ScriptSettings: () => import_chunk_TOXBGIEI.ScriptSettings,
37
- ScriptSettingsPanel: () => import_chunk_TOXBGIEI.ScriptSettingsPanel,
36
+ ScriptSettings: () => import_chunk_7DFSSJOL.ScriptSettings,
37
+ ScriptSettingsPanel: () => import_chunk_7DFSSJOL.ScriptSettingsPanel,
38
38
  meta: () => import_chunk_5UH3F7TA.meta
39
39
  });
40
40
  module.exports = __toCommonJS(node_exports);
41
- var import_chunk_TOXBGIEI = require("./chunk-TOXBGIEI.cjs");
41
+ var import_chunk_7DFSSJOL = require("./chunk-7DFSSJOL.cjs");
42
42
  var import_chunk_ALY3N6PW = require("./chunk-ALY3N6PW.cjs");
43
43
  var import_chunk_K3ZZWVXS = require("./chunk-K3ZZWVXS.cjs");
44
- var import_chunk_DJGLGRQV = require("./chunk-DJGLGRQV.cjs");
44
+ var import_chunk_3ICET6JB = require("./chunk-3ICET6JB.cjs");
45
45
  var import_chunk_5UH3F7TA = require("./chunk-5UH3F7TA.cjs");
46
46
  var import_app_framework = require("@dxos/app-framework");
47
47
  var import_app_framework2 = require("@dxos/app-framework");
@@ -55,9 +55,9 @@ var import_echo = require("@dxos/react-client/echo");
55
55
  var import_app_framework3 = require("@dxos/app-framework");
56
56
  var import_functions2 = require("@dxos/functions");
57
57
  var Compiler = (0, import_app_framework.lazy)(() => import("./compiler-UIBLKJKG.cjs"));
58
- var IntentResolver = (0, import_app_framework.lazy)(() => import("./intent-resolver-NYJFPD5B.cjs"));
59
- var ReactSurface = (0, import_app_framework.lazy)(() => import("./react-surface-EGSE3FMN.cjs"));
60
- var ScriptSettings2 = (0, import_app_framework.lazy)(() => import("./settings-SZFSMSKM.cjs"));
58
+ var IntentResolver = (0, import_app_framework.lazy)(() => import("./intent-resolver-L4WJAAV3.cjs"));
59
+ var ReactSurface = (0, import_app_framework.lazy)(() => import("./react-surface-JRDQP3MO.cjs"));
60
+ var ScriptSettings2 = (0, import_app_framework.lazy)(() => import("./settings-TR2CA4IH.cjs"));
61
61
  var ArtifactDefinition = (0, import_app_framework.lazy)(() => import("./artifact-definition-BXQCFPAH.cjs"));
62
62
  var ScriptEvents;
63
63
  (function(ScriptEvents2) {
@@ -171,8 +171,8 @@ var ScriptPlugin = () => (0, import_app_framework2.definePlugin)(import_chunk_5U
171
171
  activatesOn: import_plugin_client.ClientEvents.SetupSchema,
172
172
  activate: () => (0, import_app_framework2.contributes)(import_plugin_space.SpaceCapabilities.ObjectForm, (0, import_types.defineObjectForm)({
173
173
  objectSchema: import_functions.ScriptType,
174
- formSchema: import_chunk_DJGLGRQV.ScriptAction.CreateScriptSchema,
175
- getIntent: (props, options) => (0, import_app_framework2.createIntent)(import_chunk_DJGLGRQV.ScriptAction.Create, {
174
+ formSchema: import_chunk_3ICET6JB.ScriptAction.CreateScriptSchema,
175
+ getIntent: (props, options) => (0, import_app_framework2.createIntent)(import_chunk_3ICET6JB.ScriptAction.Create, {
176
176
  ...props,
177
177
  space: options.space
178
178
  })
@@ -16,13 +16,13 @@ var __copyProps = (to, from, except, desc) => {
16
16
  return to;
17
17
  };
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
- var intent_resolver_NYJFPD5B_exports = {};
20
- __export(intent_resolver_NYJFPD5B_exports, {
19
+ var intent_resolver_L4WJAAV3_exports = {};
20
+ __export(intent_resolver_L4WJAAV3_exports, {
21
21
  default: () => intent_resolver_default
22
22
  });
23
- module.exports = __toCommonJS(intent_resolver_NYJFPD5B_exports);
24
- var import_chunk_ITAJ3WRW = require("./chunk-ITAJ3WRW.cjs");
25
- var import_chunk_DJGLGRQV = require("./chunk-DJGLGRQV.cjs");
23
+ module.exports = __toCommonJS(intent_resolver_L4WJAAV3_exports);
24
+ var import_chunk_I57SKIAA = require("./chunk-I57SKIAA.cjs");
25
+ var import_chunk_3ICET6JB = require("./chunk-3ICET6JB.cjs");
26
26
  var import_chunk_5UH3F7TA = require("./chunk-5UH3F7TA.cjs");
27
27
  var import_core = require("@octokit/core");
28
28
  var import_app_framework = require("@dxos/app-framework");
@@ -30,9 +30,9 @@ var import_functions = require("@dxos/functions");
30
30
  var import_live_object = require("@dxos/live-object");
31
31
  var import_schema = require("@dxos/schema");
32
32
  var intent_resolver_default = () => (0, import_app_framework.contributes)(import_app_framework.Capabilities.IntentResolver, (0, import_app_framework.createResolver)({
33
- intent: import_chunk_DJGLGRQV.ScriptAction.Create,
33
+ intent: import_chunk_3ICET6JB.ScriptAction.Create,
34
34
  resolve: async ({ name, gistUrl }) => {
35
- let content = import_chunk_ITAJ3WRW.templates[0].source;
35
+ let content = import_chunk_I57SKIAA.templates[0].source;
36
36
  const gistId = gistUrl?.split("/").at(-1);
37
37
  if (gistId) {
38
38
  const octokit = new import_core.Octokit();
@@ -56,4 +56,4 @@ var intent_resolver_default = () => (0, import_app_framework.contributes)(import
56
56
  };
57
57
  }
58
58
  }));
59
- //# sourceMappingURL=intent-resolver-NYJFPD5B.cjs.map
59
+ //# sourceMappingURL=intent-resolver-L4WJAAV3.cjs.map