@jataware/beaker-client 2.0.0-b.1
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/README.md +24 -0
- package/dist/extension.d.ts +21 -0
- package/dist/extension.js +3 -0
- package/dist/history.d.ts +39 -0
- package/dist/history.js +16 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +10 -0
- package/dist/notebook.d.ts +192 -0
- package/dist/notebook.js +690 -0
- package/dist/render.d.ts +38 -0
- package/dist/render.js +84 -0
- package/dist/session.d.ts +166 -0
- package/dist/session.js +418 -0
- package/dist/util.d.ts +50 -0
- package/dist/util.js +112 -0
- package/package.json +39 -0
- package/src/extension.ts +34 -0
- package/src/history.ts +61 -0
- package/src/index.ts +12 -0
- package/src/notebook.ts +949 -0
- package/src/render.ts +121 -0
- package/src/session.ts +504 -0
- package/src/util.ts +173 -0
package/README.md
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# beaker-ts typescript library
|
|
2
|
+
|
|
3
|
+
Beaker-ts is a typescript library that simplifies working with Beaker in the
|
|
4
|
+
browser. Highlights of what beaker-ts provides include:
|
|
5
|
+
|
|
6
|
+
* Easy creation of Beaker sessions
|
|
7
|
+
* Connecting to an existing Beaker kernel or spinning up a new one
|
|
8
|
+
* Ability to send/recieve messages directly to the Beaker kernel
|
|
9
|
+
* Kernel status tracking
|
|
10
|
+
* A light-weight reactive notebook
|
|
11
|
+
* Interfaces and classes for all standard Jupyter cells
|
|
12
|
+
* A new Beaker "LLM Query" cell for interactions with the LLM agent
|
|
13
|
+
* Full rendering of types registered with Jupyter
|
|
14
|
+
* Exportable to a standard Jupyter .ipynb file
|
|
15
|
+
* Tested to be reactive in React and Vue frameworks
|
|
16
|
+
* Session history tracking
|
|
17
|
+
* Tracks all actions taken in a notebook (in progress)
|
|
18
|
+
* Savable/Exportable to JSON (coming soon)
|
|
19
|
+
* Ability to fully roll-back a notebook to a previous point (planned feature)
|
|
20
|
+
|
|
21
|
+
It is recommended to use the beaker-ts library to create and edit your Beaker
|
|
22
|
+
sessions and notebooks.
|
|
23
|
+
|
|
24
|
+
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { JSONObject, PartialJSONObject } from '@lumino/coreutils';
|
|
2
|
+
import { IBeakerShellMessage } from './notebook';
|
|
3
|
+
import { IBeakerFuture } from './util';
|
|
4
|
+
import * as messages from '@jupyterlab/services/lib/kernel/messages';
|
|
5
|
+
import * as nbformat from '@jupyterlab/nbformat';
|
|
6
|
+
declare module "@jupyterlab/services/lib/kernel" {
|
|
7
|
+
interface KernelConnection {
|
|
8
|
+
sendBeakerMessage(messageType: string, content: JSONObject, messageId: string, expectReply: boolean, disposeOnDone: boolean): IBeakerFuture;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
declare module "@jupyterlab/services/lib/kernel/messages" {
|
|
12
|
+
function createMessage<T extends IBeakerShellMessage>(options: messages.IOptions<T>): T;
|
|
13
|
+
}
|
|
14
|
+
declare module '@jupyterlab/nbformat' {
|
|
15
|
+
interface IBaseOutput extends PartialJSONObject {
|
|
16
|
+
output_type: string;
|
|
17
|
+
metadata?: nbformat.OutputMetadata;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
declare const _default: {};
|
|
21
|
+
export default _default;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import * as nbformat from '@jupyterlab/nbformat';
|
|
2
|
+
export interface IBeakerHistoryEvent {
|
|
3
|
+
kernel_id: string;
|
|
4
|
+
kernel_slug: string;
|
|
5
|
+
context_slug: string;
|
|
6
|
+
creation_time: Date;
|
|
7
|
+
}
|
|
8
|
+
export interface IBeakerHistoryExecutionEvent extends IBeakerHistoryEvent {
|
|
9
|
+
cell_id: string;
|
|
10
|
+
execution_time: Date;
|
|
11
|
+
execution_duration: number;
|
|
12
|
+
silent: boolean;
|
|
13
|
+
execution_id: number;
|
|
14
|
+
source: nbformat.MultilineString;
|
|
15
|
+
result: any;
|
|
16
|
+
stdin: nbformat.MultilineString;
|
|
17
|
+
stderr: nbformat.MultilineString;
|
|
18
|
+
success: boolean;
|
|
19
|
+
}
|
|
20
|
+
export interface IBeakerHistoryQueryEvent extends IBeakerHistoryEvent {
|
|
21
|
+
cell_id: string;
|
|
22
|
+
execution_time: Date;
|
|
23
|
+
execution_duration: number;
|
|
24
|
+
source: nbformat.MultilineString;
|
|
25
|
+
thoughts: string[];
|
|
26
|
+
result: nbformat.MultilineString;
|
|
27
|
+
}
|
|
28
|
+
export type BeakerHistoryEvent = IBeakerHistoryExecutionEvent | IBeakerHistoryQueryEvent;
|
|
29
|
+
export interface IBeakerHistory {
|
|
30
|
+
sessionId: string;
|
|
31
|
+
events: IBeakerHistoryEvent[];
|
|
32
|
+
}
|
|
33
|
+
export declare class BeakerHistory implements IBeakerHistory {
|
|
34
|
+
constructor(sessionId: string);
|
|
35
|
+
addEvent(event: BeakerHistoryEvent): void;
|
|
36
|
+
clear(): void;
|
|
37
|
+
sessionId: string;
|
|
38
|
+
events: IBeakerHistoryEvent[];
|
|
39
|
+
}
|
package/dist/history.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
class BeakerHistory {
|
|
2
|
+
constructor(sessionId) {
|
|
3
|
+
this.sessionId = sessionId;
|
|
4
|
+
this.events = [];
|
|
5
|
+
}
|
|
6
|
+
addEvent(event) {
|
|
7
|
+
this.events.push(event);
|
|
8
|
+
}
|
|
9
|
+
clear() {
|
|
10
|
+
this.events.splice(0, this.events.splice.length);
|
|
11
|
+
}
|
|
12
|
+
sessionId;
|
|
13
|
+
events;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export { BeakerHistory };
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import extension from './extension.js';
|
|
2
|
+
export { BeakerSession } from './session.js';
|
|
3
|
+
export { BeakerBaseCell, BeakerCodeCell, BeakerMarkdownCell, BeakerNotebook, BeakerNotebookContent, BeakerQueryCell, BeakerRawCell } from './notebook.js';
|
|
4
|
+
export { BeakerRenderer, JupyterMimeRenderer, MimeRenderer } from './render.js';
|
|
5
|
+
export { BeakerCellFuture, BeakerCellFutures, KernelState, createMessageId } from './util.js';
|
|
6
|
+
export { BeakerHistory } from './history.js';
|
|
7
|
+
|
|
8
|
+
if (extension === void 0) {
|
|
9
|
+
throw new Error("Unable to extend Jupyterlab types");
|
|
10
|
+
}
|
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
import { PartialJSONValue, PartialJSONObject } from '@lumino/coreutils';
|
|
2
|
+
import { BeakerSession } from './session';
|
|
3
|
+
import { IBeakerFuture, BeakerCellFuture } from './util';
|
|
4
|
+
import * as nbformat from '@jupyterlab/nbformat';
|
|
5
|
+
import * as messages from '@jupyterlab/services/lib/kernel/messages';
|
|
6
|
+
export interface IBeakerHeader extends messages.IHeader<messages.MessageType> {
|
|
7
|
+
msg_type: any;
|
|
8
|
+
}
|
|
9
|
+
export interface IBeakerShellMessage extends messages.IShellMessage {
|
|
10
|
+
header: IBeakerHeader;
|
|
11
|
+
channel: "shell";
|
|
12
|
+
content: any;
|
|
13
|
+
parent_header: any;
|
|
14
|
+
}
|
|
15
|
+
export interface IBeakerIOPubMessage extends messages.IIOPubMessage {
|
|
16
|
+
header: IBeakerHeader;
|
|
17
|
+
channel: "iopub";
|
|
18
|
+
content: any;
|
|
19
|
+
}
|
|
20
|
+
export interface IBeakerAnyMessage extends messages.IMessage {
|
|
21
|
+
header: IBeakerHeader;
|
|
22
|
+
content: any;
|
|
23
|
+
}
|
|
24
|
+
export type BeakerCellStatus = messages.Status | "awaiting_input";
|
|
25
|
+
export type BeakerCellExecutionStatus = IBeakerCellExecutionStatusPlain | IBeakerCellExecutionStatusPending | IBeakerCellExecutionStatusOk | IBeakerCellExecutionStatusError;
|
|
26
|
+
export interface IBeakerCellExecutionStatusPlain {
|
|
27
|
+
status: "none" | "modified" | "abort";
|
|
28
|
+
}
|
|
29
|
+
export interface IBeakerCellExecutionStatusPending {
|
|
30
|
+
status: "pending";
|
|
31
|
+
checkpoint_index?: number;
|
|
32
|
+
}
|
|
33
|
+
export interface IBeakerCellExecutionStatusOk {
|
|
34
|
+
status: "ok";
|
|
35
|
+
checkpoint_index?: number;
|
|
36
|
+
}
|
|
37
|
+
export interface IBeakerCellExecutionStatusError {
|
|
38
|
+
status: "error";
|
|
39
|
+
ename: string;
|
|
40
|
+
evalue: string;
|
|
41
|
+
traceback: string[];
|
|
42
|
+
}
|
|
43
|
+
export type BeakerCellType = nbformat.CellType | string | 'query';
|
|
44
|
+
export declare class BeakerBaseCell implements nbformat.IBaseCell {
|
|
45
|
+
static IPYNB_KEYS: string[];
|
|
46
|
+
[key: string]: any;
|
|
47
|
+
id: string;
|
|
48
|
+
cell_type: BeakerCellType;
|
|
49
|
+
metadata: Partial<nbformat.ICellMetadata>;
|
|
50
|
+
source: nbformat.MultilineString;
|
|
51
|
+
status: BeakerCellStatus;
|
|
52
|
+
children: BeakerBaseCell[];
|
|
53
|
+
constructor(content: Partial<nbformat.IBaseCell>);
|
|
54
|
+
static generateId(): string;
|
|
55
|
+
fromJSON(obj: any): void;
|
|
56
|
+
toJSON(): this;
|
|
57
|
+
fromIPynb(obj: any): void;
|
|
58
|
+
toIPynb(): nbformat.IBaseCell | nbformat.IBaseCell[];
|
|
59
|
+
}
|
|
60
|
+
type BeakerQueryTextEventType = "response" | "user_question" | "user_answer" | "abort";
|
|
61
|
+
export interface IBeakerQueryTextEvent extends PartialJSONObject {
|
|
62
|
+
type: BeakerQueryTextEventType;
|
|
63
|
+
content: string;
|
|
64
|
+
}
|
|
65
|
+
type BeakerQueryCellEventType = "code_cell";
|
|
66
|
+
export interface IBeakerQueryCellEvent extends PartialJSONObject {
|
|
67
|
+
type: BeakerQueryCellEventType;
|
|
68
|
+
content: {
|
|
69
|
+
cell_id: string;
|
|
70
|
+
parent_id: string;
|
|
71
|
+
metadata: PartialJSONObject;
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
type BeakerQueryErrorEventType = "error";
|
|
75
|
+
export interface IBeakerQueryErrorEvent extends PartialJSONObject {
|
|
76
|
+
type: BeakerQueryErrorEventType;
|
|
77
|
+
content: {
|
|
78
|
+
ename: string;
|
|
79
|
+
evalue: string;
|
|
80
|
+
traceback: string[];
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
export type BeakerToolCallState = "pending" | "running" | "done" | "error" | "cancelled";
|
|
84
|
+
export interface IBeakerToolCall extends PartialJSONObject {
|
|
85
|
+
tool_call_id: string;
|
|
86
|
+
tool_name: string;
|
|
87
|
+
tool_input: any;
|
|
88
|
+
state: BeakerToolCallState;
|
|
89
|
+
started_at?: string;
|
|
90
|
+
ended_at?: string;
|
|
91
|
+
output_preview?: string;
|
|
92
|
+
output_truncated?: boolean;
|
|
93
|
+
error?: {
|
|
94
|
+
ename: string;
|
|
95
|
+
evalue: string;
|
|
96
|
+
traceback?: string[];
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
type BeakerQueryThoughtType = "thought";
|
|
100
|
+
export interface IBeakerQueryThoughtEvent extends PartialJSONObject {
|
|
101
|
+
type: BeakerQueryThoughtType;
|
|
102
|
+
content: {
|
|
103
|
+
thought: string;
|
|
104
|
+
thought_id: string;
|
|
105
|
+
tool_calls: IBeakerToolCall[];
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
export type BeakerQueryEventType = BeakerQueryTextEventType | BeakerQueryCellEventType | BeakerQueryErrorEventType | BeakerQueryThoughtType;
|
|
109
|
+
export type BeakerQueryEvent = IBeakerQueryTextEvent | IBeakerQueryCellEvent | IBeakerQueryErrorEvent | IBeakerQueryThoughtEvent;
|
|
110
|
+
export interface IQueryCell extends nbformat.IBaseCell {
|
|
111
|
+
cell_type: 'query';
|
|
112
|
+
events: BeakerQueryEvent[];
|
|
113
|
+
}
|
|
114
|
+
export declare class BeakerRawCell extends BeakerBaseCell implements nbformat.IRawCell {
|
|
115
|
+
cell_type: "raw";
|
|
116
|
+
attachments?: nbformat.IAttachments;
|
|
117
|
+
metadata: Partial<nbformat.IRawCellMetadata>;
|
|
118
|
+
constructor(content: nbformat.ICell);
|
|
119
|
+
execute(session: BeakerSession): IBeakerFuture | null;
|
|
120
|
+
}
|
|
121
|
+
export declare class BeakerCodeCell extends BeakerBaseCell implements nbformat.ICodeCell {
|
|
122
|
+
cell_type: "code";
|
|
123
|
+
outputs: nbformat.IOutput[];
|
|
124
|
+
execution_count: nbformat.ExecutionCount;
|
|
125
|
+
metadata: Partial<nbformat.ICodeCellMetadata>;
|
|
126
|
+
last_execution?: BeakerCellExecutionStatus;
|
|
127
|
+
busy?: boolean;
|
|
128
|
+
constructor(content: Partial<nbformat.ICell>);
|
|
129
|
+
execute(session: BeakerSession, syntheticFuture?: BeakerCellFuture): IBeakerFuture | null;
|
|
130
|
+
rollback(session: BeakerSession): IBeakerFuture | null;
|
|
131
|
+
reset_execution_state(): void;
|
|
132
|
+
toIPynb(): nbformat.ICodeCell;
|
|
133
|
+
}
|
|
134
|
+
export declare class BeakerMarkdownCell extends BeakerBaseCell implements nbformat.IMarkdownCell {
|
|
135
|
+
static IPYNB_KEYS: string[];
|
|
136
|
+
cell_type: "markdown";
|
|
137
|
+
attachments?: nbformat.IAttachments;
|
|
138
|
+
constructor(content: Partial<nbformat.ICell>);
|
|
139
|
+
execute(session: BeakerSession): IBeakerFuture | null;
|
|
140
|
+
toIPynb(): nbformat.IBaseCell | nbformat.IBaseCell[];
|
|
141
|
+
}
|
|
142
|
+
export declare class BeakerQueryCell extends BeakerBaseCell implements IQueryCell {
|
|
143
|
+
cell_type: "query";
|
|
144
|
+
events: BeakerQueryEvent[];
|
|
145
|
+
_current_input_request_message?: messages.IInputRequestMsg;
|
|
146
|
+
_toolCallIndex: Map<string, {
|
|
147
|
+
eventIndex: number;
|
|
148
|
+
slot: number;
|
|
149
|
+
}>;
|
|
150
|
+
constructor(content: Partial<nbformat.ICell>);
|
|
151
|
+
execute(session: BeakerSession, includeNotebookState?: boolean): IBeakerFuture | null;
|
|
152
|
+
respond(response: string, session: BeakerSession): void;
|
|
153
|
+
toMultipleCells(): [BeakerMarkdownCell, ...BeakerBaseCell[]];
|
|
154
|
+
fromIPynb(obj: any): void;
|
|
155
|
+
toIPynb(): [nbformat.IMarkdownCell, ...nbformat.IBaseCell[]];
|
|
156
|
+
}
|
|
157
|
+
export type IBeakerCell = BeakerCodeCell | BeakerMarkdownCell | BeakerRawCell | nbformat.IUnrecognizedCell;
|
|
158
|
+
export declare class BeakerNotebookContent implements nbformat.INotebookContent {
|
|
159
|
+
[key: string]: PartialJSONValue;
|
|
160
|
+
nbformat: number;
|
|
161
|
+
nbformat_minor: number;
|
|
162
|
+
metadata: nbformat.INotebookMetadata;
|
|
163
|
+
cells: BeakerBaseCell[];
|
|
164
|
+
}
|
|
165
|
+
export declare class BeakerNotebook {
|
|
166
|
+
constructor();
|
|
167
|
+
toJSON(): {
|
|
168
|
+
[key: string]: PartialJSONValue;
|
|
169
|
+
nbformat: number;
|
|
170
|
+
nbformat_minor: number;
|
|
171
|
+
metadata: nbformat.INotebookMetadata;
|
|
172
|
+
cells: BeakerBaseCell[];
|
|
173
|
+
};
|
|
174
|
+
fromJSON(obj: any): void;
|
|
175
|
+
loadFromIPynb(obj: any): void;
|
|
176
|
+
toIPynb(): {
|
|
177
|
+
nbformat: number;
|
|
178
|
+
nbformat_minor: number;
|
|
179
|
+
cells: nbformat.IBaseCell[];
|
|
180
|
+
metadata: nbformat.INotebookMetadata;
|
|
181
|
+
};
|
|
182
|
+
addCell(cell: IBeakerCell | nbformat.ICell): void;
|
|
183
|
+
insertCell(cell: IBeakerCell | nbformat.ICell, position: number): void;
|
|
184
|
+
removeCell(index: number): void;
|
|
185
|
+
cutCell(index: number): IBeakerCell | null;
|
|
186
|
+
moveCell(fromIndex: number, toIndex: number): void;
|
|
187
|
+
setSubkernelInfo(sessionInfo: any): void;
|
|
188
|
+
content: BeakerNotebookContent;
|
|
189
|
+
cells: IBeakerCell[];
|
|
190
|
+
private subkernelInfo?;
|
|
191
|
+
}
|
|
192
|
+
export {};
|