@opencode/plugin 2.1.3 → 2.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (55) hide show
  1. package/dist/effect/event.d.ts +8 -2
  2. package/dist/effect/plugin.d.ts +4 -1
  3. package/dist/effect/session.d.ts +2 -2
  4. package/dist/effect/vcs.d.ts +1 -0
  5. package/dist/gui/browser.d.ts +36 -0
  6. package/dist/gui/browser.js +3 -0
  7. package/dist/gui/context.d.ts +271 -0
  8. package/dist/gui/core.d.ts +560 -0
  9. package/dist/gui/core.js +86 -0
  10. package/dist/gui/declarations.d.ts +24 -0
  11. package/dist/gui/declarations.js +0 -0
  12. package/dist/gui/file.d.ts +122 -0
  13. package/dist/gui/file.js +7 -0
  14. package/dist/gui/host-apis.d.ts +1925 -0
  15. package/dist/gui/host-apis.js +0 -0
  16. package/dist/gui/icon-name.d.ts +2 -0
  17. package/dist/gui/icon-name.js +1 -0
  18. package/dist/gui/index.d.ts +7 -0
  19. package/dist/gui/index.js +6 -0
  20. package/dist/gui/internal.d.ts +44 -0
  21. package/dist/gui/internal.js +33 -0
  22. package/dist/gui/main.d.ts +279 -0
  23. package/dist/gui/main.js +20 -0
  24. package/dist/gui/modules.d.ts +15 -0
  25. package/dist/gui/modules.js +30 -0
  26. package/dist/gui/plugin.d.ts +86 -0
  27. package/dist/gui/plugin.js +9 -0
  28. package/dist/gui/reactive.d.ts +93 -0
  29. package/dist/gui/reactive.js +130 -0
  30. package/dist/gui/registries.d.ts +783 -0
  31. package/dist/gui/registries.js +110 -0
  32. package/dist/gui/review.d.ts +73 -0
  33. package/dist/gui/review.js +3 -0
  34. package/dist/gui/scope.d.ts +64 -0
  35. package/dist/gui/scope.js +85 -0
  36. package/dist/gui/solid.d.ts +99 -0
  37. package/dist/gui/solid.js +74 -0
  38. package/dist/gui/vite.d.ts +24 -0
  39. package/dist/gui/vite.js +49 -0
  40. package/dist/host.d.ts +12 -1
  41. package/dist/host.js +34 -2
  42. package/dist/permission.d.ts +0 -1
  43. package/dist/promise/adapter.js +14 -1
  44. package/dist/promise/agent.d.ts +4 -4
  45. package/dist/promise/event.d.ts +6 -2
  46. package/dist/promise/mcp.d.ts +4 -4
  47. package/dist/promise/model.d.ts +4 -4
  48. package/dist/promise/plugin.d.ts +4 -1
  49. package/dist/promise/provider.d.ts +3 -3
  50. package/dist/promise/session.d.ts +2 -2
  51. package/dist/promise/skill.d.ts +4 -4
  52. package/dist/runtime-modules.js +3 -1
  53. package/package.json +68 -17
  54. package/dist/promise/types.d.ts +0 -3
  55. /package/dist/{promise/types.js → gui/context.js} +0 -0
