@pooder/core 2.0.0 → 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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pooder/core",
3
- "version": "2.0.0",
3
+ "version": "2.2.0",
4
4
  "description": "Core logic for Pooder editor",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",
package/src/command.ts CHANGED
@@ -1,10 +1,10 @@
1
- export interface CommandArgSchema {}
2
-
3
- export interface Command {
4
- id: string;
5
- handler: (...args: any[]) => any;
6
- title?: string;
7
- category?: string;
8
- description?: string;
9
- schema?: Record<string, CommandArgSchema>;
10
- }
1
+ export interface CommandArgSchema {}
2
+
3
+ export interface Command {
4
+ id: string;
5
+ handler: (...args: any[]) => any;
6
+ title?: string;
7
+ category?: string;
8
+ description?: string;
9
+ schema?: Record<string, CommandArgSchema>;
10
+ }
package/src/context.ts CHANGED
@@ -1,17 +1,22 @@
1
- import EventBus from "./event";
2
- import { Contribution } from "./contribution";
3
- import { Service } from "./service";
4
- import Disposable from "./disposable";
5
-
6
- interface ExtensionContext {
7
- readonly eventBus: EventBus;
8
- readonly services: {
9
- get<T extends Service>(serviceName: string): T | undefined;
10
- };
11
- readonly contributions: {
12
- get<T>(pointId: string): Contribution<T>[];
13
- register<T>(pointId: string, contribution: Contribution<T>): Disposable;
14
- };
15
- }
16
-
17
- export { ExtensionContext };
1
+ import EventBus from "./event";
2
+ import { Contribution } from "./contribution";
3
+ import { Service, ServiceIdentifier } from "./service";
4
+ import Disposable from "./disposable";
5
+
6
+ interface ExtensionContext {
7
+ readonly eventBus: EventBus;
8
+ readonly services: {
9
+ get<T extends Service>(identifier: ServiceIdentifier<T>): T | undefined;
10
+ getOrThrow<T extends Service>(
11
+ identifier: ServiceIdentifier<T>,
12
+ errorMessage?: string,
13
+ ): T;
14
+ has(identifier: ServiceIdentifier<Service>): boolean;
15
+ };
16
+ readonly contributions: {
17
+ get<T>(pointId: string): Contribution<T>[];
18
+ register<T>(pointId: string, contribution: Contribution<T>): Disposable;
19
+ };
20
+ }
21
+
22
+ export { ExtensionContext };
@@ -1,12 +1,12 @@
1
- export * from "./points";
2
- export * from "./registry";
3
-
4
- export interface ContributionMetadata {
5
- name: string;
6
- extensionId: string;
7
- }
8
- export interface Contribution<T = any> {
9
- id: string;
10
- data: T;
11
- metadata?: Partial<ContributionMetadata>;
12
- }
1
+ export * from "./points";
2
+ export * from "./registry";
3
+
4
+ export interface ContributionMetadata {
5
+ name: string;
6
+ extensionId: string;
7
+ }
8
+ export interface Contribution<T = any> {
9
+ id: string;
10
+ data: T;
11
+ metadata?: Partial<ContributionMetadata>;
12
+ }
@@ -17,12 +17,36 @@ export interface CommandContribution {
17
17
  /**
18
18
  * Tool Contribution Data Definition
19
19
  */
20
+ export type ToolInteraction = "instant" | "session" | "hybrid";
21
+
22
+ export type ToolSessionLeavePolicy = "block" | "commit" | "rollback";
23
+
24
+ export interface ToolCommandBindings {
25
+ execute?: string;
26
+ begin?: string;
27
+ validate?: string;
28
+ commit?: string;
29
+ rollback?: string;
30
+ reset?: string;
31
+ }
32
+
20
33
  export interface ToolContribution {
21
34
  id: string;
22
35
  name: string;
23
- description: string;
24
- parameters?: Record<string, any>; // JSON Schema for parameters
25
- execute: (...args: any[]) => Promise<any>;
36
+ description?: string;
37
+ icon?: string;
38
+ interaction: ToolInteraction;
39
+ parameters?: Record<string, any>;
40
+ commands?: ToolCommandBindings;
41
+ view?: {
42
+ id?: string;
43
+ type?: "sidebar" | "panel" | "editor" | "dialog";
44
+ location?: string;
45
+ };
46
+ session?: {
47
+ autoBegin?: boolean;
48
+ leavePolicy?: ToolSessionLeavePolicy;
49
+ };
26
50
  }
27
51
 
28
52
  /**
@@ -1,118 +1,118 @@
1
- import { Contribution, ContributionPoint, ContributionPointIds } from "./index";
2
- import Disposable from "../disposable";
3
-
4
- export class ContributionRegistry {
5
- private points: Map<string, ContributionPoint> = new Map();
6
- private contributions = {
7
- byId: new Map<string, Contribution>(),
8
- byPointId: new Map<string, Contribution[]>(),
9
- };
10
-
11
- /**
12
- * Register a new contribution point
13
- */
14
- registerPoint<T>(point: ContributionPoint<T>): void {
15
- if (this.points.has(point.id)) {
16
- console.warn(
17
- `Contribution point ${point.id} already exists. Overwriting definitions may cause issues.`,
18
- );
19
- }
20
- this.points.set(point.id, point);
21
- if (!this.contributions.byPointId.has(point.id)) {
22
- this.contributions.byPointId.set(point.id, []);
23
- }
24
- }
25
-
26
- /**
27
- * Register a contribution to a specific point
28
- * @returns Disposable to unregister the contribution
29
- */
30
- register<T>(pointId: string, contribution: Contribution<T>): Disposable {
31
- if (this.contributions.byId.has(contribution.id)) {
32
- console.warn(
33
- `Contribution with ID "${contribution.id}" is already registered. Overwriting.`,
34
- );
35
- // We could choose to throw, or overwrite. Let's overwrite for now but warn.
36
- // If we overwrite, we should probably remove the old one from the list first to avoid duplicates.
37
- this.unregister(pointId, contribution.id);
38
- }
39
-
40
- if (!this.points.has(pointId)) {
41
- console.warn(
42
- `Contribution point ${pointId} does not exist. The contribution ${contribution.id} will be queued but may not be valid.`,
43
- );
44
- if (!this.contributions.byPointId.has(pointId)) {
45
- this.contributions.byPointId.set(pointId, []);
46
- }
47
- }
48
-
49
- const point = this.points.get(pointId);
50
- if (point?.validate) {
51
- try {
52
- if (!point.validate(contribution.data)) {
53
- console.error(
54
- `Contribution ${contribution.id} failed validation for point ${pointId}.`,
55
- );
56
- return { dispose: () => {} };
57
- }
58
- } catch (e) {
59
- console.error(
60
- `Validation error for contribution ${contribution.id}:`,
61
- e,
62
- );
63
- return { dispose: () => {} };
64
- }
65
- }
66
-
67
- const arr = this.contributions.byPointId.get(pointId)!;
68
-
69
- arr.push(contribution);
70
- this.contributions.byId.set(contribution.id, contribution);
71
-
72
- // Auto-register if this is a contribution point contribution
73
- if (pointId === ContributionPointIds.CONTRIBUTIONS) {
74
- this.registerPoint(contribution.data as ContributionPoint);
75
- }
76
-
77
- return {
78
- dispose: () => {
79
- this.unregister(pointId, contribution.id);
80
- },
81
- };
82
- }
83
-
84
- /**
85
- * Get all contributions for a given point
86
- */
87
- get<T>(pointId: string): Contribution<T>[] {
88
- return Array.from(
89
- this.contributions.byPointId.get(pointId)?.values() || [],
90
- ) as Contribution<T>[];
91
- }
92
-
93
- /**
94
- * Get a specific contribution by ID
95
- */
96
- getById<T>(id: string): Contribution<T> | undefined {
97
- return this.contributions.byId.get(id) as Contribution<T> | undefined;
98
- }
99
-
100
- /**
101
- * Get the contribution point definition
102
- */
103
- getPoint(pointId: string): ContributionPoint | undefined {
104
- return this.points.get(pointId);
105
- }
106
-
107
- /**
108
- * Unregister a contribution
109
- */
110
- private unregister(pointId: string, contributionId: string): void {
111
- const arr = this.contributions.byPointId.get(pointId);
112
- arr?.splice(
113
- arr.findIndex((c) => c.id === contributionId),
114
- 1,
115
- );
116
- this.contributions.byId.delete(contributionId);
117
- }
118
- }
1
+ import { Contribution, ContributionPoint, ContributionPointIds } from "./index";
2
+ import Disposable from "../disposable";
3
+
4
+ export class ContributionRegistry {
5
+ private points: Map<string, ContributionPoint> = new Map();
6
+ private contributions = {
7
+ byId: new Map<string, Contribution>(),
8
+ byPointId: new Map<string, Contribution[]>(),
9
+ };
10
+
11
+ /**
12
+ * Register a new contribution point
13
+ */
14
+ registerPoint<T>(point: ContributionPoint<T>): void {
15
+ if (this.points.has(point.id)) {
16
+ console.warn(
17
+ `Contribution point ${point.id} already exists. Overwriting definitions may cause issues.`,
18
+ );
19
+ }
20
+ this.points.set(point.id, point);
21
+ if (!this.contributions.byPointId.has(point.id)) {
22
+ this.contributions.byPointId.set(point.id, []);
23
+ }
24
+ }
25
+
26
+ /**
27
+ * Register a contribution to a specific point
28
+ * @returns Disposable to unregister the contribution
29
+ */
30
+ register<T>(pointId: string, contribution: Contribution<T>): Disposable {
31
+ if (this.contributions.byId.has(contribution.id)) {
32
+ console.warn(
33
+ `Contribution with ID "${contribution.id}" is already registered. Overwriting.`,
34
+ );
35
+ // We could choose to throw, or overwrite. Let's overwrite for now but warn.
36
+ // If we overwrite, we should probably remove the old one from the list first to avoid duplicates.
37
+ this.unregister(pointId, contribution.id);
38
+ }
39
+
40
+ if (!this.points.has(pointId)) {
41
+ console.warn(
42
+ `Contribution point ${pointId} does not exist. The contribution ${contribution.id} will be queued but may not be valid.`,
43
+ );
44
+ if (!this.contributions.byPointId.has(pointId)) {
45
+ this.contributions.byPointId.set(pointId, []);
46
+ }
47
+ }
48
+
49
+ const point = this.points.get(pointId);
50
+ if (point?.validate) {
51
+ try {
52
+ if (!point.validate(contribution.data)) {
53
+ console.error(
54
+ `Contribution ${contribution.id} failed validation for point ${pointId}.`,
55
+ );
56
+ return { dispose: () => {} };
57
+ }
58
+ } catch (e) {
59
+ console.error(
60
+ `Validation error for contribution ${contribution.id}:`,
61
+ e,
62
+ );
63
+ return { dispose: () => {} };
64
+ }
65
+ }
66
+
67
+ const arr = this.contributions.byPointId.get(pointId)!;
68
+
69
+ arr.push(contribution);
70
+ this.contributions.byId.set(contribution.id, contribution);
71
+
72
+ // Auto-register if this is a contribution point contribution
73
+ if (pointId === ContributionPointIds.CONTRIBUTIONS) {
74
+ this.registerPoint(contribution.data as ContributionPoint);
75
+ }
76
+
77
+ return {
78
+ dispose: () => {
79
+ this.unregister(pointId, contribution.id);
80
+ },
81
+ };
82
+ }
83
+
84
+ /**
85
+ * Get all contributions for a given point
86
+ */
87
+ get<T>(pointId: string): Contribution<T>[] {
88
+ return Array.from(
89
+ this.contributions.byPointId.get(pointId)?.values() || [],
90
+ ) as Contribution<T>[];
91
+ }
92
+
93
+ /**
94
+ * Get a specific contribution by ID
95
+ */
96
+ getById<T>(id: string): Contribution<T> | undefined {
97
+ return this.contributions.byId.get(id) as Contribution<T> | undefined;
98
+ }
99
+
100
+ /**
101
+ * Get the contribution point definition
102
+ */
103
+ getPoint(pointId: string): ContributionPoint | undefined {
104
+ return this.points.get(pointId);
105
+ }
106
+
107
+ /**
108
+ * Unregister a contribution
109
+ */
110
+ private unregister(pointId: string, contributionId: string): void {
111
+ const arr = this.contributions.byPointId.get(pointId);
112
+ arr?.splice(
113
+ arr.findIndex((c) => c.id === contributionId),
114
+ 1,
115
+ );
116
+ this.contributions.byId.delete(contributionId);
117
+ }
118
+ }
package/src/disposable.ts CHANGED
@@ -1,3 +1,3 @@
1
- export default interface Disposable {
2
- dispose(): void;
3
- }
1
+ export default interface Disposable {
2
+ dispose(): void;
3
+ }