@apaas-ai/code-sdk-core
Advanced tools
Comparing version 0.1.0-beta.2 to 0.1.0-beta.3
@@ -56,5 +56,3 @@ "use strict"; | ||
this.expireTime = data.expireTime; | ||
if (!this.tenantInfo) { | ||
this.tenantInfo = data.tenantInfo; | ||
} | ||
this.tenantInfo = data.tenantInfo; | ||
}); | ||
@@ -61,0 +59,0 @@ } |
@@ -1,3 +0,24 @@ | ||
export { MessageBuilder, MessageBuilderOptions, Button, ButtonProps, Chart, ChartProps, Code, CodeProps, Col, ColProps, ColorText, ColorTextProps, DataRecord, DataRecordProps, DataRecordField, DataRecordFieldTypeEnum, Highlight, HighlightProps, Image, ImageProps, ItemList, ItemListProps, Link, LinkProps, Mention, MentionProps, Note, NoteProps, OrderedList, OrderedListProps, Row, RowProps, TableColumn, TableColumnTypeEnum, TableProps, Table, TitleProps, TitleStyleEnum, Title, } from './message'; | ||
import { Builder } from './message'; | ||
export declare const message: { | ||
Builder: typeof Builder; | ||
components: { | ||
Button: typeof import("./message/components/button").Button; | ||
Chart: typeof import("./message/components/chart").Chart; | ||
Code: typeof import("./message/components/code").Code; | ||
Col: typeof import("./message/components/col").Col; | ||
Row: typeof import("./message/components/row").Row; | ||
ColorText: typeof import("./message/components/color-text").ColorText; | ||
DataRecord: typeof import("./message/components/data-record").DataRecord; | ||
Highlight: typeof import("./message/components/highlight").Highlight; | ||
Image: typeof import("./message/components/image").Image; | ||
ItemList: typeof import("./message/components/item-list").ItemList; | ||
Link: typeof import("./message/components/link").Link; | ||
Mention: typeof import("./message/components/mention").Mention; | ||
Note: typeof import("./message/components/note").Note; | ||
OrderedList: typeof import("./message/components/ordered-list").OrderedList; | ||
Table: typeof import("./message/components/table").Table; | ||
Title: typeof import("./message/components/title").Title; | ||
}; | ||
}; | ||
export { getEnvInfo } from './env/getEnvInfo'; | ||
export { callAction } from './action/callAction'; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.callAction = exports.getEnvInfo = exports.Title = exports.TitleStyleEnum = exports.Table = exports.TableColumnTypeEnum = exports.Row = exports.OrderedList = exports.Note = exports.Mention = exports.Link = exports.ItemList = exports.Image = exports.Highlight = exports.DataRecordFieldTypeEnum = exports.DataRecord = exports.ColorText = exports.Col = exports.Code = exports.Chart = exports.Button = exports.MessageBuilder = void 0; | ||
var message_1 = require("./message"); | ||
Object.defineProperty(exports, "MessageBuilder", { enumerable: true, get: function () { return message_1.MessageBuilder; } }); | ||
Object.defineProperty(exports, "Button", { enumerable: true, get: function () { return message_1.Button; } }); | ||
Object.defineProperty(exports, "Chart", { enumerable: true, get: function () { return message_1.Chart; } }); | ||
Object.defineProperty(exports, "Code", { enumerable: true, get: function () { return message_1.Code; } }); | ||
Object.defineProperty(exports, "Col", { enumerable: true, get: function () { return message_1.Col; } }); | ||
Object.defineProperty(exports, "ColorText", { enumerable: true, get: function () { return message_1.ColorText; } }); | ||
Object.defineProperty(exports, "DataRecord", { enumerable: true, get: function () { return message_1.DataRecord; } }); | ||
Object.defineProperty(exports, "DataRecordFieldTypeEnum", { enumerable: true, get: function () { return message_1.DataRecordFieldTypeEnum; } }); | ||
Object.defineProperty(exports, "Highlight", { enumerable: true, get: function () { return message_1.Highlight; } }); | ||
Object.defineProperty(exports, "Image", { enumerable: true, get: function () { return message_1.Image; } }); | ||
Object.defineProperty(exports, "ItemList", { enumerable: true, get: function () { return message_1.ItemList; } }); | ||
Object.defineProperty(exports, "Link", { enumerable: true, get: function () { return message_1.Link; } }); | ||
Object.defineProperty(exports, "Mention", { enumerable: true, get: function () { return message_1.Mention; } }); | ||
Object.defineProperty(exports, "Note", { enumerable: true, get: function () { return message_1.Note; } }); | ||
Object.defineProperty(exports, "OrderedList", { enumerable: true, get: function () { return message_1.OrderedList; } }); | ||
Object.defineProperty(exports, "Row", { enumerable: true, get: function () { return message_1.Row; } }); | ||
Object.defineProperty(exports, "TableColumnTypeEnum", { enumerable: true, get: function () { return message_1.TableColumnTypeEnum; } }); | ||
Object.defineProperty(exports, "Table", { enumerable: true, get: function () { return message_1.Table; } }); | ||
Object.defineProperty(exports, "TitleStyleEnum", { enumerable: true, get: function () { return message_1.TitleStyleEnum; } }); | ||
Object.defineProperty(exports, "Title", { enumerable: true, get: function () { return message_1.Title; } }); | ||
exports.callAction = exports.getEnvInfo = exports.message = void 0; | ||
const message_1 = require("./message"); | ||
exports.message = { | ||
Builder: message_1.Builder, | ||
components: message_1.components, | ||
}; | ||
var getEnvInfo_1 = require("./env/getEnvInfo"); | ||
@@ -26,0 +10,0 @@ Object.defineProperty(exports, "getEnvInfo", { enumerable: true, get: function () { return getEnvInfo_1.getEnvInfo; } }); |
@@ -15,3 +15,11 @@ "use strict"; | ||
}); | ||
(0, vitest_1.it)('validate props', () => { | ||
const button = new button_1.Button({ | ||
type: 'primary', | ||
action: 'navigate', | ||
children: 'Example', | ||
}); | ||
(0, vitest_1.expect)(() => button.toMessage()).toThrowError('button validate error: url is required when action is navigate'); | ||
}); | ||
}); | ||
//# sourceMappingURL=button.spec.js.map |
@@ -23,3 +23,3 @@ "use strict"; | ||
(0, vitest_1.expect)(row.toMessage()).toMatchInlineSnapshot(` | ||
"<row ><col flex=1 >hello</col> | ||
"<row><col flex=1 >hello</col> | ||
<col flex=1 ><button action="navigate" url="https://example.com" >Detail</button></col></row>" | ||
@@ -26,0 +26,0 @@ `); |
@@ -5,3 +5,3 @@ import { type BaseComponent } from './components/base-component'; | ||
} | ||
export declare class MessageBuilder { | ||
export declare class Builder { | ||
private lines; | ||
@@ -8,0 +8,0 @@ private options; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.MessageBuilder = void 0; | ||
class MessageBuilder { | ||
exports.Builder = void 0; | ||
class Builder { | ||
constructor(options) { | ||
@@ -19,3 +19,3 @@ this.lines = []; | ||
} | ||
exports.MessageBuilder = MessageBuilder; | ||
exports.Builder = Builder; | ||
//# sourceMappingURL=builder.js.map |
export declare abstract class BaseComponent<P extends object> { | ||
props: P; | ||
constructor(props: P); | ||
validateProps(): string; | ||
propLines(): string[]; | ||
@@ -5,0 +6,0 @@ propLinesString(): string; |
@@ -8,2 +8,5 @@ "use strict"; | ||
} | ||
validateProps() { | ||
return ''; | ||
} | ||
propLines() { | ||
@@ -24,3 +27,3 @@ return Object.entries(this.props) | ||
} | ||
return `${lines.join(' ')}`; | ||
return ` ${lines.join(' ')} `; | ||
} | ||
@@ -31,2 +34,6 @@ toMessage() { | ||
} | ||
const error = this.validateProps(); | ||
if (error) { | ||
throw new Error(`${this.name} validate error: ${error}`); | ||
} | ||
if ('children' in this.props) { | ||
@@ -52,5 +59,5 @@ const { children } = this.props; | ||
const lines = [`<${this.name}`, this.propLinesString(), `>${childrenMessage}</${this.name}>`]; | ||
return lines.join(' '); | ||
return lines.join(''); | ||
} | ||
return `<${this.name} ${this.propLines().join('')} />`; | ||
return [`<${this.name}`, this.propLinesString(), `/>`].join(''); | ||
} | ||
@@ -57,0 +64,0 @@ } |
import { BaseComponent } from './base-component'; | ||
export interface ButtonProps { | ||
url: string; | ||
children: string; | ||
url?: string; | ||
action?: 'navigate' | 'message'; | ||
@@ -14,3 +14,4 @@ type?: 'default' | 'primary' | 'danger' | 'text' | 'primaryFilled' | 'dangerFilled ' | 'primaryText ' | 'dangerText'; | ||
export declare class Button extends BaseComponent<ButtonProps> { | ||
validateProps(): string; | ||
name: string; | ||
} |
@@ -10,4 +10,14 @@ "use strict"; | ||
} | ||
validateProps() { | ||
const { action, url } = this.props; | ||
if (!action) { | ||
return 'action is required'; | ||
} | ||
if (action === 'navigate' && !url) { | ||
return 'url is required when action is navigate'; | ||
} | ||
return ''; | ||
} | ||
} | ||
exports.Button = Button; | ||
//# sourceMappingURL=button.js.map |
@@ -1,17 +0,36 @@ | ||
export * from './builder'; | ||
export * from './components/table'; | ||
export * from './components/link'; | ||
export * from './components/button'; | ||
export * from './components/chart'; | ||
export * from './components/code'; | ||
export * from './components/col'; | ||
export * from './components/row'; | ||
export * from './components/color-text'; | ||
export * from './components/highlight'; | ||
export * from './components/image'; | ||
export * from './components/item-list'; | ||
export * from './components/ordered-list'; | ||
export * from './components/mention'; | ||
export * from './components/note'; | ||
export * from './components/data-record'; | ||
export * from './components/title'; | ||
import { ButtonProps, Button } from './components/button'; | ||
import { ChartProps, ChartOptimizeConfig, Chart } from './components/chart'; | ||
import { CodeProps, Code } from './components/code'; | ||
import { ColProps, Col } from './components/col'; | ||
import { ColorTextProps, ColorText } from './components/color-text'; | ||
import { DataRecordField, DataRecordFieldTypeEnum, DataRecordProps, DataRecord } from './components/data-record'; | ||
import { HighlightProps, Highlight } from './components/highlight'; | ||
import { ImageProps, Image } from './components/image'; | ||
import { ItemListProps, ItemList } from './components/item-list'; | ||
import { LinkProps, Link } from './components/link'; | ||
import { MentionProps, Mention } from './components/mention'; | ||
import { NoteProps, Note } from './components/note'; | ||
import { OrderedListProps, OrderedList } from './components/ordered-list'; | ||
import { RowProps, Row } from './components/row'; | ||
import { TableColumn, TableColumnTypeEnum, TableProps, Table } from './components/table'; | ||
import { TitleProps, TitleStyleEnum, Title } from './components/title'; | ||
export { RowProps, ButtonProps, ChartProps, ChartOptimizeConfig, CodeProps, ColProps, ColorTextProps, DataRecordField, DataRecordFieldTypeEnum, DataRecordProps, HighlightProps, ImageProps, ItemListProps, LinkProps, MentionProps, NoteProps, OrderedListProps, TableProps, TableColumn, TableColumnTypeEnum, TitleProps, TitleStyleEnum, }; | ||
export { MessageBuilderOptions, Builder } from './builder'; | ||
export declare const components: { | ||
Button: typeof Button; | ||
Chart: typeof Chart; | ||
Code: typeof Code; | ||
Col: typeof Col; | ||
Row: typeof Row; | ||
ColorText: typeof ColorText; | ||
DataRecord: typeof DataRecord; | ||
Highlight: typeof Highlight; | ||
Image: typeof Image; | ||
ItemList: typeof ItemList; | ||
Link: typeof Link; | ||
Mention: typeof Mention; | ||
Note: typeof Note; | ||
OrderedList: typeof OrderedList; | ||
Table: typeof Table; | ||
Title: typeof Title; | ||
}; |
"use strict"; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
var desc = Object.getOwnPropertyDescriptor(m, k); | ||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
desc = { enumerable: true, get: function() { return m[k]; } }; | ||
} | ||
Object.defineProperty(o, k2, desc); | ||
}) : (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
o[k2] = m[k]; | ||
})); | ||
var __exportStar = (this && this.__exportStar) || function(m, exports) { | ||
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.components = exports.Builder = exports.TitleStyleEnum = exports.TableColumnTypeEnum = exports.DataRecordFieldTypeEnum = void 0; | ||
const button_1 = require("./components/button"); | ||
const chart_1 = require("./components/chart"); | ||
const code_1 = require("./components/code"); | ||
const col_1 = require("./components/col"); | ||
const color_text_1 = require("./components/color-text"); | ||
const data_record_1 = require("./components/data-record"); | ||
Object.defineProperty(exports, "DataRecordFieldTypeEnum", { enumerable: true, get: function () { return data_record_1.DataRecordFieldTypeEnum; } }); | ||
const highlight_1 = require("./components/highlight"); | ||
const image_1 = require("./components/image"); | ||
const item_list_1 = require("./components/item-list"); | ||
const link_1 = require("./components/link"); | ||
const mention_1 = require("./components/mention"); | ||
const note_1 = require("./components/note"); | ||
const ordered_list_1 = require("./components/ordered-list"); | ||
const row_1 = require("./components/row"); | ||
const table_1 = require("./components/table"); | ||
Object.defineProperty(exports, "TableColumnTypeEnum", { enumerable: true, get: function () { return table_1.TableColumnTypeEnum; } }); | ||
const title_1 = require("./components/title"); | ||
Object.defineProperty(exports, "TitleStyleEnum", { enumerable: true, get: function () { return title_1.TitleStyleEnum; } }); | ||
// export message builder | ||
var builder_1 = require("./builder"); | ||
Object.defineProperty(exports, "Builder", { enumerable: true, get: function () { return builder_1.Builder; } }); | ||
// export components | ||
exports.components = { | ||
Button: button_1.Button, | ||
Chart: chart_1.Chart, | ||
Code: code_1.Code, | ||
Col: col_1.Col, | ||
Row: row_1.Row, | ||
ColorText: color_text_1.ColorText, | ||
DataRecord: data_record_1.DataRecord, | ||
Highlight: highlight_1.Highlight, | ||
Image: image_1.Image, | ||
ItemList: item_list_1.ItemList, | ||
Link: link_1.Link, | ||
Mention: mention_1.Mention, | ||
Note: note_1.Note, | ||
OrderedList: ordered_list_1.OrderedList, | ||
Table: table_1.Table, | ||
Title: title_1.Title, | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
__exportStar(require("./builder"), exports); | ||
__exportStar(require("./components/table"), exports); | ||
__exportStar(require("./components/link"), exports); | ||
__exportStar(require("./components/button"), exports); | ||
__exportStar(require("./components/chart"), exports); | ||
__exportStar(require("./components/code"), exports); | ||
__exportStar(require("./components/col"), exports); | ||
__exportStar(require("./components/row"), exports); | ||
__exportStar(require("./components/color-text"), exports); | ||
__exportStar(require("./components/highlight"), exports); | ||
__exportStar(require("./components/image"), exports); | ||
__exportStar(require("./components/item-list"), exports); | ||
__exportStar(require("./components/ordered-list"), exports); | ||
__exportStar(require("./components/mention"), exports); | ||
__exportStar(require("./components/note"), exports); | ||
__exportStar(require("./components/data-record"), exports); | ||
__exportStar(require("./components/title"), exports); | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "@apaas-ai/code-sdk-core", | ||
"version": "0.1.0-beta.2", | ||
"version": "0.1.0-beta.3", | ||
"description": "Aily Code SDK Core", | ||
@@ -5,0 +5,0 @@ "license": "ISC", |
Aily Code SDK JavaScript | ||
## Usage | ||
### 调用 Action | ||
```ts | ||
const { callAction } = require('@apaas-ai/code-sdk-core'); | ||
const apiName = "brn:cn:spring:all:all:connector_action:spring_llm_v2/1.0.0/spring_llm_v2"; | ||
const res = await callAction(apiName, { | ||
query: "你好", | ||
llmSettingID: "some-llm-id", | ||
}); | ||
``` | ||
### 生成消息内容 | ||
```ts | ||
const { message } = require('@apaas-ai/code-sdk-core'); | ||
const { Button, ColorText } = message.components; | ||
const builder = new message.Builder(); | ||
builder.addLine( | ||
new ColorText({ | ||
children: "Hello World", | ||
color: "green", | ||
}) | ||
); | ||
builder.addLine( | ||
new Button({ | ||
children: "Click Me", | ||
}) | ||
); | ||
const message = builder.toMessage(); | ||
``` | ||
## Development | ||
@@ -14,2 +52,2 @@ | ||
- 执行 `pnpm test` 通过单元测试进行开发调试。 | ||
- 执行 `pnpm test` 通过单元测试进行开发调试。 |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
71655
107
1349
52