@@ -0,0 +1,130 @@
1
+ import { createMemo, createRenderEffect, createRoot, createSignal, getOwner, on, onCleanup, runWithOwner, untrack, } from "solid-js";
2
+ import { createStore } from "solid-js/store";
3
+ import { isLiveAccessor, LifetimeContext } from "./internal.js";
4
+ import { usePlugin } from "./solid.js";
5
+ /**
6
+ * Runs `fn` once per key, like `<Show keyed>`: each active generation of a `Live` accessor, or each identity of a plain
7
+ * accessor's value. Each run, and each run of `otherwise` while there is no key, has its own owner: its
8
+ * `onCleanup` and its registrations end with it. This is the way plugin code runs side effects reactively; use it
9
+ * only to sync with something outside Solid (the DOM, a widget, an Ipc subscription), never to set state from state.
10
+ * Call it under an owner: in setup, or in a component.
11
+ *
12
+ * A plain accessor that builds an object, such as `{ directory, tab }`, gives a new key each time it reads, even when
13
+ * every field is unchanged; pass `equals` to compare the fields that matter instead.
14
+ *
15
+ * @param source - A `Live` accessor from `ctx.use(token)`, or any accessor.
16
+ * @param fn - Runs once per key with the source's value. It runs untracked.
17
+ * @param options - What runs while there is no key, and when a plain accessor's new value is the same key.
18
+ *
19
+ * @example
20
+ * ```ts
21
+ * // Each provider generation: listen to its events; the listener ends with the generation.
22
+ * createKeyed(ctx.use(Changes), (changes) => changes.watch(screen, "files"))
23
+ * // A plain accessor: the picker runs while the tab is visible, and `otherwise` while it is not.
24
+ * createKeyed(visible, startPicker, { otherwise: endPicker })
25
+ * // An object source: lists again only when the directory or the tab changes.
26
+ * createKeyed(() => ({ directory: file.root, tab: tab() }), (key) => void list(key), {
27
+ * equals: (previous, next) => previous.directory === next.directory && previous.tab === next.tab,
28
+ * })
29
+ * ```
30
+ */
31
+ export function createKeyed(source, fn, options) {
32
+ const read = source;
33
+ const same = options?.equals;
34
+ const active = isLiveAccessor(read)
35
+ ? createMemo(() => {
36
+ const value = read();
37
+ return value.status === "active" ? value : undefined;
38
+ }, undefined,
39
+ // A Live source changes generation, not merely object, when its provider restarts.
40
+ { equals: (previous, next) => previous?.generation === next?.generation })
41
+ : createMemo(() => {
42
+ const value = read();
43
+ return value === undefined || value === null || value === false ? undefined : { value };
44
+ }, undefined, {
45
+ equals: (previous, next) => {
46
+ if (previous === undefined || next === undefined)
47
+ return previous === next;
48
+ // SAFETY: both values come from `source` while it is active, which is what `KeyedValue<S>` describes.
49
+ return (previous.value === next.value || !!same?.(previous.value, next.value));
50
+ },
51
+ });
52
+ createRenderEffect(on(active, (current) => {
53
+ // SAFETY: `current.value` comes from `source`, and `KeyedValue<S>` is what that source gives while active.
54
+ const run = current === undefined ? options?.otherwise : () => fn(current.value);
55
+ if (!run)
56
+ return;
57
+ // A root per run, so a registration made through a captured owner after the run ended disposes at once.
58
+ const lifetime = { ended: false };
59
+ const scope = createRoot((dispose) => ({ owner: getOwner(), dispose }));
60
+ onCleanup(() => {
61
+ lifetime.ended = true;
62
+ scope.dispose();
63
+ });
64
+ if (scope.owner)
65
+ scope.owner.context = { ...scope.owner.context, [LifetimeContext.id]: lifetime };
66
+ runWithOwner(scope.owner, run);
67
+ }));
68
+ }
69
+ /**
70
+ * The latest result of `fetch` for the source's current value. Never suspends. A new value aborts the previous request
71
+ * through its signal and drops its reply; so does the owner going away. `latest` keeps the last result meanwhile.
72
+ * Call it under an owner: in setup, or in a component.
73
+ *
74
+ * @param source - What to fetch for: a `Live` accessor from `ctx.use(token)`, or any accessor (see `KeyedValue`).
75
+ * @param fetch - Fetches for one value. Pass `signal` on to the request.
76
+ * @returns A store; read its fields in render or in a memo.
77
+ *
78
+ * @example
79
+ * ```ts
80
+ * const active = createLatest(ctx.use(Pairing), (pairing, signal) => pairing.screenActive({ signal }))
81
+ * const awake = () => active.latest ?? false
82
+ * ```
83
+ */
84
+ export function createLatest(source, fetch) {
85
+ const [state, setState] = createStore({
86
+ latest: undefined,
87
+ loading: false,
88
+ error: undefined,
89
+ });
90
+ createKeyed(source, (value) => {
91
+ const controller = new AbortController();
92
+ onCleanup(() => controller.abort());
93
+ setState({ loading: true, error: undefined });
94
+ void Promise.try(() => fetch(value, controller.signal)).then((latest) => {
95
+ if (!controller.signal.aborted)
96
+ setState({ latest, loading: false, error: undefined });
97
+ }, (cause) => {
98
+ if (!controller.signal.aborted)
99
+ setState({ loading: false, error: cause });
100
+ });
101
+ }, { otherwise: () => setState({ loading: false, error: undefined }) });
102
+ return state;
103
+ }
104
+ /**
105
+ * State that returns to `initial` on every routing visit of the current session (`MountedSession.visit`), e.g. a
106
+ * selection to forget when the user goes Home and back. Call it inside a contribution or setup: it reads
107
+ * `usePlugin()`.
108
+ *
109
+ * @param initial - The value at the start of every visit.
110
+ * @returns The value accessor and its setter, like `createSignal`.
111
+ *
112
+ * @example
113
+ * ```ts
114
+ * const [expanded, setExpanded] = createVisitState(false)
115
+ * ```
116
+ */
117
+ export function createVisitState(initial) {
118
+ const sessions = usePlugin().sessions;
119
+ const visit = () => sessions.current()?.visit;
120
+ const [state, setState] = createSignal({
121
+ visit: undefined,
122
+ value: initial,
123
+ });
124
+ const value = () => {
125
+ const current = state();
126
+ return current.visit !== undefined && current.visit === visit() ? current.value : initial;
127
+ };
128
+ const set = (next) => void setState({ visit: untrack(visit), value: next });
129
+ return [value, set];
130
+ }